Photon

[Photon] Photon Transform View, Photon Animator View

다모아 2023. 11. 27. 15:39

새로운 씬에 Player를 만들고 Resources 폴더에 프리팹으로 지정해준다.

Photon View와 Photn Transform View를 component에 추가해준다.

 

그냥 다시 SampleScene으로 돌아와서 작업

 

PhotonManager의 OnJoinedRoom에서 PhotonNetwork.Instantiate 해준다.

 

그리고 Build한 창과 유니티 상의 Play로 했을 때 2마리가 나오는지 확인해본다.

 

 

IsMine이 True인게 내가 사용할 수 있는 Player이다. False면 내꺼가 아님

IsMine이 True가 아닌 애의 Position이나 Rotation을 움직여도 동기화가 안되는걸 볼 수 있다.

 

IsMine에 따라 Build한 화면에서는 동기화가 되고 안되는걸 확인할 수 있다.

 

ConnectToMasterServer라는 Button 생성 후 마스터 접속을 닉네임 입력 후에 접속하게 만들기

 

 

방 만들기 버튼을 클릭했을 때

 

마스터 버튼을 클릭했을 때

 

Player에 Movement script 만들어서 추가해놓기

 

https://doc.photonengine.com/pun/current/demos-and-tutorials/pun-basics-tutorial/player-networking

 

7 - Player Networking | Photon Engine

This section will guide you to modify the "Player" prefab. We've first created a player that works as is, but now we are going to modify it...

doc.photonengine.com

 

https://doc-api.photonengine.com/en/pun/current/class_photon_1_1_pun_1_1_photon_view.html

 

Photon Unity Networking 2: PhotonView Class Reference

A PhotonView identifies an object across the network (viewID) and configures how the controlling client updates remote instances. More... Inherits MonoBehaviour. A PhotonView identifies an object across the network (viewID) and configures how the controlli

doc-api.photonengine.com

API

 

 

Player 프리팹에 Cnavas 추가해주

 

userId를 

using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using TMPro;
using UnityEngine;

public class Movement : MonoBehaviour
{
    private PhotonView photonView;
    public TMP_Text debugText;

    // Start is called before the first frame update
    void Start()
    {
        this.photonView = this.GetComponent<PhotonView>();
        StringBuilder sb = new StringBuilder();
        sb.Append(this.photonView.Owner.NickName);
        sb.AppendLine();
        sb.Append("IsMine: " + this.photonView.IsMine.ToString());


        this.debugText.text = sb.ToString();
    }

    // Update is called once per frame
    void Update()
    {
        if(this.photonView.IsMine)
        {

        }
    }
}