Get it on Google Play


Wm뮤 :: 'Unity/Photon' 카테고리의 글 목록 (2 Page)

블로그 이미지
가끔 그림그리거나 3D모델링하거나
취미로 로봇만드는
퇴직한 전자과 게임프로그래머
2020.3.48f1 , 2022.3.6f1 주로 사용
모카쨩
@Ahzkwid

Recent Comment

Archive


'Unity/Photon'에 해당되는 글 12건

  1. 2021.07.07 포톤 챗
  2. 2021.07.06 포톤 볼트
  3. 2021.07.04 포톤 커스텀 플레이어 만들기
  4. 2020.12.02 포톤 설치
2021. 7. 7. 02:16 Unity/Photon

별도로 챗용 에셋을 다운받을 필요없이 PUN API에서도 동작한다

 

 

 

 

 

 

 

 

 

 

 

 

 

UI Text를 깔고 ContentSizeFitter를 넣는다

 

 

PUN코드

더보기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Chat;
using ExitGames.Client.Photon;

public class PhotonChatTest : MonoBehaviour, IChatClientListener
{
    public string serverName = "Default0001";




    ChatClient chatClient;
    public string userName="TestName";

    List<string> messageList = new List<string>();
    readonly int messageFromHistory = 10;

    public Text currentChannelText;

    public void Connect()
    {

        chatClient = new ChatClient(this);


        chatClient.UseBackgroundWorkerForSending = true;
        chatClient.Connect(PhotonNetwork.PhotonServerSettings.ChatAppID, Application.version, new Photon.Chat.AuthenticationValues(userName));


        Debug.Log("Connect");


    }


    public void OnApplicationQuit()
    {
        chatClient.Disconnect();
    }

    public void AddLine(string message)
    {
        messageList.Add(message);

        if (messageList.Count> messageFromHistory)
        {
            messageList.RemoveAt(0);
        }
        currentChannelText.text = string.Join("\n", messageList);
    }


    public void DebugReturn(DebugLevel level, string message)
    {
        switch (level)
        {
            case DebugLevel.ERROR:
                Debug.LogError(message);
                break;
            case DebugLevel.WARNING:
                Debug.LogWarning(message);
                break;
            default:
                Debug.Log(message);
                break;
        }
    }


    public void OnConnected()
    {
        Debug.Log("OnConnected");

        chatClient.Subscribe(new string[] { serverName }, messageFromHistory);
    }

    public void OnDisconnected()
    {
        Debug.Log( "OnDisconnected");
    }


    public void OnChatStateChange(ChatState state)
    {
        Debug.Log($"OnChatStateChange {state}");
    }

    public void OnSubscribed(string[] channels, bool[] results)
    {
        Debug.Log( $"OnSubscribed : {string.Join(", ", channels)}");
    }

    public void OnUnsubscribed(string[] channels)
    {
        Debug.Log( $"OnUnsubscribed : {string.Join(", ", channels)}");
    }

    public void OnGetMessages(string channelName, string[] senders, object[] messages)
    {
        for (int i = 0; i < messages.Length; i++)
        {
            AddLine($"{senders[i]}:{ messages[i]}");
        }
    }


    void Start()
    {
        Application.runInBackground = true;
        if (Application.platform==RuntimePlatform.WindowsEditor)
        {
            userName += SystemInfo.deviceUniqueIdentifier.Substring(0,4);
        }
        Connect();
        currentChannelText.text = "";
    }
    void Update()
    {
        chatClient.Service();
    }

    public void SendChatMessage(string message)
    {
        if (string.IsNullOrWhiteSpace(message))
        {
            return;
        }
        message = message.Trim();
        chatClient.PublishMessage(serverName, message);
    }

    public void OnUserSubscribed(string channel, string user)
    {
        Debug.Log($"OnUserSubscribed :channel {channel},user {user}");
    }

    public void OnUserUnsubscribed(string channel, string user)
    {
        Debug.Log($"OnDisconnected :channel {channel},user {user}");
    }

    public void OnPrivateMessage(string sender, object message, string channelName)
    {
        Debug.Log($"OnDisconnected :sender {sender},message {message},channelName {channelName}");
    }

    public void OnStatusUpdate(string user, int status, bool gotMessage, object message)
    {
        Debug.Log($"OnDisconnected :user {user},status {status},gotMessage {gotMessage},message {message}");
    }

}

 

PUN2코드

더보기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Chat;
using ExitGames.Client.Photon;

