๐ท์ค์ต 1 (7)
- ๋ฐฉ ๋ชฉ๋ก ๋์ฐ๊ธฐ
- ๋ชฉ๋ก์์ ๋ฐฉ์ ์ ํํด ํด๋น ๋ฐฉ์ ์ ์ฅ
๐ถ ๋ฐฉ ๋ชฉ๋ก ๋์ฐ๊ธฐ
- Scroll View ์์ฑ
- ๋ฒํผ ์์ฑ : RoomEntity
- ์คํฌ๋ฆฝํธ ์์ฑ : RoomData
- RoomEntity์ ์คํฌ๋ฆฝํธ ์ถ๊ฐ
- Scrollbar Horizontal ์ญ์
- Horizontal : ์ธ์ฒดํฌ
- Horizontal Scrollbar : ์๋ฌด๊ฒ๋ ์ฐ๊ฒฐ ์๋์ด ์๋ ๊ฒ ํ์ธ
- ์ปดํฌ๋ํธ ์ถ๊ฐ
- Vertical Layout Group
- Padding ์กฐ์
- Child Alignment : Upper Center
- Child Force Expand : ์ธ์ฒดํฌ
- Content Size Fitter
- Vertical Fit : Min Size
- ํ๋ฆฌํนํ
- ํ์ด์ด๋ผํค์ ์๋ RoomEntity ์ญ์
- ์ฐ๊ฒฐ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
public class RoomData : MonoBehaviour
{
private TMP_Text RoomInfoText;
private RoomInfo _roomInfo;
public TMP_InputField userIdText;
public RoomInfo RoomInfo
{
get
{
return _roomInfo;
}
set
{
_roomInfo = value;
// EX : room_03 (1/2)
RoomInfoText.text = $"{_roomInfo.Name} ({_roomInfo.PlayerCount}/{_roomInfo.MaxPlayers})";
// ๋ฒํผ์ ํด๋ฆญ ์ด๋ฒคํธ์ ํจ์๋ฅผ ์ฐ๊ฒฐ
GetComponent<UnityEngine.UI.Button>().onClick.AddListener(() => OnEnterRoom(_roomInfo.Name));
}
}
void Awake()
{
RoomInfoText = GetComponentInChildren<TMP_Text>();
userIdText = GameObject.Find("InputField (TMP) - Nickname").GetComponent<TMP_InputField>();
}
void OnEnterRoom(string roomName)
{
RoomOptions ro = new RoomOptions();
ro.IsOpen = true;
ro.IsVisible = true;
ro.MaxPlayers = 2;
PhotonNetwork.NickName = userIdText.text;
PhotonNetwork.JoinOrCreateRoom(roomName, ro, TypedLobby.Default);
}
}
-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;
using TMPro;
public class PhotonManager : MonoBehaviourPunCallbacks
{
private readonly string gameVersion = "v1.0";
private string userId = "Ojui";
public TMP_InputField userIdText;
public TMP_InputField roomNameText;
// ๋ฃธ ๋ชฉ๋ก ์ ์ฅํ๊ธฐ ์ํ ๋์
๋๋ฆฌ ์๋ฃํ
private Dictionary<string, GameObject> roomDict = new Dictionary<string, GameObject>();
// ๋ฃธ์ ํ์ํ ํ๋ฆฌํน
public GameObject roomPrefab;
// Room ํ๋ฆฌํน์ด ์ฐจ์ผ๋ํ ์ํฌ ๋ถ๋ชจ ๊ฐ์ฒด
public Transform scrollContent;
private void Awake()
{
// ๋ฐฉ์ฅ์ด ํผ์ ์ฌ์ ๋ก๋ฉํ๋ฉด, ๋๋จธ์ง ์ฌ๋๋ค์ ์๋์ผ๋ก ์ฑํฌ๊ฐ ๋จ
PhotonNetwork.AutomaticallySyncScene = true;
// ๊ฒ์ ๋ฒ์ ์ง์
PhotonNetwork.GameVersion = gameVersion;
// ์๋ฒ ์ ์
PhotonNetwork.ConnectUsingSettings();
}
void Start()
{
Debug.Log("00. ํฌํค ๋งค๋์ ์์");
userId = PlayerPrefs.GetString("USER_ID", $"USER_{Random.Range(0, 100):00}");
userIdText.text = userId;
PhotonNetwork.NickName = userId;
}
public override void OnConnectedToMaster()
{
Debug.Log("01. ํฌํค ์๋ฒ์ ์ ์");
//๋ก๋น์ ์ ์
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
Debug.Log("02. ๋ก๋น์ ์ ์");
}
public override void OnJoinRandomFailed(short returnCode, string message)
{
Debug.Log("๋๋ค ๋ฃธ ์ ์ ์คํจ");
// ๋ฃธ ์์ฑ ์ค์
RoomOptions ro = new RoomOptions();
ro.IsOpen = true;
ro.IsVisible = true;
ro.MaxPlayers = 2;
roomNameText.text = $"Room_{Random.Range(1, 100):000}";
// ๋ฃธ์ ์์ฑ > ์๋ ์
์ฅ๋จ
PhotonNetwork.CreateRoom("room_1", ro);
}
public override void OnCreatedRoom()
{
Debug.Log("03. ๋ฐฉ ์์ฑ ์๋ฃ");
}
public override void OnJoinedRoom()
{
Debug.Log("04. ๋ฐฉ ์
์ฅ ์๋ฃ");
if (PhotonNetwork.IsMasterClient)
{
PhotonNetwork.LoadLevel("Level_1");
}
}
public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
GameObject tempRoom = null;
foreach (var room in roomList)
{
// ๋ฃธ์ด ์ญ์ ๋ ๊ฒฝ์ฐ
if (room.RemovedFromList == true)
{
roomDict.TryGetValue(room.Name, out tempRoom);
Destroy(tempRoom);
roomDict.Remove(room.Name);
}
// ๋ฃธ ์ ๋ณด๊ฐ ๊ฐฑ์ (๋ณ๊ฒฝ)๋ ๊ฒฝ์ฐ
else
{
// ๋ฃธ์ด ์ฒ์ ์์ฑ๋ ๊ฒฝ์ฐ
if (roomDict.ContainsKey(room.Name) == false)
{
GameObject _room = Instantiate(roomPrefab, scrollContent);
_room.GetComponent<RoomData>().RoomInfo = room;
roomDict.Add(room.Name, _room);
}
// ๋ฃธ ์ ๋ณด๋ฅผ ๊ฐฑ์ ํ๋ ๊ฒฝ์ฐ
else
{
roomDict.TryGetValue(room.Name, out tempRoom);
tempRoom.GetComponent<RoomData>().RoomInfo = room;
}
}
}
}
#region UI_BUTTON_CALLBACK
// Random ๋ฒํผ ํด๋ฆญ
public void OnRandomBtn()
{
// ID ์ธํํ๋๊ฐ ๋น์ด์์ผ๋ฉด
if (string.IsNullOrEmpty(userIdText.text))
{
// ๋๋ค ์์ด๋ ๋ถ์ฌ
userId = $"USER_{Random.Range(0, 100):00}";
userIdText.text = userId;
}
PlayerPrefs.SetString("USER_ID", userIdText.text);
PhotonNetwork.NickName = userIdText.text;
PhotonNetwork.JoinRandomRoom();
}
// Room ๋ฒํผ ํด๋ฆญ ์ (๋ฃธ ์์ฑ)
public void OnMakeRoomClick()
{
RoomOptions ro = new RoomOptions();
ro.IsOpen = true;
ro.IsVisible = true;
ro.MaxPlayers = 2;
// ์ธํํ๋๊ฐ ๋น์ด์์ผ๋ฉด
if (string.IsNullOrEmpty(roomNameText.text))
{
// ๋๋ค ๋ฃธ ์ด๋ฆ ๋ถ์ฌ
roomNameText.text = $"ROOM_{Random.Range(1, 100):000}";
}
PhotonNetwork.CreateRoom(roomNameText.text, ro);
}
#endregion
}
-
- ํด๋ฆญ ์ด๋ฒคํธ ์ฐ๊ฒฐ
- play
- USER_52 : Room ๋ฒํผ ํด๋ฆญ
- USER_52๊ฐ ๋ฐฉ์ ์์ฑ
- ojui_1 : ์์ฑ๋ ๋ฐฉ ํด๋ฆญ
- ๊ฐ์ ๋ฐฉ์ ์ ์ฅ
- ๋ฐฉ๋ชฉ๋ก์ 2/2๋ผ๊ณ ์ ๋ฐ์ดํธ๊ฐ ๋์ด์์
- ๋ฐฉ์ ์์ฑ
- ๋ฐฉ ๋ชฉ๋ก์ ๋ฐฉ 2๊ฐ๊ฐ ์๊ธด ๊ฒ์ ๋ณผ ์ ์์
'Unity > Photon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Photon - VR(XR Toolkit), Voice (0) | 2023.06.14 |
---|---|
08. Photon - ์ค์ต 1 (6) Photon Nickname (0) | 2021.08.24 |
07. Photon - ์ค์ต 1 (5) Photon Voice (0) | 2021.08.23 |
06. Photon - ์ค์ต 1 (4) Lobby, Custom Property (0) | 2021.08.22 |
05. Photon - ์ค์ต 1 (3) Score (1) | 2021.08.18 |