본문 바로가기
반응형

개발/Photon14

유니티 C# 포톤 채팅 간단 구현 Photon Chat 패키지 임포트 Photon Chat | 네트워크 | Unity Asset Store Get the Photon Chat package from Photon Engine and speed up your game development process. Find this & other 네트워크 options on the Unity Asset Store. assetstore.unity.com 코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Chat; using ExitGames.Client.Photon; using UnityEngine.UI; using System.IO; using Sy.. 2024. 3. 27.
유니티 C# 포톤 회전값 지연보상 간단 구현 Photon 코드 작성 void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.IsWriting) { stream.SendNext(transform.rotation); } else { Quaternion rotation = (Quaternion)stream.ReceiveNext(); float lag = Mathf.Abs((float)(PhotonNetwork.Time - info.timestamp)); transform.rotation = Quaternion.Lerp(transform.rotation, rotation, lag); } } 2023. 3. 8.
유니티 C# 포톤 매치메이킹 만들기 방 입장조건 걸기 Photon Matching Room 입장조건이 있는 방 만들기 void JoinOrCreateRoom() { RoomOptions roomOption = new RoomOptions(); roomOption.MaxPlayers = 2; roomOption.CustomRoomPropertiesForLobby = new string[] { "difficulty" }; roomOption.CustomRoomProperties = new Hashtable() { { "difficulty", "easy" } }; PhotonNetwork.JoinOrCreateRoom("room name", roomOption, null); } 조건에 맞는 방 참여하기 public void JoinRandomRoom() { Hashtable roomPropertie.. 2023. 3. 8.
유니티 C# 포톤 동적 오브젝트 생성 후 동기화 Photon Instantiate 유니티에서 제공하는 Instantiate가 아닌 포톤에서 제공하는 PhotonNetwork.Instantiate로 생성한뒤 Photon Transform View 또는 Photon Animator View 를 달아주게 되면 자동으로 동기화가 이루어집니다. 생성할 Prefab의 위치는 Resource 폴더 안에 있어야합니다. 코드 예시 using UnityEngine; using Photon.Pun; public class MyScript : MonoBehaviourPunCallbacks { public GameObject prefab; void Start() { PhotonNetwork.Instantiate(prefab.name, transform.position, transform.rotation, 0.. 2023. 3. 8.
유니티 C# 포톤 코루틴 간단 사용 Photon Coroution 코드 작성 using System; using System.Collections; using UnityEngine; using Photon.Pun; using Photon.Realtime; using UnityEngine.UI; public class NetworkManager : MonoBehaviourPunCallbacks { int hp = 100; public Text hpText; public PhotonView PV; private void Start() { StartTimer(); } void StartTimer() { if(PhotonNetwork.IsMasterClient) { hp = 100; StartCoroutine(TimerCoroution()); } } IEnumerator Ti.. 2022. 12. 22.
유니티 C# 포톤 씬 로드하기 Photon Scene Load 코드 작성 using System; using System.Collections; using UnityEngine; using Photon.Pun; using Photon.Realtime; public class NetworkManager : MonoBehaviourPunCallbacks { private void LoadScene() { PhotonNetwork.LoadLevel("Scene Name"); } } 2022. 12. 22.
유니티 C# 포톤 타이머 간단 구현 Photon Timer 코드 작성 using System; using System.Collections; using UnityEngine; using Photon.Pun; using Photon.Realtime; using UnityEngine.UI; public class NetworkManager : MonoBehaviourPunCallbacks { int time = 0; public Text timerText; public PhotonView PV; private void Start() { StartTimer(); } void StartTimer() { if(PhotonNetwork.IsMasterClient) { time = 60; StartCoroutine(TimerCoroution()); } } IEnumerato.. 2022. 12. 22.
유니티 C# 포톤 소유권 제어하기 Photon Ownership 코드 작성 전 주의사항 스크립트가 달린 오브젝트의 PhotonView에서 OwnershipSphere 옵션이 TakeOver로 설정되어 있어야합니다. "Fixed" 는 게임오브젝트를 생성한 것이 지속적으로 소유자로 유지 되는 것입니다. "Takeover" 다른 클라이언트가 현재 오너로 부터 소유권을 가져갈 수 있도록 합니다. "Request" 현재 오너에게 소유권을 요청 할 수 있으나 거절 될 수 있는 것 입니다. 코드 작성 using System; using System.Collections; using UnityEngine; using Photon.Pun; using Photon.Realtime; public class Player : MonoBehaviourPunCallbacks { public P.. 2022. 12. 22.
유니티 C# 포톤 커스텀 프로퍼티 간단 사용법 Photon Custom Property 코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; using UnityEngine.UI; using Hashtable = ExitGames.Client.Photon.Hashtable; public class NetworkManager : MonoBehaviourPunCallbacks { public override void OnJoinedRoom() { statusText.text = "방에 참가하였습니다."; if (PhotonNetwork.IsMasterClient) { PhotonNetwork.CurrentRoom.SetCus.. 2022. 12. 22.
유니티 C# 포톤 변수 동기화 Photon RPC 코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; using UnityEngine.UI; public class NetworkManager : MonoBehaviourPunCallbacks { int towerHp = 100; bool isRaining = false; public PhotonView PV; void AttackTower() { PV.RPC("HitTower", RpcTarget.All); //방 전체 사람들에게 타워 체력 -10 PV.RPC("HitTower", RpcTarget.All, 10); PV.RPC("H.. 2022. 12. 22.
유니티 C# 포톤 방 참가 퇴장 알림 간단 구현 Photon RPC 코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; using UnityEngine.UI; public class NetworkManager : MonoBehaviourPunCallbacks { public Text notionText; public PhotonView PV; private void Awake() { PV = GetComponent(); } public override void OnPlayerEnteredRoom(Player newPlayer) { PV.RPC("NotionRPC", RpcTarget.All, newP.. 2022. 12. 22.
유니티 C# 포톤 방 설정하기 Photon RoomOptions 코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; using UnityEngine.UI; public class NetworkManager : MonoBehaviourPunCallbacks { public void CreateRoom() { PhotonNetwork.LocalPlayer.NickName = "닉네임 설정"; RoomOptions roomOption = new RoomOptions(); roomOption.MaxPlayers = 4; //최대 인원수 설정 roomOption.IsOpen = true; //방이 열려있는.. 2022. 12. 22.
반응형