멀티플레이 제작 끝

This commit is contained in:
김도환
2026-05-01 07:06:29 +09:00
parent a36270f77a
commit ad7caf1e71
23 changed files with 2212 additions and 96 deletions

View File

@@ -4,17 +4,22 @@ using TMPro;
using UnityEngine;
using Photon.Pun;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using Hashtable = ExitGames.Client.Photon.Hashtable;
public class GameManager : MonoBehaviourPunCallbacks
{
public TextMeshProUGUI text;
public GameObject readyPanel;
public GameObject restartButton;
public GameObject destroyRoomButton;
public static Dictionary<int, Sprite> AvatarCache = new Dictionary<int, Sprite>();
private void Start()
{
if (restartButton != null) restartButton.SetActive(false);
if (destroyRoomButton != null) destroyRoomButton.SetActive(false); // [추가]
// 씬 시작 시, 모두의 아바타를 다운로드하는 코루틴 시작
StartCoroutine(DownloadAllAvatarsAndReady());
}
@@ -191,19 +196,68 @@ public class GameManager : MonoBehaviourPunCallbacks
if (winnerActorNumber == -1)
{
text.text = "아무도 참여하지 않았습니다.";
ShowRestartButtonIfMaster(); // 아무도 안 했을 때도 다시하기 버튼 띄우기
return;
}
// 우승자 닉네임 찾기
string winnerName = "알 수 없음";
foreach (var p in PhotonNetwork.PlayerList)
foreach (var player in PhotonNetwork.PlayerList)
{
if (p.ActorNumber == winnerActorNumber) winnerName = p.NickName;
if (player.ActorNumber == winnerActorNumber)
{
winnerName = player.NickName;
break;
}
}
text.text = $"우승: {winnerName}!";
// 텍스트를 바로 바꾸지 않고 "추첨 중"으로 변경! (스포일러 방지)
text.text = "추첨 중...";
// 화면에서 우승자의 아바타만 빼고 전부 어둡게/투명하게 만드는 연출 실행!
FindObjectOfType<Gazuaa>().HighlightWinner(winnerActorNumber);
// Gazuaa 스크립트를 찾아서 룰렛 연출 시작 (이름도 같이 넘겨줍니다)
FindObjectOfType<Gazuaa>().HighlightWinner(winnerActorNumber, winnerName);
}
// Gazuaa.cs의 코루틴이 끝난 후(룰렛이 멈춘 후) 호출할 함수
public void ShowRestartButtonIfMaster()
{
// 내가 방장일 때만 버튼을 활성화합니다.
if (PhotonNetwork.IsMasterClient )
{
if (restartButton != null) restartButton.SetActive(true);
if (destroyRoomButton != null) destroyRoomButton.SetActive(true); // [추가]
}
} // '다시 하기' 버튼의 OnClick() 이벤트에 연결할 함수
public void ClickRestart()
{
// 방장이 씬을 다시 로드합니다. (모두가 자동으로 따라옵니다!)
// "GameScene" 부분은 실제 사용 중인 게임 씬의 이름으로 적어주세요.
PhotonNetwork.LoadLevel("GameScene");
}
// [추가] '방 삭제' 버튼의 OnClick() 이벤트에 연결할 함수
public void ClickDestroyRoom()
{
// 방장이 모든 클라이언트에게 "방에서 나가!" 라고 명령을 내립니다.
photonView.RPC("RpcLeaveRoom", RpcTarget.All);
}
// [추가] 모두의 컴퓨터에서 실행될 방 나가기 함수
[PunRPC]
private void RpcLeaveRoom()
{
// 포톤 서버에 이 방에서 나가겠다고 요청합니다.
PhotonNetwork.LeaveRoom();
}
// [추가] 방에서 완전히 빠져나왔을 때 포톤이 자동으로 호출해 주는 함수
public override void OnLeftRoom()
{
// 방에서 성공적으로 나갔다면, 최초 로비 화면으로 씬을 이동시킵니다.
// "LobbyScene" 부분을 실제 로비 씬의 이름으로 꼭 바꿔주세요!!!
SceneManager.LoadScene("LobbyScene");
}
}