Наследование: NetworkBehaviour
        void SerializeModeTransform(NetworkWriter writer)
        {
            int start = writer.Position;

            foreach (var bone in m_Bones)
            {
                // position
                writer.Write(bone.localPosition);

                // rotation
                if (m_SyncRotationAxis != NetworkTransform.AxisSyncMode.None)
                {
                    NetworkTransform.SerializeRotation3D(writer, bone.localRotation, syncRotationAxis, rotationSyncCompression);
                }
            }

            int sz = writer.Position - start;

            if (sz > 1400 && binarySize == 0)
            {
                // this is only generated once.
                Debug.LogWarning("NetworkSkeleton binary serialization size is very large:" + sz + ". Consider reducing the number of levels being synchronized.");
            }
            binarySize = sz;
        }
        void UnserializeModeTransform(NetworkReader reader, bool initialState)
        {
            if (hasAuthority)
            {
                // this component must read the data that the server wrote, even if it ignores it.
                // otherwise the NetworkReader stream will still contain that data for the next component.

                for (int i = 0; i < m_Bones.Length; i++)
                {
                    // position
                    reader.ReadVector3();

                    if (syncRotationAxis != NetworkTransform.AxisSyncMode.None)
                    {
                        NetworkTransform.UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression);
                    }
                }
                return;
            }

            for (int i = 0; i < m_Bones.Length; i++)
            {
                var boneInfo = m_BoneInfos[i];

                // position
                boneInfo.m_TargetSyncPosition = reader.ReadVector3();

                // rotation
                if (syncRotationAxis != NetworkTransform.AxisSyncMode.None)
                {
                    var rot = NetworkTransform.UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression);
                    boneInfo.m_TargetSyncRotation3D = rot;
                }
            }
        }
 public override void OnStartClient()
 {
   if (!((Object) this.m_VisualizerPrefab != (Object) null))
     return;
   this.m_NetworkTransform = this.GetComponent<NetworkTransform>();
   NetworkTransformVisualizer.CreateLineMaterial();
   this.m_Visualizer = (GameObject) Object.Instantiate((Object) this.m_VisualizerPrefab, this.transform.position, Quaternion.identity);
 }
Пример #4
0
 public override void OnStartClient()
 {
     if (m_VisualizerPrefab != null)
     {
         m_NetworkTransform = GetComponent <NetworkTransform>();
         CreateLineMaterial();
         m_Visualizer = (GameObject)Instantiate(m_VisualizerPrefab, transform.position, Quaternion.identity);
     }
 }
Пример #5
0
 public override void OnStartClient()
 {
     if (this.m_VisualizerPrefab != null)
     {
         this.m_NetworkTransform = base.GetComponent <NetworkTransform>();
         CreateLineMaterial();
         this.m_Visualizer = (GameObject)UnityEngine.Object.Instantiate(this.m_VisualizerPrefab, base.transform.position, Quaternion.identity);
     }
 }
 public override void OnStartClient()
 {
     if (!((Object)this.m_VisualizerPrefab != (Object)null))
     {
         return;
     }
     this.m_NetworkTransform = this.GetComponent <NetworkTransform>();
     NetworkTransformVisualizer.CreateLineMaterial();
     this.m_Visualizer = (GameObject)Object.Instantiate((Object)this.m_VisualizerPrefab, this.transform.position, Quaternion.identity);
 }
