Beispiel #1
0
        public override void SetDynamic(NetworkObj obj, object value)
        {
            var v = (Guid)value;

            if (NetworkValue.Diff(obj.Storage.Values[obj[this]].Guid, v))
            {
                obj.Storage.Values[obj[this]].Guid = v;
                obj.Storage.PropertyChanged(obj.OffsetProperties + this.OffsetProperties);
            }
        }
Beispiel #2
0
        public override void SetDynamic(NetworkObj obj, object value)
        {
            var v = (IMessageRider)value;

            if (NetworkValue.Diff(obj.Storage.Values[obj[this]].ProtocolToken, v))
            {
                obj.Storage.Values[obj[this]].ProtocolToken = v;
                obj.Storage.PropertyChanged(obj.OffsetProperties + this.OffsetProperties);
            }
        }
Beispiel #3
0
        public override void SetDynamic(NetworkObj obj, object value)
        {
            if (MecanimDirection == MecanimDirection.UsingAnimatorMethods)
            {
                NetLog.Error("Can't call SetDynamic on a float in 'UsingAnimatorMethods' mode");
                return;
            }

            var v = (float)value;

            if (NetworkValue.Diff(obj.Storage.Values[obj[this]].Float0, v))
            {
                obj.Storage.Values[obj[this]].Float0 = v;
                obj.Storage.PropertyChanged(obj.OffsetProperties + this.OffsetProperties);
            }
        }
Beispiel #4
0
        public override void PullMecanimValue(NetworkState state)
        {
            if (state.Animator == null)
            {
                return;
            }

            float newValue = state.Animator.GetFloat(PropertyName);
            float oldValue = state.Storage.Values[state[this]].Float0;

            state.Storage.Values[state[this]].Float0 = newValue;

            if (NetworkValue.Diff(newValue, oldValue))
            {
                state.Storage.PropertyChanged(state.OffsetProperties + this.OffsetProperties);
            }
        }
Beispiel #5
0
        void PullMecanimLayer(NetworkState state)
        {
            if (state.Animator == null)
            {
                return;
            }

            //UnityEngine.Debug.Log(state.RootState.Entity.UnityObject.name + ":" + state.Animator.runtimeAnimatorController.name + ":"  + MecanimLayer);

            float newValue = state.Animator.GetLayerWeight(MecanimLayer);
            float oldValue = state.Storage.Values[state[this]].Float0;

            state.Storage.Values[state[this]].Float0 = newValue;

            if (NetworkValue.Diff(newValue, oldValue))
            {
                state.Storage.PropertyChanged(state.OffsetProperties + this.OffsetProperties);
            }
        }
Beispiel #6
0
        public override void OnSimulateAfter(NetworkObj obj)
        {
            var nt = obj.Storage.Values[obj[this] + POSITION].Transform;

            if (nt != null && nt.Simulate)
            {
                if (obj.RootState.Entity.IsOwner)
                {
                    var oldPosition = obj.Storage.Values[obj[this] + POSITION].Vector3;
                    var oldVelocity = obj.Storage.Values[obj[this] + VELOCITY].Vector3;
                    var oldRotation = obj.Storage.Values[obj[this] + ROTATION].Quaternion;

                    obj.Storage.Values[obj[this] + POSITION].Vector3    = GetPosition(nt.Simulate);
                    obj.Storage.Values[obj[this] + VELOCITY].Vector3    = CalculateVelocity(nt, oldPosition);
                    obj.Storage.Values[obj[this] + ROTATION].Quaternion = GetRotation(nt.Simulate);

                    var positionChanged = false;
                    var velocityChanged = false;
                    var rotationChanged = false;

                    if (PositionCompression.StrictComparison)
                    {
                        positionChanged = NetworkValue.Diff_Strict(oldPosition, obj.Storage.Values[obj[this] + POSITION].Vector3);

                        if (Extrapolation.Enabled)
                        {
                            velocityChanged = NetworkValue.Diff_Strict(oldVelocity, obj.Storage.Values[obj[this] + VELOCITY].Vector3);
                        }
                    }
                    else
                    {
                        positionChanged = NetworkValue.Diff(oldPosition, obj.Storage.Values[obj[this] + POSITION].Vector3);

                        if (Extrapolation.Enabled)
                        {
                            velocityChanged = NetworkValue.Diff(oldVelocity, obj.Storage.Values[obj[this] + VELOCITY].Vector3);
                        }

                        if (positionChanged)
                        {
                            if ((oldPosition - obj.Storage.Values[obj[this] + POSITION].Vector3).magnitude < 0.001f)
                            {
                                positionChanged = false;
                            }
                        }

                        if (velocityChanged)
                        {
                            if ((oldVelocity - obj.Storage.Values[obj[this] + VELOCITY].Vector3).magnitude < 0.001f)
                            {
                                velocityChanged = false;
                            }
                        }
                    }

                    if (RotationCompression.StrictComparison)
                    {
                        rotationChanged = NetworkValue.Diff_Strict(oldRotation, obj.Storage.Values[obj[this] + ROTATION].Quaternion);
                    }
                    else
                    {
                        rotationChanged = NetworkValue.Diff(oldRotation, obj.Storage.Values[obj[this] + ROTATION].Quaternion);

                        if (rotationChanged)
                        {
                            var r = obj.Storage.Values[obj[this] + ROTATION].Quaternion;

                            Vector4 oldR = new Vector4(oldRotation.x, oldRotation.y, oldRotation.z, oldRotation.w);
                            Vector4 newR = new Vector4(r.x, r.y, r.z, r.w);

                            if ((oldR - newR).magnitude < 0.001f)
                            {
                                rotationChanged = false;
                            }
                        }
                    }

                    if (positionChanged || velocityChanged || rotationChanged)
                    {
                        obj.Storage.PropertyChanged(obj.OffsetProperties + this.OffsetProperties);
                    }
                }

                nt.RenderDoubleBufferPosition = nt.RenderDoubleBufferPosition.Shift(nt.Simulate.position);
                nt.RenderDoubleBufferRotation = nt.RenderDoubleBufferRotation.Shift(nt.Simulate.rotation);
            }
        }