コード例 #1
0
        internal static void HandleChildTransform(NetworkMessage netMsg)
        {
            LocalChildTransformMessage message = netMsg.ReadMessage <LocalChildTransformMessage>();

            GameObject foundObj = NetworkServer.FindLocalObject(message.netId);

            if (foundObj == null)
            {
                Debug.LogError("Received NetworkTransformChild data for GameObject that doesn't exist");
                return;
            }
            var children = foundObj.GetComponents <NetworkTransformChild>();

            if (children == null || children.Length == 0)
            {
                Debug.LogError("HandleChildTransform no children");
                return;
            }
            if (message.childIndex >= children.Length)
            {
                Debug.LogError("HandleChildTransform childIndex invalid");
                return;
            }

            NetworkTransformChild foundSync = children[message.childIndex];

            if (foundSync == null)
            {
                Debug.LogError("HandleChildTransform null target");
                return;
            }
            if (!foundSync.localPlayerAuthority)
            {
                Debug.LogError("HandleChildTransform no localPlayerAuthority");
                return;
            }

            if (!netMsg.conn.clientOwnedObjects.Contains(message.netId))
            {
                Debug.LogWarning("NetworkTransformChild netId:" + message.netId + " is not for a valid player");
                return;
            }

            foundSync.UnserializeModeTransform(new NetworkReader(message.payload), false);
            foundSync.m_LastClientSyncTime = Time.time;

            if (!foundSync.isClient)
            {
                // dedicated server wont interpolate, so snap.
                foundSync.m_Target.localPosition = foundSync.m_TargetSyncPosition;
                foundSync.m_Target.localRotation = foundSync.m_TargetSyncRotation3D;
            }
        }
コード例 #2
0
        void SendTransform()
        {
            if (!HasMoved() || ClientScene.readyConnection == null)
            {
                return;
            }

            NetworkWriter writer = new NetworkWriter();

            SerializeModeTransform(writer);

            LocalChildTransformMessage message = new LocalChildTransformMessage();

            message.netId      = netId;
            message.childIndex = m_ChildIndex;
            message.payload    = writer.ToArray();

            m_PrevPosition = m_Target.localPosition;
            m_PrevRotation = m_Target.localRotation;

            ClientScene.readyConnection.Send((short)MsgType.LocalChildTransform, message);
        }