public class PhotonChatTest : MonoBehaviour, IChatClientListener
{
    public string serverName = "Default0001";




    ChatClient chatClient;
    public string userName="TestName";

    List<string> messageList = new List<string>();
    readonly int messagesFromHistory = 10;

    public Text currentChannelText;

    public void Connect()
    {

        chatClient = new ChatClient(this);


        chatClient.UseBackgroundWorkerForSending = true;
        chatClient.Connect(Photon.Pun.PhotonNetwork.PhotonServerSettings.AppSettings.AppIdChat, Application.version, new AuthenticationValues(userName));
        

        Debug.Log("Connect");


    }


    public void OnApplicationQuit()
    {
        chatClient.Disconnect();
    }

    public void AddLine(string message)
    {
        messageList.Add(message);

        if (messageList.Count> messagesFromHistory)
        {
            messageList.RemoveAt(0);
        }
        currentChannelText.text = string.Join("\n", messageList);
    }


    public void DebugReturn(DebugLevel level, string message)
    {
        switch (level)
        {
            case DebugLevel.ERROR:
                Debug.LogError(message);
                break;
            case DebugLevel.WARNING:
                Debug.LogWarning(message);
                break;
            default:
                Debug.Log(message);
                break;
        }
    }


    public void OnConnected()
    {
        Debug.Log("OnConnected");

        chatClient.Subscribe(new string[] { serverName }, messagesFromHistory);
    }

    public void OnDisconnected()
    {
        Debug.Log( "OnDisconnected");
    }


    public void OnChatStateChange(ChatState state)
    {
        Debug.Log($"OnChatStateChange {state}");
    }

    public void OnSubscribed(string[] channels, bool[] results)
    {
        Debug.Log( $"OnSubscribed : {string.Join(", ", channels)}");
    }

    public void OnUnsubscribed(string[] channels)
    {
        Debug.Log( $"OnUnsubscribed : {string.Join(", ", channels)}");
    }

    public void OnGetMessages(string channelName, string[] senders, object[] messages)
    {
        for (int i = 0; i < messages.Length; i++)
        {
            AddLine($"{senders[i]}:{ messages[i]}");
        }
    }


    void Start()
    {
        Application.runInBackground = true;
        if (Application.platform==RuntimePlatform.WindowsEditor)
        {
            userName += SystemInfo.deviceUniqueIdentifier.Substring(0,4);
        }
        Connect();
        currentChannelText.text = "";
    }
    void Update()
    {
        chatClient.Service();
    }

    public void SendChatMessage(string message)
    {
        if (string.IsNullOrWhiteSpace(message))
        {
            return;
        }
        message = message.Trim();
        chatClient.PublishMessage(serverName, message);
    }

    public void OnUserSubscribed(string channel, string user)
    {
        Debug.Log($"OnUserSubscribed :channel {channel},user {user}");
    }

    public void OnUserUnsubscribed(string channel, string user)
    {
        Debug.Log($"OnUserUnsubscribed :channel {channel},user {user}");
    }

    public void OnPrivateMessage(string sender, object message, string channelName)
    {
        Debug.Log($"OnPrivateMessage :sender {sender},message {message},channelName {channelName}");
    }

    public void OnStatusUpdate(string user, int status, bool gotMessage, object message)
    {
        Debug.Log($"OnStatusUpdate :user {user},status {status},gotMessage {gotMessage},message {message}");
    }

}

챗 관리 오브젝트를 만들어서 위 코드를 붙여넣고 아까만든 UI Text를 할당한다

 

 

 

InputField를 만들어서 다음과 같이 할당한다

 

 

 

 

 

 

 

 

 

작동중인모습

'Unity > Photon' 카테고리의 다른 글

포톤 보이스  (0) 2021.07.10
포톤 볼트  (0) 2021.07.06
포톤 커스텀 플레이어 만들기  (0) 2021.07.04
posted by 모카쨩
2021. 7. 6. 03:31 Unity/Photon

https://assetstore.unity.com/packages/tools/network/photon-bolt-free-127156

 

Photon Bolt FREE | 네트워크 | Unity Asset Store

Get the Photon Bolt FREE package from Exit Games and speed up your game development process. Find this & other 네트워크 options on the Unity Asset Store.

assetstore.unity.com

 

 

 

 

 

 

 

 

하다보니 이게 게임파일을 서버에 올리는 방식이라 좀 나중에 하기로 함

 

 

 

 

 

 

 

 

 

 

