๐ท Photon ์ฐ๊ฒฐ
- ๋น ๊ฒ์ ์ค๋ธ์ ํธ ์์ฑ : PhotonManager
- ์คํฌ๋ฆฝํธ ์์ฑ : PhotonManager
- PhotonManager ์คํฌ๋ฆฝํธ ์ถ๊ฐ
๐ถ PhotonManage.cs ์์ฑ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
public class PhotonManager : MonoBehaviourPunCallbacks
{
private readonly string gameVersion = "v1.0";
private string userId = "Ojui";
private void Awake()
{
// ๊ฒ์ ๋ฒ์ ์ง์
PhotonNetwork.GameVersion = gameVersion;
// ์๋ฒ ์ ์
PhotonNetwork.ConnectUsingSettings();
}
void Start()
{
Debug.Log("00. ํฌํค ๋งค๋์ ์์");
PhotonNetwork.NickName = userId;
}
public override void OnConnectedToMaster()
{
Debug.Log("01. ํฌํค ์๋ฒ์ ์ ์");
PhotonNetwork.JoinRandomRoom();
}
public override void OnJoinRandomFailed(short returnCode, string message)
{
Debug.Log("02. ๋๋ค ๋ฃธ ์ ์ ์คํจ");
// ๋ฃธ ์์ฑ ์ค์
RoomOptions ro = new RoomOptions();
ro.IsOpen = true;
ro.IsVisible = true;
ro.MaxPlayers = 30;
// ๋ฃธ์ ์์ฑ > ์๋ ์
์ฅ๋จ
PhotonNetwork.CreateRoom("room_1", ro);
}
public override void OnCreatedRoom()
{
Debug.Log("03. ๋ฐฉ ์์ฑ ์๋ฃ");
}
public override void OnJoinedRoom()
{
Debug.Log("04. ๋ฐฉ ์
์ฅ ์๋ฃ");
}
}
๐ถ Photon ์ฐ๊ฒฐ ํ์ธ
- ์ ๋ํฐ play ํ ์ฝ์์ฐฝ์ ์์ ๊ฐ์ ๋ก๊ทธ๊ฐ ๋จ๋ฉด, ์ฐ๊ฒฐ ์ฑ๊ณตํ ๊ฒ
๐ท ๋ฐฉ ์ ์ฅํ๋ฉด์ ์ฌ ๋์ด๊ฐ๊ธฐ
- ์ฌ ์์ฑ : PlayScene
- ๊ตฌ๋ถํ๊ธฐ ์ฝ๋๋ก ์ธํ
- cube ์์ฑ : Floor
- Scale : 10, 0.1, 10
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
public class PhotonManager : MonoBehaviourPunCallbacks
{
private readonly string gameVersion = "v1.0";
private string userId = "Ojui";
private void Awake()
{
// ๋ฐฉ์ฅ์ด ํผ์ ์ฌ์ ๋ก๋ฉํ๋ฉด, ๋๋จธ์ง ์ฌ๋๋ค์ ์๋์ผ๋ก ์ฑํฌ๊ฐ ๋จ
PhotonNetwork.AutomaticallySyncScene = true;
// ๊ฒ์ ๋ฒ์ ์ง์
PhotonNetwork.GameVersion = gameVersion;
// ์๋ฒ ์ ์
PhotonNetwork.ConnectUsingSettings();
}
void Start()
{
Debug.Log("00. ํฌํค ๋งค๋์ ์์");
PhotonNetwork.NickName = userId;
}
public override void OnConnectedToMaster()
{
Debug.Log("01. ํฌํค ์๋ฒ์ ์ ์");
PhotonNetwork.JoinRandomRoom();
}
public override void OnJoinRandomFailed(short returnCode, string message)
{
Debug.Log("02. ๋๋ค ๋ฃธ ์ ์ ์คํจ");
// ๋ฃธ ์์ฑ ์ค์
RoomOptions ro = new RoomOptions();
ro.IsOpen = true;
ro.IsVisible = true;
ro.MaxPlayers = 30;
// ๋ฃธ์ ์์ฑ > ์๋ ์
์ฅ๋จ
PhotonNetwork.CreateRoom("room_1", ro);
}
public override void OnCreatedRoom()
{
Debug.Log("03. ๋ฐฉ ์์ฑ ์๋ฃ");
}
public override void OnJoinedRoom()
{
Debug.Log("04. ๋ฐฉ ์
์ฅ ์๋ฃ");
if (PhotonNetwork.IsMasterClient)
{
PhotonNetwork.LoadLevel("PlayScene");
}
}
}
- PhotonNetwork.LoadLevel("์ฌ์ด๋ฆ");
- Ctrl + Shift + B : Build Settings ์ด๊ธฐ
- ์ฌ์ ์์์ ๋ง๊ฒ Drag&Drop
- SampleScene์ผ๋ก ๋์์์ playํด๋ณด๋ฉด, PlayScene์ผ๋ก ์ ํ๋จ
- ์ฌ์ ํ๋๋ฉด์ ์ค์ ํด๋ ๋จธํฐ๋ฆฌ์ผ ์์๋ณด๋ค ์ด๋์๋ณด์ธ๋ค๋ฉด ๋ผ์ดํธ๋งต์ ๊ตฌ์์ฃผ๋ฉด ํด๊ฒฐ๋จ
'Unity > Photon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
06. Photon - ์ค์ต 1 (4) Lobby, Custom Property (0) | 2021.08.22 |
---|---|
05. Photon - ์ค์ต 1 (3) Score (1) | 2021.08.18 |
04. Photon - ์ค์ต 1 (2) ํ๋ ์ด์ด Material ๋ฐ๊พธ๊ธฐ (0) | 2021.08.17 |
03. Photon - ์ค์ต 1 (1) player ์์ฑ, ์์น ๋๊ธฐํ (0) | 2021.08.16 |
01. Photon Setting (0) | 2021.07.28 |