Beispiel #1
0
 void OnPhotonCustomRoomPropertiesChanged(Hashtable props)
 {
     foreach (object key in props.Keys)
     {
         if (key is string)
         {
             var parts = key.ToString().Split('$');
             if (parts.Length >= 3)
             {
                 // Could be one of our properties
                 string             id       = parts[0] + "$";
                 int                parentId = int.Parse(parts[1]);
                 string             path     = parts[2];
                 Hashtable          content  = (Hashtable)props[key];
                 NetworkReference   nref     = NetworkReference.FromIdAndPath(parentId, path);
                 NetworkBehaviour[] comps    = nref.FindComponents <NetworkBehaviour>();
                 foreach (NetworkBehaviour comp in comps)
                 {
                     if (comp.PropKey.StartsWith(id))
                     {
                         Debug.Log("RVD PROPS: " + content.ToString());
                         comp.RecvState(content);
                     }
                 }
             }
         }
     }
 }
        void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            int    pid  = 0;
            string path = null;

            if (stream.isWriting)
            {
                NetworkReference nref = NetworkReference.FromTransform(transform.parent);
                pid  = nref.parentHandleId;
                path = nref.pathFromParent;

                // Send update

                stream.Serialize(ref pid);
                stream.Serialize(ref path);
            }
            else
            {
                // Receive updated state information

                stream.Serialize(ref pid);
                stream.Serialize(ref path);

                newState.timestamp = info.timestamp;
                newState.parentId  = pid;
                newState.path      = path;
            }
        }
Beispiel #3
0
 public override void Apply()
 {
     var actualNor = NetworkReference.FromTransform(transform.parent);
     if (actualNor != parentNetRef) {
         //Debug.Log("Reparenting from " + actualNor + " to " + parentNetRef);
         GameObject newParent = parentNetRef.FindObject();
         //Debug.Log("New parent " + newParent);
         transform.parent = newParent != null ? newParent.transform : null;
     }
     base.Apply();
 }
        void UpdateParent()
        {
            var actualNref = NetworkReference.FromTransform(transform.parent);
            var newNref    = NetworkReference.FromIdAndPath(newState.parentId, newState.path);

            if (actualNref != newNref)
            {
                //Debug.Log("Reparenting from " + actualNref + " to " + newNref);
                GameObject newParent = newNref.FindObject();
                //Debug.Log("New parent " + newParent);
                transform.parent = newParent != null ? newParent.transform : null;
            }
        }
Beispiel #5
0
 public bool Equals(NetworkReference other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(parentHandleId == other.parentHandleId &&
            pathFromParent == other.pathFromParent);
 }
Beispiel #6
0
            public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
            {
                int        pid   = 0;
                string     path  = null;
                Vector3    pos   = Vector3.zero;
                Quaternion rot   = Quaternion.identity;
                Vector3    scale = Vector3.one;
                Vector3    v     = Vector3.zero;
                Vector3    angv  = Vector3.zero;

                if (stream.isWriting)
                {
                    if (component is Transform)
                    {
                        Transform        transform = (Transform)component;
                        NetworkReference nref      = NetworkReference.FromTransform(transform.parent);
                        pid  = nref.parentHandleId;
                        path = nref.pathFromParent;
                        if (nit.useLocalValues)
                        {
                            pos = transform.localPosition;
                            rot = transform.localRotation;
                        }
                        else
                        {
                            pos = transform.position;
                            rot = transform.rotation;
                        }
                        scale = transform.localScale;
                        if (!nit.onChangeOnly || slotsUsed == 0 || hasChanged(pid, path, pos, rot, scale, v, angv))
                        {
                            // Send update
                            if (nit.parent)
                            {
                                stream.Serialize(ref pid);
                                stream.Serialize(ref path);
                            }
                            if (nit.position != UpdateMode.None)
                            {
                                stream.Serialize(ref pos);
                            }
                            if (nit.rotation != UpdateMode.None)
                            {
                                stream.Serialize(ref rot);
                            }
                            if (nit.scale != UpdateMode.None)
                            {
                                stream.Serialize(ref scale);
                            }
                        }
                    }
                    else if (component is Rigidbody)
                    {
                        Rigidbody rbody = (Rigidbody)component;
                        v    = rbody.velocity;
                        angv = rbody.angularVelocity;
                        if (!nit.onChangeOnly || slotsUsed == 0 || hasChanged(pid, path, pos, rot, scale, v, angv))
                        {
                            // Send update
                            if (nit.velocity != UpdateMode.None)
                            {
                                stream.Serialize(ref v);
                            }
                            if (nit.angularVelocity != UpdateMode.None)
                            {
                                stream.Serialize(ref angv);
                            }
                        }
                    }
                    if (nit.onChangeOnly)
                    {
                        // Keep a copy
                        State state;
                        state.timestamp = info.timestamp;
                        state.parentId  = pid;
                        state.path      = path;
                        state.pos       = pos;
                        state.rot       = rot;
                        state.scale     = scale;
                        state.v         = v;
                        state.angv      = angv;
                        states[0]       = state;
                        slotsUsed       = 1;
                    }
                }
                else
                {
                    // Receive updated state information
                    if (component is Transform)
                    {
                        Transform transform = component.transform;
                        if (nit.parent)
                        {
                            stream.Serialize(ref pid);
                            stream.Serialize(ref path);
                        }
                        if (nit.position != UpdateMode.None)
                        {
                            stream.Serialize(ref pos);
                        }
                        if (nit.rotation != UpdateMode.None)
                        {
                            stream.Serialize(ref rot);
                        }
                        if (nit.scale != UpdateMode.None)
                        {
                            stream.Serialize(ref scale);
                        }
                    }
                    else if (component is Rigidbody)
                    {
                        Rigidbody rbody = (Rigidbody)component;
                        if (nit.velocity != UpdateMode.None)
                        {
                            stream.Serialize(ref v);
                        }
                        if (nit.angularVelocity != UpdateMode.None)
                        {
                            stream.Serialize(ref angv);
                        }
                    }
                    // Make sure the update was received in the correct order
                    // If not we simply drop it
                    if (slotsUsed == 0 || states[lastRcvdSlot].timestamp <= info.timestamp)
                    {
                        // Save currect received state in the next free slot
                        State state;
                        state.timestamp      = info.timestamp;
                        state.parentId       = pid;
                        state.path           = path;
                        state.pos            = pos;
                        state.rot            = rot;
                        state.scale          = scale;
                        state.v              = v;
                        state.angv           = angv;
                        states[nextFreeSlot] = state;
                        // Increment nextSlot wrapping around to 0 when getting to the end
                        lastRcvdSlot = nextFreeSlot;
                        nextFreeSlot = (nextFreeSlot + 1) % states.Length;
                        // Increment the number of unhandled updates currently in the buffer
                        slotsUsed = Mathf.Min(slotsUsed + 1, states.Length);
                    }
                }
            }
Beispiel #7
0
 public override void Retain()
 {
     prevParentNetRef = parentNetRef;
 }
Beispiel #8
0
 public override void Obtain()
 {
     parentNetRef = NetworkReference.FromTransform(transform.parent);
 }