Пример #7
0
 private void SerializeModeTransform(NetworkWriter writer)
 {
     writer.Write(this.m_Target.localPosition);
     if (this.m_SyncRotationAxis != NetworkTransform.AxisSyncMode.None)
     {
         NetworkTransform.SerializeRotation3D(writer, this.m_Target.localRotation, this.syncRotationAxis, this.rotationSyncCompression);
     }
     this.m_PrevPosition = this.m_Target.localPosition;
     this.m_PrevRotation = this.m_Target.localRotation;
 }
        void UnserializeModeTransform(NetworkReader reader, bool initialState)
        {
            if (hasAuthority)
            {
                // this component must read the data that the server wrote, even if it ignores it.
                // otherwise the NetworkReader stream will still contain that data for the next component.

                // position
                reader.ReadVector3();

                if (syncRotationAxis != NetworkTransform.AxisSyncMode.None)
                {
                    NetworkTransform.UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression);
                }
                return;
            }

            if (isServer && m_ClientMoveCallback3D != null)
            {
                var pos = reader.ReadVector3();
                var vel = Vector3.zero;
                var rot = Quaternion.identity;
                if (syncRotationAxis != NetworkTransform.AxisSyncMode.None)
                {
                    rot = NetworkTransform.UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression);
                }

                if (m_ClientMoveCallback3D(ref pos, ref vel, ref rot))
                {
                    m_TargetSyncPosition = pos;
                    if (syncRotationAxis != NetworkTransform.AxisSyncMode.None)
                    {
                        m_TargetSyncRotation3D = rot;
                    }
                }
                else
                {
                    // rejected by callback
                    return;
                }
            }
            else
            {
                // position
                m_TargetSyncPosition = reader.ReadVector3();

                // rotation
                if (syncRotationAxis != NetworkTransform.AxisSyncMode.None)
                {
                    m_TargetSyncRotation3D = NetworkTransform.UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression);
                }
            }
        }
 public void Init()
 {
     if (!this.m_Initialized)
     {
         this.m_Initialized = true;
         this.m_SyncTransform = base.target as NetworkTransform;
         if (this.m_SyncTransform.transformSyncMode == NetworkTransform.TransformSyncMode.SyncNone)
         {
             if (this.m_SyncTransform.GetComponent<Rigidbody>() != null)
             {
                 this.m_SyncTransform.transformSyncMode = NetworkTransform.TransformSyncMode.SyncRigidbody3D;
                 this.m_SyncTransform.syncRotationAxis = NetworkTransform.AxisSyncMode.AxisXYZ;
                 EditorUtility.SetDirty(this.m_SyncTransform);
             }
             else if (this.m_SyncTransform.GetComponent<Rigidbody2D>() != null)
             {
                 this.m_SyncTransform.transformSyncMode = NetworkTransform.TransformSyncMode.SyncRigidbody2D;
                 this.m_SyncTransform.syncRotationAxis = NetworkTransform.AxisSyncMode.AxisZ;
                 EditorUtility.SetDirty(this.m_SyncTransform);
             }
             else if (this.m_SyncTransform.GetComponent<CharacterController>() != null)
             {
                 this.m_SyncTransform.transformSyncMode = NetworkTransform.TransformSyncMode.SyncCharacterController;
                 this.m_SyncTransform.syncRotationAxis = NetworkTransform.AxisSyncMode.AxisXYZ;
                 EditorUtility.SetDirty(this.m_SyncTransform);
             }
             else
             {
                 this.m_SyncTransform.transformSyncMode = NetworkTransform.TransformSyncMode.SyncTransform;
                 this.m_SyncTransform.syncRotationAxis = NetworkTransform.AxisSyncMode.AxisXYZ;
                 EditorUtility.SetDirty(this.m_SyncTransform);
             }
         }
         this.m_TransformSyncMode = base.serializedObject.FindProperty("m_TransformSyncMode");
         this.m_MovementTheshold = base.serializedObject.FindProperty("m_MovementTheshold");
         this.m_SnapThreshold = base.serializedObject.FindProperty("m_SnapThreshold");
         this.m_InterpolateRotation = base.serializedObject.FindProperty("m_InterpolateRotation");
         this.m_InterpolateMovement = base.serializedObject.FindProperty("m_InterpolateMovement");
         this.m_RotationSyncCompression = base.serializedObject.FindProperty("m_RotationSyncCompression");
         this.m_SyncSpin = base.serializedObject.FindProperty("m_SyncSpin");
         this.m_NetworkSendIntervalProperty = base.serializedObject.FindProperty("m_SendInterval");
         this.m_NetworkSendIntervalLabel = new GUIContent("Network Send Rate (seconds)", "Number of network updates per second");
         EditorGUI.indentLevel++;
         this.m_MovementThesholdLabel = new GUIContent("Movement Threshold");
         this.m_SnapThresholdLabel = new GUIContent("Snap Threshold");
         this.m_InterpolateRotationLabel = new GUIContent("Interpolate Rotation Factor");
         this.m_InterpolateMovementLabel = new GUIContent("Interpolate Movement Factor");
         this.m_RotationSyncCompressionLabel = new GUIContent("Compress Rotation");
         this.m_SyncSpinLabel = new GUIContent("Sync Angular Velocity");
         EditorGUI.indentLevel--;
     }
 }
        void SerializeModeTransform(NetworkWriter writer)
        {
            // position
            writer.Write(m_Target.localPosition);

            // rotation
            if (m_SyncRotationAxis != NetworkTransform.AxisSyncMode.None)
            {
                NetworkTransform.SerializeRotation3D(writer, m_Target.localRotation, syncRotationAxis, rotationSyncCompression);
            }
            m_PrevPosition = m_Target.localPosition;
            m_PrevRotation = m_Target.localRotation;
        }