'Unity > Photon' 카테고리의 다른 글

포톤 챗  (0) 2021.07.07
포톤 커스텀 플레이어 만들기  (0) 2021.07.04
포톤 설치  (0) 2020.12.02
posted by 모카쨩
2021. 7. 4. 20:17

보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

2020. 12. 2. 11:27 Unity/Photon

 

 

www.photonengine.com/ko-KR/

 

글로벌 크로스 플랫폼 실시간 게임 개발 | Photon Engine

MULTIPLAYER REALTIME PUN BOLT QUANTUM COMMUNICATION CHAT VOICE SELF-HOSTED SERVER 멀티플레이를 간단하게 실현합니다! Photon Realtime 인디/프로 개발자 누구나 실시간 멀티 플레이어 게임을 개발하여 세계로 진출할

www.photonengine.com

 

가입하고

 

dashboard.photonengine.com/ko-KR/

 

Multiplayer Game Development Made Easy | Photon Engine

MULTIPLAYER REALTIME PUN BOLT QUANTUM COMMUNICATION CHAT VOICE SELF-HOSTED SERVER We Make Multiplayer Simple Photon Realtime Develop and launch multiplayer games globally whether you are an indie developer or AAA studio. Create synchronous or asynchronous

id.photonengine.com

여기에 들어가서

 

Photon PUN은 VRChat같은거 만들때 씀, 전부 간접통신임

Photon BOLT는 오버워치 같은거 만들때 쓰고 직접통신, NAT나 방화벽등으로 인해 직접연결이 불가한경우 릴레이를 통한 간접연결이 됨, 방장이 나가면 방이 닫힌다

 

설정한다

 

 

 

어플리케이션 ID 필요함

 

 

 

 

유니티로 가서

 

PUN1

더보기

assetstore.unity.com/packages/tools/network/photon-unity-networking-classic-free-1786

 

다운로드해

 

