https://doc.photonengine.com/ko-kr/pun/v2/demos-and-tutorials/pun-basics-tutorial/game-scenes

페이지 번역이 되어있지 않지만 전 튜토리얼과 크게다르지 않다


패널에 버튼을 만들고 방나가는 이벤트를 등록하고 바닥과 벽오브젝트를 생성


씬을 같은 구조의 씬을 4개만들고 바닥과 벽스케일과 위치만 변경한다


이후 빌드 설정에서 지금까지 만든 씬들을 등록한다


이번에 만든 GameManager 스크립트는 방에서 나가는 메소드와 방을 나갔을 때 첫 로비씬으로 바꾸는 이벤트메소드말고는 없다


퇴근 후 귀가가 늦었으므로 오늘은 여기까지


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using Photon.Pun;
using Photon.Realtime;
 
 
namespace Com.MyCompany.MyGame
{
    public class GameManager : MonoBehaviourPunCallbacks
    {
 
        public override void OnLeftRoom()
        {
            SceneManager.LoadScene(0);
        }
 
        public void LeaveRoom()
        {
            PhotonNetwork.LeaveRoom();
        }
 
    }
}
cs



4일차 


https://doc.photonengine.com/ko-kr/pun/v2/demos-and-tutorials/pun-basics-tutorial/lobby-ui


해당 튜토리얼을 보고 유저네임 입력 UI와 스크립트를 만들었다




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;
 
namespace Com.MyCompany.MyGame
{
 
    [RequireComponent(typeof(InputField))]
    public class PlayerNameInputField : MonoBehaviour
    {
 
        const string playerNamePrefKey = "PlayerName";
        // Start is called before the first frame update
        void Start()
        {
            string defaultName = string.Empty;
            InputField _inputField = this.GetComponent<InputField>();
            if(_inputField != null)
            {
                if (PlayerPrefs.HasKey(playerNamePrefKey))
                {
                    defaultName = PlayerPrefs.GetString(playerNamePrefKey);
                    _inputField.text = defaultName;
                }
            }
 
            PhotonNetwork.NickName = defaultName;
        }
 
        // Update is called once per frame
        void Update()
        {
        
        }
 
        public void SetPlayerName(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                Debug.LogError("Player Name is null or empty");
                return;
            }
            PhotonNetwork.NickName = value;
 
            PlayerPrefs.SetString(playerNamePrefKey, value);
        }
    }
}
cs


**InputField 의 on value changed 이벤트에 SetPlayName걸어도 null이 나가서 

인자를 InputField로 변경 후  value.text로 접근하니 접근이 가능했다.

 ** public void SetPlayerName(InputField value){ value.text ...........

원인을  찾아보자

추가

위에 Dynamic string 쪽에 선택을 했어야했다 ... 글을 대충읽지 말자




[RequireComponent(typeof(컴포넌트))]

스크립트가 달린 오브젝트에 해당 컴포넌트가 없다면 추가를 요청한다


C#에서 [] 연산자 용법중 어트리뷰트 부분을 참고해보자

https://docs.microsoft.com/ko-kr/dotnet/csharp/programming-guide/concepts/attributes/index


PlayerPrefs 클래스는 로컬에 간단한 자료를 저장 할 수있게 해준다

https://docs.unity3d.com/ScriptReference/PlayerPrefs.html





3일차 


공식 홈페이지에 튜토리얼이 한글로 잘 나와있다

참조 : https://doc.photonengine.com/ko-kr/pun/v2/demos-and-tutorials/pun-basics-tutorial/intro



유니티 에셋스토에서 PUN을 받는다







 PUN 을 임포트하고 포톤 클라우드의 애플리케이션 ID를 입력하면 된다

 




씬을 하나 만든 후 빈 오브젝트에 아래 스크립트를 추가해 보자


https://doc-api.photonengine.com/ko-kr/pun/current/index.html 

API 도 한글로 잘 되어있다


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
 
namespace Com.MyCompany.MyGame
{  
    public class Launcher : MonoBehaviour
    {
 
        string gameVersion = "1";
 
        private void Awake()
        {
            PhotonNetwork.AutomaticallySyncScene = true;
        }
 
        void Start()
        {
            Connect();
        }
   
        void Update()
        {
        
        }
        public void Connect()
        {
            if (PhotonNetwork.IsConnected)
            {
                PhotonNetwork.JoinRandomRoom();
            }
            else
            {
                PhotonNetwork.GameVersion = gameVersion;
                PhotonNetwork.ConnectUsingSettings();
            }
        }
 
    }
}



PhotomNetwork가 사용중이니


https://doc-api.photonengine.com/ko-kr/pun/current/class_photon_network.html

관련 API를 보자




Window -> Photon Unity Networking ->PUN Wizard

PUN 관련 세팅을 할 수 있다





Logging 을 full로 설정하면 전체 로그를 확인 할 수 있다









+ Recent posts