Пример #11
0
        void UnserializeModeTransform(NetworkReader reader, bool initialState)
        {
            //IMPORTANT: Time critical: Don't put print statements in loop!  Makess Unity hang.
            //print("SN:Unserialize numbones= "+ m_Bones.Length);
            if (hasAuthority)
            {
                // this component must read the data that the server wrote, even if it ignores it.
                // otherwise the NetworkReader stream will still contain that data for the next component.

                for (int i = 0; i < m_Bones.Length; i++)
                {
                    // position
                    reader.ReadVector3();

                    if (syncRotationAxis != NetworkTransform.AxisSyncMode.None)
                    {
                        NetworkTransform.UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression);
                    }
                }
                return;
            }

            for (int i = 0; i < m_Bones.Length; i++)
            {
                var boneInfo = m_BoneInfos[i];

                // position
                Vector3 pos = reader.ReadVector3();
                boneInfo.m_TargetSyncPosition = pos;

                // rotation
                if (syncRotationAxis != NetworkTransform.AxisSyncMode.None)
                {
                    var rot = NetworkTransform.UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression);
                    //rot = Quaternion.identity;
                    boneInfo.m_TargetSyncRotation3D = rot;
                    if (pos.x == 111 && pos.z == 333)  //this joint was not sent, so skip
                    {
                        //Debug.Log ("unserialize count = " + pos.y);
                        boneInfo.valid = false;
                    }
                }
            }
        }
Пример #12
0
 private void UnserializeModeTransform(NetworkReader reader, bool initialState)
 {
     if (this.hasAuthority)
     {
         reader.ReadVector3();
         if (this.syncRotationAxis == NetworkTransform.AxisSyncMode.None)
         {
             return;
         }
         NetworkTransform.UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
     }
     else if (this.isServer && this.m_ClientMoveCallback3D != null)
     {
         Vector3    position = reader.ReadVector3();
         Vector3    zero     = Vector3.zero;
         Quaternion rotation = Quaternion.identity;
         if (this.syncRotationAxis != NetworkTransform.AxisSyncMode.None)
         {
             rotation = NetworkTransform.UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
         }
         if (!this.m_ClientMoveCallback3D(ref position, ref zero, ref rotation))
         {
             return;
         }
         this.m_TargetSyncPosition = position;
         if (this.syncRotationAxis == NetworkTransform.AxisSyncMode.None)
         {
             return;
         }
         this.m_TargetSyncRotation3D = rotation;
     }
     else
     {
         this.m_TargetSyncPosition = reader.ReadVector3();
         if (this.syncRotationAxis == NetworkTransform.AxisSyncMode.None)
         {
             return;
         }
         this.m_TargetSyncRotation3D = NetworkTransform.UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
     }
 }
 private static float ReadAngle(NetworkReader reader, NetworkTransform.CompressionSyncMode compression)
 {
   switch (compression)
   {
     case NetworkTransform.CompressionSyncMode.None:
       return reader.ReadSingle();
     case NetworkTransform.CompressionSyncMode.Low:
       return (float) reader.ReadInt16();
     case NetworkTransform.CompressionSyncMode.High:
       return (float) reader.ReadInt16();
     default:
       return 0.0f;
   }
 }
 private static void WriteAngle(NetworkWriter writer, float angle, NetworkTransform.CompressionSyncMode compression)
 {
   switch (compression)
   {
     case NetworkTransform.CompressionSyncMode.None:
       writer.Write(angle);
       break;
     case NetworkTransform.CompressionSyncMode.Low:
       writer.Write((short) angle);
       break;
     case NetworkTransform.CompressionSyncMode.High:
       writer.Write((short) angle);
       break;
   }
 }
 public static float UnserializeSpin2D(NetworkReader reader, NetworkTransform.CompressionSyncMode compression)
 {
   return NetworkTransform.ReadAngle(reader, compression);
 }
 public static Vector3 UnserializeSpin3D(NetworkReader reader, NetworkTransform.AxisSyncMode mode, NetworkTransform.CompressionSyncMode compression)
 {
   Vector3 zero = Vector3.zero;
   switch (mode)
   {
     case NetworkTransform.AxisSyncMode.AxisX:
       zero.Set(NetworkTransform.ReadAngle(reader, compression), 0.0f, 0.0f);
       break;
     case NetworkTransform.AxisSyncMode.AxisY:
       zero.Set(0.0f, NetworkTransform.ReadAngle(reader, compression), 0.0f);
       break;
     case NetworkTransform.AxisSyncMode.AxisZ:
       zero.Set(0.0f, 0.0f, NetworkTransform.ReadAngle(reader, compression));
       break;
     case NetworkTransform.AxisSyncMode.AxisXY:
       zero.Set(NetworkTransform.ReadAngle(reader, compression), NetworkTransform.ReadAngle(reader, compression), 0.0f);
       break;
     case NetworkTransform.AxisSyncMode.AxisXZ:
       zero.Set(NetworkTransform.ReadAngle(reader, compression), 0.0f, NetworkTransform.ReadAngle(reader, compression));
       break;
     case NetworkTransform.AxisSyncMode.AxisYZ:
       zero.Set(0.0f, NetworkTransform.ReadAngle(reader, compression), NetworkTransform.ReadAngle(reader, compression));
       break;
     case NetworkTransform.AxisSyncMode.AxisXYZ:
       zero.Set(NetworkTransform.ReadAngle(reader, compression), NetworkTransform.ReadAngle(reader, compression), NetworkTransform.ReadAngle(reader, compression));
       break;
   }
   return zero;
 }
