photonView.IsMine

True if the PhotonView is "mine" and can be controlled by this client.

PUN has an ownership concept that defines who can control and destroy each PhotonView. True in case the owner matches the local Player. True if this is a scene photonview on the Master client.


OnPhotonSerializeView

Called by PUN several times per second, so that your script can write and read synchronization data for the PhotonView.

This method will be called in scripts that are assigned as Observed component of a PhotonView.
PhotonNetwork.SerializationRate affects how often this method is called.
PhotonNetwork.SendRate affects how often packages are sent by this client.

Implementing this method, you can customize which data a PhotonView regularly synchronizes. Your code defines what is being sent (content) and how your data is used by receiving clients.

Unlike other callbacks, OnPhotonSerializeView only gets called when it is assigned to a PhotonView as PhotonView.observed script.

To make use of this method, the PhotonStream is essential. It will be in "writing" mode" on the client that controls a PhotonView (PhotonStream.IsWriting == true) and in "reading mode" on the remote clients that just receive that the controlling client sends.

If you skip writing any value into the stream, PUN will skip the update. Used carefully, this can conserve bandwidth and messages (which have a limit per room/second).

Note that OnPhotonSerializeView is not called on remote clients when the sender does not send any update. This can't be used as "x-times per second Update()".

Implemented in PhotonAnimatorViewCullingHandlerPhotonRigidbody2DViewPhotonRigidbodyViewPhotonTransformView, and SmoothSyncMovement.


놀러가야 돼서 해석은 차후에...



분석한 스크립트(위 도식과 함께 볼 것!)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using Valve.VR;
 
public class cntrlNet : MonoBehaviourPunCallbacks, IPunObservable {
 
    private Transform tr;
 
    private GameObject tiltBrush;
 
    public SteamVR_Input_Sources any = SteamVR_Input_Sources.Any;
    public SteamVR_Action_Boolean triggerAction;
 
    private bool isTriggerDown = false;
 
    void Start()
    {
        tr = GetComponent<Transform>();
 
        tiltBrush = GameObject.Find("tiltBrush");
        tiltBrush.SetActive(false);
 
        if (SteamVR_Input.initialized == false)
        {
            Debug.Log("cntrl is not detected");
            return;
        }
    }
 
    void Update () {
        //controlled locally일 경우 이동(자기 자신의 캐릭터일 때)
        if (photonView.IsMine)
        {
//트리거 상태를 체크해서 보내기 위한(currTrigger에 보내는)
            if (triggerAction.GetState(SteamVR_Input_Sources.Any))
            {
                isTriggerDown = true;
            }
            else
            {
                isTriggerDown = false;
            }
 
            if (SteamVR_Input._default.inActions.InteractUI.GetStateDown(SteamVR_Input_Sources.Any))
            {
                tiltBrush.SetActive(true);
            }
            else if (SteamVR_Input._default.inActions.InteractUI.GetStateUp(SteamVR_Input_Sources.Any))
            {
                tiltBrush.SetActive(false);
            }
        } 
        else
        {
            //끊어진 시간이 너무 길 경우(텔레포트)
            if ((tr.position - currPos).sqrMagnitude >= 10.0f * 10.0f)
            {
                tr.position = currPos;
                tr.rotation = currRot;
            }
            //끊어진 시간이 짧을 경우(자연스럽게 연결 - 데드레커닝)
            else
            {
                tr.position = Vector3.Lerp(tr.position, currPos, Time.deltaTime * 10.0f);
                tr.rotation = Quaternion.Slerp(tr.rotation, currRot, Time.deltaTime * 10.0f);
            }
 
            tiltBrush.SetActive(currTrigger);
        }
 
    }
 
    //클론이 통신을 받는 변수 설정
    private Vector3 currPos;
    private Quaternion currRot;
    private bool currTrigger;
 
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        //통신을 보내는 
        if (stream.IsWriting)
        {
            stream.SendNext(tr.position);
            stream.SendNext(tr.rotation);
            stream.SendNext(isTriggerDown);
        }
 
        //클론이 통신을 받는 
        else
        {
            currPos = (Vector3)stream.ReceiveNext();
            currRot = (Quaternion)stream.ReceiveNext();
            currTrigger = (bool)stream.ReceiveNext();
        }
    }
}
  cs




[참조]

http://itmining.tistory.com/25 

http://doc-api.photonengine.com/en/pun/v2/index.html

Posted by 도이(doi)
,