펀 ID를 넣자

 

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PhotonInit : Photon.PunBehaviour
{
    public string serverName = "Default0001";
    public int roomNumber = 0;
    public Transform spawnPoint;
    public GameObject playerPrefab;



    // Start is called before the first frame update
    void Start()
    {
        PhotonNetwork.ConnectUsingSettings(serverName);
        PhotonNetwork.ConnectToBestCloudServer(serverName);
    }
    /// <summary>
    /// 로비에 들어가기 성공했을때
    /// </summary>
    public override void OnConnectedToPhoton()
    {
        Debug.Log("ConnectedToPhoton");
    }


    /// <summary>
    /// 로비에 들어가기 성공했을때
    /// </summary>
    public override void OnJoinedLobby()
    {
        Debug.Log("JoinedLobby");
        PhotonNetwork.JoinRandomRoom();
    }
    /// <summary>
    /// PhotonNetwork.autoJoinLobby 이 false 인 경우에만 마스터 서버에 연결되고 인증 후에 호출 
    /// </summary>
    public override void OnConnectedToMaster()
    {
        Debug.Log("ConnectedToMaster");
        PhotonNetwork.JoinLobby(); //로비접속
    }

    /// <summary>
    /// 룸입장실패
    /// </summary>
    /// <param name="codeAndMsg"></param>
    public override void OnPhotonRandomJoinFailed(object[] codeAndMsg)
    {
        Debug.LogError("PhotonRandomJoinFailed");
        PhotonNetwork.CreateRoom(roomNumber.ToString());
    }

    /// <summary>
    /// 룸생성실패
    /// </summary>
    /// <param name="codeAndMsg"></param>
    public override void OnPhotonCreateRoomFailed(object[] codeAndMsg)
    {
        Debug.LogError("PhotonCreateRoomFailed");
        PhotonNetwork.JoinRandomRoom();
    }

    /// <summary>
    /// 룸생성 성공
    /// </summary>
    public override void OnCreatedRoom()
    {
        Debug.Log("CreatedRoom");
    }

    /// <summary>
    /// 룸접속 성공
    /// </summary>
    public override void OnJoinedRoom()
    {
        Debug.Log("JoinedRoom");
        CreatePlayer();
    }
    void CreatePlayer()
    {
        var pos = Vector3.zero;
        var rot = Quaternion.identity;
        if (spawnPoint != null)
        {
            pos = spawnPoint.position;
            rot = spawnPoint.rotation;
        }
        string objName = "Player";//플레이어 프리팹이 없으면 기본 플레이어가 호출됨
        if (playerPrefab != null)
        {
            objName = playerPrefab.name; //프리팹 이름은 Player로 하면 안됨
        }
        PhotonNetwork.Instantiate(objName, pos, rot);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

 

 

PUN2

더보기

https://assetstore.unity.com/packages/tools/network/pun-2-free-119922

 

PUN 2 - FREE | 네트워크 | Unity Asset Store

Get the PUN 2 - FREE package from Exit Games and speed up your game development process. Find this & other 네트워크 options on the Unity Asset Store.

assetstore.unity.com

다운로드해

 

펀 ID를 넣자

 

using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PhotonInit : MonoBehaviourPunCallbacks
{
    public string serverName = "Default0001";
    public int roomNumber = 0;
    public Transform spawnPoint;
    public GameObject playerPrefab;



    // Start is called before the first frame update
    void Start()
    {
        PhotonNetwork.ConnectUsingSettings();
        PhotonNetwork.ConnectToBestCloudServer();
    }

    /// <summary>
    /// 로비에 들어가기 성공했을때
    /// </summary>
    public override void OnJoinedLobby()
    {
        Debug.Log("JoinedLobby");
        //PhotonNetwork.JoinRandomRoom(); //로비사용시
    }
    /// <summary>
    /// PhotonNetwork.autoJoinLobby 이 false 인 경우에만 마스터 서버에 연결되고 인증 후에 호출 
    /// </summary>
    public override void OnConnectedToMaster()
    {
        Debug.Log("ConnectedToMaster");
        PhotonNetwork.JoinRandomRoom();
        //PhotonNetwork.JoinLobby(); //로비접속 (로비사용시)
    }

    /// <summary>
    /// 룸입장실패
    /// </summary>
    /// <param name="codeAndMsg"></param>
    public override void OnJoinRandomFailed(short returnCode, string message)
    {
        Debug.LogError("PhotonRandomJoinFailed");
        PhotonNetwork.CreateRoom(roomNumber.ToString());
    }

    /// <summary>
    /// 룸생성실패
    /// </summary>
    /// <param name="codeAndMsg"></param>
    public override void OnCreateRoomFailed(short returnCode, string message)
    {
        Debug.LogError("PhotonCreateRoomFailed");
        PhotonNetwork.JoinRandomRoom();
    }

    /// <summary>
    /// 룸생성 성공
    /// </summary>
    public override void OnCreatedRoom()
    {
        Debug.Log("CreatedRoom");
    }

    /// <summary>
    /// 룸접속 성공
    /// </summary>
    public override void OnJoinedRoom()
    {
        Debug.Log("JoinedRoom");
        CreatePlayer();
    }
    void CreatePlayer()
    {
        var pos = Vector3.zero;
        var rot = Quaternion.identity;
        if (spawnPoint != null)
        {
            pos = spawnPoint.position;
            rot = spawnPoint.rotation;
        }
        string objName = "My Robot Kyle -done-";//플레이어 프리팹이 없으면 기본 플레이어가 호출됨
        if (playerPrefab != null)
        {
            objName = playerPrefab.name; //프리팹 이름은 Player로 하면 안됨
        }
        PhotonNetwork.Instantiate(objName, pos, rot, 0);
    }

    // Update is called once per frame
    void Update()
    {

    }
}

 

 

 

 

 

 

이렇게 만들어서 

씬에 넣는다.

PUN2

 

 

 

 

api는 여기 참조

PUN1

doc-api.photonengine.com/ko-kr/pun/current/class_photon_1_1_pun_behaviour.html

 

실행하면 이렇게 나온다

 

PUN1

더보기

 

 

로그를 보면 이렇게

빨간줄이 있지만 단지 방이 없어서 뜬것이니 쫄지 말자 정상이다

 

PUN2

더보기

로그를 보면 이렇게

빨간줄이 있지만 단지 방이 없어서 뜬것이니 쫄지 말자 정상이다

 

 

 

 

 

 

시작하면 이렇게 나올것이다.

1. 포톤서버에 연결하고

2. 로비에 들어가서

3. 룸에 들어가는것이다

 

기본적인 네트워킹 시스템은 완성했다

 

 

 

'Unity > Photon' 카테고리의 다른 글

포톤 챗  (0) 2021.07.07
포톤 볼트  (0) 2021.07.06
포톤 커스텀 플레이어 만들기  (0) 2021.07.04
posted by 모카쨩

  • total
  • today
  • yesterday

Recent Post

저사양 유저용 블로그 진입