Пример #17
0
 private void OnValidate()
 {
     if (this.m_Target != null)
     {
         Transform parent = this.m_Target.parent;
         if (parent == null)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("NetworkTransformChild target cannot be the root transform.");
             }
             this.m_Target = null;
             return;
         }
         while (parent.parent != null)
         {
             parent = parent.parent;
         }
         this.m_Root = parent.gameObject.GetComponent <NetworkTransform>();
         if (this.m_Root == null)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("NetworkTransformChild root must have NetworkTransform");
             }
             this.m_Target = null;
             return;
         }
     }
     if (this.m_Root != null)
     {
         this.m_ChildIndex = uint.MaxValue;
         NetworkTransformChild[] components = this.m_Root.GetComponents <NetworkTransformChild>();
         uint num = 0u;
         while ((ulong)num < (ulong)((long)components.Length))
         {
             if (components[(int)((UIntPtr)num)] == this)
             {
                 this.m_ChildIndex = num;
                 break;
             }
             num += 1u;
         }
         if (this.m_ChildIndex == 4294967295u)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("NetworkTransformChild component must be a child in the same hierarchy");
             }
             this.m_Target = null;
         }
     }
     if (this.m_SendInterval < 0f)
     {
         this.m_SendInterval = 0f;
     }
     if (this.m_SyncRotationAxis < NetworkTransform.AxisSyncMode.None || this.m_SyncRotationAxis > NetworkTransform.AxisSyncMode.AxisXYZ)
     {
         this.m_SyncRotationAxis = NetworkTransform.AxisSyncMode.None;
     }
     if (this.movementThreshold < 0f)
     {
         this.movementThreshold = 0f;
     }
     if (this.interpolateRotation < 0f)
     {
         this.interpolateRotation = 0.01f;
     }
     if (this.interpolateRotation > 1f)
     {
         this.interpolateRotation = 1f;
     }
     if (this.interpolateMovement < 0f)
     {
         this.interpolateMovement = 0.01f;
     }
     if (this.interpolateMovement > 1f)
     {
         this.interpolateMovement = 1f;
     }
 }
