Esempio n. 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();
                }
            }
        }
Esempio n. 2
0
 public void Clear()
 {
     this.destinations.Clear();
     this.previousObjective = null;
     this.paused            = false;
     this.CurrentState      = MoverStateKind.None;
     this.Speed             = this.startSpeed;
 }
Esempio n. 3
0
        void Update()
        {
            if (!this.paused && this.path.Count > 0)
            {
                this.CurrentState = MoverStateKind.Moving;

                this.SyncPathMover();

                if (this.PathMover.IsArrived)
                {
                    this.CurrentState = MoverStateKind.Arrived;
                }
            }
        }
Esempio n. 4
0
        private void OnMoverStateChanged(IMoveDriver driver, MoverStateKind previousState, MoverStateKind currentState)
        {
            Assert.AreEqual(this.Driver, driver);

            if (this.dispatchDiagnosticIndicatorSignals)
            {
                this.diagnosticSignal.DispatchSet(
                    this.gameObject,
                    StateDiagnosticsKey,
                    currentState.ToString());
            }

            switch (currentState)
            {
            case MoverStateKind.Arrived:
                this.log.Trace("Arrived").Write();

                if (this.Arrived != null)
                {
                    this.Arrived(driver);
                }

                if (this.raiseFlagOnArrival)
                {
                    this.log.Trace("Raising arrival flag").Field("flag", this.arrivedFlag).Write();
                    this.flagSignal.DispatchFlag(this.gameObject, this.arrivedFlag);
                }

                break;

            case MoverStateKind.Cancelled:
                this.log.Trace("Cancelled").Write();

                if (this.Cancelled != null)
                {
                    this.Cancelled(driver);
                }
                break;
            }
        }
Esempio n. 5
0
 public void Clear()
 {
     this.path.Clear();
     this.paused       = false;
     this.CurrentState = MoverStateKind.None;
 }
Esempio n. 6
0
 public void Pause()
 {
     this.paused       = true;
     this.CurrentState = MoverStateKind.Paused;
 }
Esempio n. 7
0
 public void Cancel()
 {
     this.PathMover.Stop();
     this.path.Clear();
     this.CurrentState = MoverStateKind.Cancelled;
 }
Esempio n. 8
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();
                }
            }
        }
Esempio n. 9
0
 public void Cancel()
 {
     this.destinations.Clear();
     this.previousObjective = null;
     this.CurrentState      = MoverStateKind.Cancelled;
 }