Пример #1
0
        void FixedUpdate()
        {
            if (this.paused)
            {
                return;
            }

            IObjective destination;

            if (this.TryPeekDestination(out destination))
            {
                if (this.CurrentState != MoverStateKind.Moving)
                {
                    // Raise an event when we start moving for the first time.
                    this.RaiseObjectiveChanged(this.previousObjective, destination);
                    this.CurrentState = MoverStateKind.Moving;
                }

                var delta = destination.TargetPosition - this.cachedTx.position;

                if (!this.ignoreArrival && delta.sqrMagnitude <= this.arrivalDistanceSqr)
                {
                    this.destinations.Dequeue();

                    if (this.destinations.Count == 0)
                    {
                        this.CurrentState = MoverStateKind.Arrived;
                    }

                    this.RaiseObjectiveChanged(destination, this.destinations.Count > 0 ? this.destinations.Peek() : null);

                    this.previousObjective = destination;
                }
                else
                {
                    if (delta != Vector3.zero)
                    {
                        var rot = Quaternion.LookRotation(delta);
                        var t   = 1f / 360f * this.rotateSpeed * Time.deltaTime;
                        this.cachedTx.rotation = Quaternion.Slerp(this.cachedTx.rotation, rot, t);
                    }

                    this.cachedTx.Translate(Vector3.forward * this.Speed * Time.deltaTime);

                    if (this.snapDown)
                    {
                        var rayconf = RaycastConfig.Ray(layerMask: this.snapLayer);
                        this.cachedTx.SnapDown(rayconf, this.raiseSnapRaycast, this.raiseSnapPosition);
                    }
                }
            }
            else
            {
                if (this.CurrentState == MoverStateKind.Moving)
                {
                    this.Cancel();
                }
            }
        }
Пример #2
0
        void FixedUpdate()
        {
            if (this.paused)
            {
                return;
            }

            IObjective destination;

            if (this.TryPeekDestination(out destination))
            {
                if (this.CurrentState != MoverStateKind.Moving)
                {
                    // Raise an event when we start moving for the first time.
                    this.RaiseObjectiveChanged(this.previousObjective, destination);
                    this.CurrentState = MoverStateKind.Moving;
                }

                // We need to modify the arrival distance to take account of the raised snap position.
                // TODO: This probably isn't accurate. Should raise the destination position first.
                var raisedArrialDistance = this.arrivalDistance + this.raiseSnapPosition;

                if (this.cachedTx.MoveTowards(destination.TargetPosition, this.Speed, raisedArrialDistance) && !this.ignoreArrival)
                {
                    this.destinations.Dequeue();

                    if (this.destinations.Count == 0)
                    {
                        this.CurrentState = MoverStateKind.Arrived;
                    }

                    this.RaiseObjectiveChanged(destination, this.destinations.Count > 0 ? this.destinations.Peek() : null);

                    this.previousObjective = destination;
                }

                // TODO: Integrate orientation in here somehow? Maybe using movement modifiers, and a OnPostMove callback.

                if (this.snapDown)
                {
                    var rayconf = RaycastConfig.Ray(layerMask: this.snapLayer);
                    this.cachedTx.SnapDown(rayconf, this.raiseSnapRaycast, this.raiseSnapPosition);
                }

                switch (this.lookMode)
                {
                case MoverLookMode.None:
                    break;

                case MoverLookMode.WorldUp:
                    this.cachedTx.LookAt(destination.TargetPosition);
                    break;

                case MoverLookMode.TransformUp:
                    this.cachedTx.LookAt(destination.TargetPosition, this.cachedTx.up);
                    break;
                }
            }
            else
            {
                if (this.CurrentState == MoverStateKind.Moving)
                {
                    this.Cancel();
                }
            }
        }