Пример #18
0
        public static void HandleTransform(NetworkMessage netMsg)
        {
            NetworkInstanceId networkInstanceId = netMsg.reader.ReadNetworkId();
            GameObject        gameObject        = NetworkServer.FindLocalObject(networkInstanceId);

            if (gameObject == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("HandleTransform no gameObject");
                }
                return;
            }
            NetworkTransform component = gameObject.GetComponent <NetworkTransform>();

            if (component == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("HandleTransform null target");
                }
            }
            else if (!component.localPlayerAuthority)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("HandleTransform no localPlayerAuthority");
                }
            }
            else if (netMsg.conn.clientOwnedObjects == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("HandleTransform object not owned by connection");
                }
            }
            else if (netMsg.conn.clientOwnedObjects.Contains(networkInstanceId))
            {
                switch (component.transformSyncMode)
                {
                case TransformSyncMode.SyncNone:
                    return;

                case TransformSyncMode.SyncTransform:
                    component.UnserializeModeTransform(netMsg.reader, initialState: false);
                    break;

                case TransformSyncMode.SyncRigidbody3D:
                    component.UnserializeMode3D(netMsg.reader, initialState: false);
                    break;

                case TransformSyncMode.SyncRigidbody2D:
                    component.UnserializeMode2D(netMsg.reader, initialState: false);
                    break;

                case TransformSyncMode.SyncCharacterController:
                    component.UnserializeModeCharacterController(netMsg.reader, initialState: false);
                    break;
                }
                component.m_LastClientSyncTime = Time.time;
            }
            else if (LogFilter.logWarn)
            {
                Debug.LogWarning("HandleTransform netId:" + networkInstanceId + " is not for a valid player");
            }
        }
 public static void SerializeRotation3D(NetworkWriter writer, Quaternion rot, NetworkTransform.AxisSyncMode mode, NetworkTransform.CompressionSyncMode compression)
 {
   switch (mode)
   {
     case NetworkTransform.AxisSyncMode.AxisX:
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.x, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisY:
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.y, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisZ:
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.z, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisXY:
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.x, compression);
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.y, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisXZ:
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.x, compression);
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.z, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisYZ:
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.y, compression);
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.z, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisXYZ:
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.x, compression);
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.y, compression);
       NetworkTransform.WriteAngle(writer, rot.eulerAngles.z, compression);
       break;
   }
 }
 public override void OnStartClient()
 {
     if (this.m_VisualizerPrefab != null)
     {
         this.m_NetworkTransform = base.GetComponent<NetworkTransform>();
         CreateLineMaterial();
         this.m_Visualizer = UnityEngine.Object.Instantiate<GameObject>(this.m_VisualizerPrefab, base.transform.position, Quaternion.identity);
     }
 }
 private void OnValidate()
 {
     if (this.m_Target != null)
     {
         Transform parent = this.m_Target.parent;
         if (parent == null)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("NetworkTransformChild target cannot be the root transform.");
             }
             this.m_Target = null;
             return;
         }
         while (parent.parent != null)
         {
             parent = parent.parent;
         }
         this.m_Root = parent.gameObject.GetComponent <NetworkTransform>();
         if (this.m_Root == null)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("NetworkTransformChild root must have NetworkTransform");
             }
             this.m_Target = null;
             return;
         }
     }
     this.m_ChildIndex = uint.MaxValue;
     NetworkTransformChild[] components = this.m_Root.GetComponents <NetworkTransformChild>();
     for (uint i = 0; i < components.Length; i++)
     {
         if (components[i] == this)
         {
             this.m_ChildIndex = i;
             break;
         }
     }
     if (this.m_ChildIndex == uint.MaxValue)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("NetworkTransformChild component must be a child in the same hierarchy");
         }
         this.m_Target = null;
     }
     if (this.m_SendInterval < 0f)
     {
         this.m_SendInterval = 0f;
     }
     if ((this.m_SyncRotationAxis < NetworkTransform.AxisSyncMode.None) || (this.m_SyncRotationAxis > NetworkTransform.AxisSyncMode.AxisXYZ))
     {
         this.m_SyncRotationAxis = NetworkTransform.AxisSyncMode.None;
     }
     if (this.movementThreshold < 0f)
     {
         this.movementThreshold = 0f;
     }
     if (this.interpolateRotation < 0f)
     {
         this.interpolateRotation = 0.01f;
     }
     if (this.interpolateRotation > 1f)
     {
         this.interpolateRotation = 1f;
     }
     if (this.interpolateMovement < 0f)
     {
         this.interpolateMovement = 0.01f;
     }
     if (this.interpolateMovement > 1f)
     {
         this.interpolateMovement = 1f;
     }
 }
Пример #22
0
 public Vector3 UnserializeVelocity3D(NetworkReader reader, NetworkTransform.CompressionSyncMode compression)
 {
     return reader.ReadVector3();
 }
 private void GetNetworkInformation(GameObject gameObject)
 {
     this.m_Transform = gameObject.GetComponent<NetworkTransform>();
     this.m_Rigidbody3D = gameObject.GetComponent<Rigidbody>();
     this.m_Rigidbody2D = gameObject.GetComponent<Rigidbody2D>();
 }
 public static void SerializeVelocity3D(NetworkWriter writer, Vector3 velocity, NetworkTransform.CompressionSyncMode compression)
 {
   writer.Write(velocity);
 }
