UnityEngine.Networking.NetworkTransform.UnserializeModeCharacterController C# (CSharp) Method

UnserializeModeCharacterController() private method

private UnserializeModeCharacterController ( NetworkReader reader, bool initialState ) : void
reader NetworkReader
initialState bool
return void
        private void UnserializeModeCharacterController(NetworkReader reader, bool initialState)
        {
            if (base.hasAuthority)
            {
                reader.ReadVector3();
                if (this.syncRotationAxis != AxisSyncMode.None)
                {
                    UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
                }
            }
            else
            {
                if (base.isServer && (this.m_ClientMoveCallback3D != null))
                {
                    Vector3 position = reader.ReadVector3();
                    Quaternion identity = Quaternion.identity;
                    if (this.syncRotationAxis != AxisSyncMode.None)
                    {
                        identity = UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
                    }
                    if (this.m_CharacterController == null)
                    {
                        return;
                    }
                    Vector3 velocity = this.m_CharacterController.velocity;
                    if (!this.m_ClientMoveCallback3D(ref position, ref velocity, ref identity))
                    {
                        return;
                    }
                    this.m_TargetSyncPosition = position;
                    this.m_TargetSyncVelocity = velocity;
                    if (this.syncRotationAxis != AxisSyncMode.None)
                    {
                        this.m_TargetSyncRotation3D = identity;
                    }
                }
                else
                {
                    this.m_TargetSyncPosition = reader.ReadVector3();
                    if (this.syncRotationAxis != AxisSyncMode.None)
                    {
                        this.m_TargetSyncRotation3D = UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
                    }
                }
                if (this.m_CharacterController != null)
                {
                    Vector3 vector3 = this.m_TargetSyncPosition - base.transform.position;
                    Vector3 vector4 = (Vector3) (vector3 / this.GetNetworkSendInterval());
                    this.m_FixedPosDiff = (Vector3) (vector4 * Time.fixedDeltaTime);
                    if (base.isServer && !base.isClient)
                    {
                        base.transform.position = this.m_TargetSyncPosition;
                        base.transform.rotation = this.m_TargetSyncRotation3D;
                    }
                    else if (this.GetNetworkSendInterval() == 0f)
                    {
                        base.transform.position = this.m_TargetSyncPosition;
                        if (this.syncRotationAxis != AxisSyncMode.None)
                        {
                            base.transform.rotation = this.m_TargetSyncRotation3D;
                        }
                    }
                    else
                    {
                        Vector3 vector5 = base.transform.position - this.m_TargetSyncPosition;
                        if (vector5.magnitude > this.snapThreshold)
                        {
                            base.transform.position = this.m_TargetSyncPosition;
                        }
                        if ((this.interpolateRotation == 0f) && (this.syncRotationAxis != AxisSyncMode.None))
                        {
                            base.transform.rotation = this.m_TargetSyncRotation3D;
                        }
                        if (this.m_InterpolateMovement == 0f)
                        {
                            base.transform.position = this.m_TargetSyncPosition;
                        }
                        if (initialState && (this.syncRotationAxis != AxisSyncMode.None))
                        {
                            base.transform.rotation = this.m_TargetSyncRotation3D;
                        }
                    }
                }
            }
        }

Usage Example

Ejemplo n.º 1
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");
            }
        }