using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameMain : MonoBehaviour
{
[SerializeField] private List<GameObject> prefabs;
private int cnt = 0;
// Start is called before the first frame update
void Start()
{
var pool = PhotonNetwork.PrefabPool as DefaultPool;
foreach (GameObject prefab in this.prefabs)
{
pool.ResourceCache.Add(prefab.name, prefab);
}
PhotonManager.instance.Connect(() =>
{
this.CreatePlayer();
});
}
private void CreatePlayer()
{
Transform[] points = GameObject.Find("SpawnPointGroup").GetComponentsInChildren<Transform>();
int idx = Random.Range(1, points.Length); // 1 ~ 3
Transform initPoint = points[idx];
if (PhotonNetwork.IsMasterClient)
{
PhotonNetwork.Instantiate("NetworkRig", Vector3.zero, Quaternion.identity);
}
else
{
PhotonNetwork.Instantiate("Player", initPoint.position, initPoint.rotation);
}
Debug.Log("플레이어가 생성되었습니다.");
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using System;
public class PhotonManager : MonoBehaviourPunCallbacks
{
private readonly string version = "1.0.0";
public static PhotonManager instance; //싱글톤
public string nickname;
public Action onJoinedRoomAction;
private void Awake()
{
PhotonManager.instance = this;
}
public void Connect(Action onJoinedRoomCallback)
{
this.onJoinedRoomAction = onJoinedRoomCallback;
PhotonNetwork.AutomaticallySyncScene = true;
PhotonNetwork.GameVersion = version;
PhotonNetwork.NickName = this.nickname;
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
Debug.Log("마스터 서버 접속 됨");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
Debug.Log("로비에 접속됨");
PhotonNetwork.JoinRandomOrCreateRoom();
}
public override void OnJoinedRoom()
{
Debug.Log("룸에 입장");
this.onJoinedRoomAction();
}
public override void OnCreateRoomFailed(short returnCode, string message)
{
Debug.Log("룸 생성 실패 : " + message);
}
public override void OnJoinRandomFailed(short returnCode, string message)
{
Debug.Log("룸 입장 실패 : " + message);
}
public override void OnPlayerEnteredRoom(Player newPlayer)
{
Debug.LogFormat("{0}님이 룸에 입장", newPlayer.NickName);
}
}
'Giant vs Human 팀프로젝트 개발일지' 카테고리의 다른 글
[Giant vs Human 팀프로젝트] 해머구현 (1) | 2023.12.07 |
---|---|
[Giant vs Human 팀프로젝트/ Photon] 지연 보상 (1) | 2023.12.06 |
[Giant vs Human 팀프로젝트, Mobile] 죽은 후 일정 시간 후 리스폰 (0) | 2023.11.29 |
[Giant vs Human 팀프로젝트, Mobile] 대포가 주변에 있으면 대포발사 버튼이 활성화되고 버튼을 누르면 포탄이 발사 (0) | 2023.11.29 |
[Giant vs Human 팀프로젝트, Mobile] 조이스틱을 통한 이동, 버튼을 누르면 공격 (0) | 2023.11.29 |