Пример #25
0
        //send transform data out
        void SerializeModeTransform(NetworkWriter writer)
        {
            int        start = writer.Position;
            int        i     = 0;
            Quaternion relativeRotation;
            Vector3    relativePosition;

            print("Serialize: numbones=" + m_Bones.Length);
            foreach (var bone in m_Bones)
            {
                if (!bone)
                {  //send bad quaternion if no bone
                    Debug.Log("server skipping bone " + i + ",bone=" + boneIndex2MecanimMap[i]);
                    i++;
                    relativeRotation   = Quaternion.identity;
                    relativePosition   = Vector3.zero;
                    relativePosition.x = 111f;
                    relativePosition.y = 222f;
                    relativePosition.z = 333f;
                    writer.Write(relativePosition);
                    if (m_SyncRotationAxis != NetworkTransform.AxisSyncMode.None)
                    {
                        NetworkTransform.SerializeRotation3D(writer, relativeRotation, syncRotationAxis, rotationSyncCompression);
                    }
                    continue;
                }
                // position
                if (globalData)
                {
                    relativePosition = bone.position;
                }
                else
                {
                    relativePosition = bone.localPosition;
                }

                writer.Write(relativePosition);

                if (globalData)
                {
                    //                    relativeRotation = Quaternion.Inverse(initialRotations[i]) * bone.rotation;
                    relativeRotation = bone.rotation * Quaternion.Inverse(initialRotations[i]);
                }
                else
                {
                    relativeRotation = bone.localRotation; // * Quaternion.Inverse(initialLocalRotations[i++]);
                }
                // rotation
                if (m_SyncRotationAxis != NetworkTransform.AxisSyncMode.None)
                {
                    NetworkTransform.SerializeRotation3D(writer, relativeRotation, syncRotationAxis, rotationSyncCompression);
                }
                if (i == -1)
                {
                    print("server processing bone " + i + ",bone=" + boneIndex2MecanimMap[i]);
                    print("server processing bone " + i + ",rot=" + relativeRotation);
                    print("server processing bone " + i + ",pos=" + relativePosition);
                }
                i++;
            }

            int sz = writer.Position - start;

            if (sz > 1400 && binarySize == 0)
            {
                // this is only generated once.
                Debug.LogWarning("NetworkSkeleton binary serialization size is very large:" + sz + ". Consider reducing the number of levels being synchronized.");
            }
            binarySize = sz;
        }
 public static Vector3 UnserializeVelocity2D(NetworkReader reader, NetworkTransform.CompressionSyncMode compression)
 {
   return (Vector3) reader.ReadVector2();
 }
 private void OnValidate()
 {
   if ((UnityEngine.Object) this.m_Target != (UnityEngine.Object) null)
   {
     Transform parent = this.m_Target.parent;
     if ((UnityEngine.Object) parent == (UnityEngine.Object) null)
     {
       if (LogFilter.logError)
         Debug.LogError((object) "NetworkTransformChild target cannot be the root transform.");
       this.m_Target = (Transform) null;
       return;
     }
     while ((UnityEngine.Object) parent.parent != (UnityEngine.Object) null)
       parent = parent.parent;
     this.m_Root = parent.gameObject.GetComponent<NetworkTransform>();
     if ((UnityEngine.Object) this.m_Root == (UnityEngine.Object) null)
     {
       if (LogFilter.logError)
         Debug.LogError((object) "NetworkTransformChild root must have NetworkTransform");
       this.m_Target = (Transform) null;
       return;
     }
   }
   this.m_ChildIndex = uint.MaxValue;
   NetworkTransformChild[] components = this.m_Root.GetComponents<NetworkTransformChild>();
   for (uint index = 0; (long) index < (long) components.Length; ++index)
   {
     if ((UnityEngine.Object) components[(IntPtr) index] == (UnityEngine.Object) this)
     {
       this.m_ChildIndex = index;
       break;
     }
   }
   if ((int) this.m_ChildIndex == -1)
   {
     if (LogFilter.logError)
       Debug.LogError((object) "NetworkTransformChild component must be a child in the same hierarchy");
     this.m_Target = (Transform) null;
   }
   if ((double) this.m_SendInterval < 0.0)
     this.m_SendInterval = 0.0f;
   if (this.m_SyncRotationAxis < NetworkTransform.AxisSyncMode.None || this.m_SyncRotationAxis > NetworkTransform.AxisSyncMode.AxisXYZ)
     this.m_SyncRotationAxis = NetworkTransform.AxisSyncMode.None;
   if ((double) this.movementThreshold < 0.0)
     this.movementThreshold = 0.0f;
   if ((double) this.interpolateRotation < 0.0)
     this.interpolateRotation = 0.01f;
   if ((double) this.interpolateRotation > 1.0)
     this.interpolateRotation = 1f;
   if ((double) this.interpolateMovement < 0.0)
     this.interpolateMovement = 0.01f;
   if ((double) this.interpolateMovement <= 1.0)
     return;
   this.interpolateMovement = 1f;
 }
 public static Quaternion UnserializeRotation3D(NetworkReader reader, NetworkTransform.AxisSyncMode mode, NetworkTransform.CompressionSyncMode compression)
 {
   Quaternion identity = Quaternion.identity;
   Vector3 zero = Vector3.zero;
   switch (mode)
   {
     case NetworkTransform.AxisSyncMode.AxisX:
       zero.Set(NetworkTransform.ReadAngle(reader, compression), 0.0f, 0.0f);
       identity.eulerAngles = zero;
       break;
     case NetworkTransform.AxisSyncMode.AxisY:
       zero.Set(0.0f, NetworkTransform.ReadAngle(reader, compression), 0.0f);
       identity.eulerAngles = zero;
       break;
     case NetworkTransform.AxisSyncMode.AxisZ:
       zero.Set(0.0f, 0.0f, NetworkTransform.ReadAngle(reader, compression));
       identity.eulerAngles = zero;
       break;
     case NetworkTransform.AxisSyncMode.AxisXY:
       zero.Set(NetworkTransform.ReadAngle(reader, compression), NetworkTransform.ReadAngle(reader, compression), 0.0f);
       identity.eulerAngles = zero;
       break;
     case NetworkTransform.AxisSyncMode.AxisXZ:
       zero.Set(NetworkTransform.ReadAngle(reader, compression), 0.0f, NetworkTransform.ReadAngle(reader, compression));
       identity.eulerAngles = zero;
       break;
     case NetworkTransform.AxisSyncMode.AxisYZ:
       zero.Set(0.0f, NetworkTransform.ReadAngle(reader, compression), NetworkTransform.ReadAngle(reader, compression));
       identity.eulerAngles = zero;
       break;
     case NetworkTransform.AxisSyncMode.AxisXYZ:
       zero.Set(NetworkTransform.ReadAngle(reader, compression), NetworkTransform.ReadAngle(reader, compression), NetworkTransform.ReadAngle(reader, compression));
       identity.eulerAngles = zero;
       break;
   }
   return identity;
 }
 public static void SerializeRotation2D(NetworkWriter writer, float rot, NetworkTransform.CompressionSyncMode compression)
 {
   NetworkTransform.WriteAngle(writer, rot, compression);
 }
