PhotonView Class Reference

Public Member Functions

void RequestOwnership ()
 Depending on the PhotonView's ownershipTransfer setting, any client can request to become owner of the PhotonViewMore...
 
void TransferOwnership (PhotonPlayer newOwner)
 Transfers the ownership of this PhotonView (and GameObject) to another player. More...
 
void TransferOwnership (int newOwnerId)
 Transfers the ownership of this PhotonView (and GameObject) to another player. More...
 
void OnMasterClientSwitched (PhotonPlayer newMasterClient)
 Check ownerId assignment for sceneObjects to keep being owned by the MasterClient. More...
 
void SerializeView (PhotonStream stream, PhotonMessageInfo info)
 
void DeserializeView (PhotonStream stream, PhotonMessageInfo info)
 
void RefreshRpcMonoBehaviourCache ()
 Can be used to refesh the list of MonoBehaviours on this GameObject while PhotonNetwork.UseRpcMonoBehaviourCache is true. More...
 
void RPC (string methodName, PhotonTargets target, params object[] parameters)
 Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client). More...
 
void RpcSecure (string methodName, PhotonTargets target, bool encrypt, params object[] parameters)
 Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client). More...
 
void RPC (string methodName, PhotonPlayer targetPlayer, params object[] parameters)
 Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client). More...
 
void RpcSecure (string methodName, PhotonPlayer targetPlayer, bool encrypt, params object[] parameters)
 Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client). More...
 
override string ToString ()


PhotonView 클래스는 네트워크상에 전송되는 오브젝트를 위한것으로 보인다 유니티네트워크의 NetworkIdentity 컴포넌트와 비슷한 역할을 하는듯하다


홈페이지에서는 아래와같이 설명되었있다


네트워크 객체

일반 GameObject들은 PhotonView 컴포넌트가 있는 네트워크 객체로 전환될 수 있습니다. PhotonView는 네트워크를 통해 객체를 식별하고 해당 객체의 상태를 동기화하는 데 사용됩니다. 일반적으로, PhotonView는 런타임에 인스턴스화된 프리팹에 연결됩니다. 종종 모든 선수들은 통제할 자신만의 객체들을 가지고 있습니다.

GameObject에 PhotonView를 추가하기위해서는, 단순히 GameObject를 선택하고 사용하면 됩니다:"Components/Miscellaneous/Photon View"

Transform 동기화


튜도리얼에 따르면 트랜스폼 동기화를 위한 컴포넌트가 PhotonTransformView  라고 되었는데 PUN2 에서는  튜토리얼버전은 클래식으로 되어있다. 클래식에 비해 옵션이 없기때문에 사용이 좀더 편해보인다



Animation 동기화


PhotonAnimatiorView 스크립트를 추가하면 해당 오브젝트의 animator 에서 레이어와 파라미터를 친절하게 가져와준다


Discreate : 초당 10회의 데이터를 전송

Continuous : 매 프레임마다 데이터를 전송






위에 두 컴포넌트를 추가한 뒤 PhotonView 컴포넌트에 observed components에 추가해주자





기타 컴포넌트 동기화


동기화가 필요한 컴포넌트일 경우 IPunObservable 인터페이스를 상속받아 OnPhotonSerializeView를 정의 후 

위 컴포넌트들 처럼 PhotoView 컴포넌트에 추가해준다


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class PlayerManager : MonoBehaviourPunCallbacks , IPunObservable
{
 
     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)        
    {
            if (stream.IsWriting)
            {             
                stream.SendNext(IsFiring);
            }
            else
            {          
                this.IsFiring = (bool)stream.ReceiveNext();
            }
    }
}
cs


+ Recent posts