Пример #30
0
 private void OnValidate()
 {
     if ((UnityEngine.Object) this.m_Target != (UnityEngine.Object)null)
     {
         Transform parent = this.m_Target.parent;
         if ((UnityEngine.Object)parent == (UnityEngine.Object)null)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError((object)"NetworkTransformChild target cannot be the root transform.");
             }
             this.m_Target = (Transform)null;
             return;
         }
         while ((UnityEngine.Object)parent.parent != (UnityEngine.Object)null)
         {
             parent = parent.parent;
         }
         this.m_Root = parent.gameObject.GetComponent <NetworkTransform>();
         if ((UnityEngine.Object) this.m_Root == (UnityEngine.Object)null)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError((object)"NetworkTransformChild root must have NetworkTransform");
             }
             this.m_Target = (Transform)null;
             return;
         }
     }
     this.m_ChildIndex = uint.MaxValue;
     NetworkTransformChild[] components = this.m_Root.GetComponents <NetworkTransformChild>();
     for (uint index = 0; (long)index < (long)components.Length; ++index)
     {
         if ((UnityEngine.Object)components[(IntPtr)index] == (UnityEngine.Object) this)
         {
             this.m_ChildIndex = index;
             break;
         }
     }
     if ((int)this.m_ChildIndex == -1)
     {
         if (LogFilter.logError)
         {
             Debug.LogError((object)"NetworkTransformChild component must be a child in the same hierarchy");
         }
         this.m_Target = (Transform)null;
     }
     if ((double)this.m_SendInterval < 0.0)
     {
         this.m_SendInterval = 0.0f;
     }
     if (this.m_SyncRotationAxis < NetworkTransform.AxisSyncMode.None || this.m_SyncRotationAxis > NetworkTransform.AxisSyncMode.AxisXYZ)
     {
         this.m_SyncRotationAxis = NetworkTransform.AxisSyncMode.None;
     }
     if ((double)this.movementThreshold < 0.0)
     {
         this.movementThreshold = 0.0f;
     }
     if ((double)this.interpolateRotation < 0.0)
     {
         this.interpolateRotation = 0.01f;
     }
     if ((double)this.interpolateRotation > 1.0)
     {
         this.interpolateRotation = 1f;
     }
     if ((double)this.interpolateMovement < 0.0)
     {
         this.interpolateMovement = 0.01f;
     }
     if ((double)this.interpolateMovement <= 1.0)
     {
         return;
     }
     this.interpolateMovement = 1f;
 }
        void OnValidate()
        {
            // root parent of target must have a NetworkTransform
            if (m_Target != null)
            {
                Transform parent = m_Target.parent;
                if (parent == null)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("NetworkTransformChild target cannot be the root transform.");
                    }
                    m_Target = null;
                    return;
                }
                while (parent.parent != null)
                {
                    parent = parent.parent;
                }

                m_Root = parent.gameObject.GetComponent <NetworkTransform>();
                if (m_Root == null)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("NetworkTransformChild root must have NetworkTransform");
                    }
                    m_Target = null;
                    return;
                }
            }

            if (m_Root != null)
            {
                // childIndex is the index within all the NetworkChildTransforms on the root
                m_ChildIndex = UInt32.MaxValue;
                var childTransforms = m_Root.GetComponents <NetworkTransformChild>();
                for (uint i = 0; i < childTransforms.Length; i++)
                {
                    if (childTransforms[i] == this)
                    {
                        m_ChildIndex = i;
                        break;
                    }
                }
                if (m_ChildIndex == UInt32.MaxValue)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("NetworkTransformChild component must be a child in the same hierarchy");
                    }
                    m_Target = null;
                }
            }

            if (m_SendInterval < 0)
            {
                m_SendInterval = 0;
            }

            if (m_SyncRotationAxis < NetworkTransform.AxisSyncMode.None || m_SyncRotationAxis > NetworkTransform.AxisSyncMode.AxisXYZ)
            {
                m_SyncRotationAxis = NetworkTransform.AxisSyncMode.None;
            }

            if (movementThreshold < 0)
            {
                movementThreshold = 0.00f;
            }

            if (interpolateRotation < 0)
            {
                interpolateRotation = 0.01f;
            }
            if (interpolateRotation > 1.0f)
            {
                interpolateRotation = 1.0f;
            }

            if (interpolateMovement < 0)
            {
                interpolateMovement = 0.01f;
            }
            if (interpolateMovement > 1.0f)
            {
                interpolateMovement = 1.0f;
            }
        }
 public static void SerializeSpin3D(NetworkWriter writer, Vector3 angularVelocity, NetworkTransform.AxisSyncMode mode, NetworkTransform.CompressionSyncMode compression)
 {
   switch (mode)
   {
     case NetworkTransform.AxisSyncMode.AxisX:
       NetworkTransform.WriteAngle(writer, angularVelocity.x, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisY:
       NetworkTransform.WriteAngle(writer, angularVelocity.y, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisZ:
       NetworkTransform.WriteAngle(writer, angularVelocity.z, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisXY:
       NetworkTransform.WriteAngle(writer, angularVelocity.x, compression);
       NetworkTransform.WriteAngle(writer, angularVelocity.y, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisXZ:
       NetworkTransform.WriteAngle(writer, angularVelocity.x, compression);
       NetworkTransform.WriteAngle(writer, angularVelocity.z, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisYZ:
       NetworkTransform.WriteAngle(writer, angularVelocity.y, compression);
       NetworkTransform.WriteAngle(writer, angularVelocity.z, compression);
       break;
     case NetworkTransform.AxisSyncMode.AxisXYZ:
       NetworkTransform.WriteAngle(writer, angularVelocity.x, compression);
       NetworkTransform.WriteAngle(writer, angularVelocity.y, compression);
       NetworkTransform.WriteAngle(writer, angularVelocity.z, compression);
       break;
   }
 }
 public static void SerializeSpin2D(NetworkWriter writer, float angularVelocity, NetworkTransform.CompressionSyncMode compression)
 {
   NetworkTransform.WriteAngle(writer, angularVelocity, compression);
 }
Пример #34
0
 private void OnValidate()
 {
     if (this.m_Target != null)
     {
         Transform parent = this.m_Target.parent;
         if (parent == null)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("NetworkTransformChild target cannot be the root transform.");
             }
             this.m_Target = null;
             return;
         }
         while (parent.parent != null)
         {
             parent = parent.parent;
         }
         this.m_Root = parent.gameObject.GetComponent<NetworkTransform>();
         if (this.m_Root == null)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("NetworkTransformChild root must have NetworkTransform");
             }
             this.m_Target = null;
             return;
         }
     }
     this.m_ChildIndex = uint.MaxValue;
     NetworkTransformChild[] components = this.m_Root.GetComponents<NetworkTransformChild>();
     for (uint i = 0; i < components.Length; i++)
     {
         if (components[i] == this)
         {
             this.m_ChildIndex = i;
             break;
         }
     }
     if (this.m_ChildIndex == uint.MaxValue)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("NetworkTransformChild component must be a child in the same hierarchy");
         }
         this.m_Target = null;
     }
     if (this.m_SendInterval < 0f)
     {
         this.m_SendInterval = 0f;
     }
     if ((this.m_SyncRotationAxis < NetworkTransform.AxisSyncMode.None) || (this.m_SyncRotationAxis > NetworkTransform.AxisSyncMode.AxisXYZ))
     {
         this.m_SyncRotationAxis = NetworkTransform.AxisSyncMode.None;
     }
     if (this.movementThreshold < 0f)
     {
         this.movementThreshold = 0f;
     }
     if (this.interpolateRotation < 0f)
     {
         this.interpolateRotation = 0.01f;
     }
     if (this.interpolateRotation > 1f)
     {
         this.interpolateRotation = 1f;
     }
     if (this.interpolateMovement < 0f)
     {
         this.interpolateMovement = 0.01f;
     }
     if (this.interpolateMovement > 1f)
     {
         this.interpolateMovement = 1f;
     }
 }