Exemplo n.º 1
0
        // -----------------------

        public void MovableUpdate()
        {
            // Parent update position.
            if (isParent)
            {
                Vector2 _position = parent.position;
                Vector2 _movement = _position - (Vector2)transform.position;

                if (!_movement.IsNull())
                {
                    Move(_movement);
                }
                else if (isMoving)
                {
                    Stop(_position);
                }
            }

            // Hacking update.
            if (isHacking)
            {
                if (hacking.UpdateHack())
                {
                    isHacking = false;
                    animator.SetBool(PlayerController.Hack_Anim, false);
                }
            }

            // Update state while not reached loop end.
            if (!isLoopCompleted)
            {
                if (isStateContinouslyUpdating)
                {
                    states[stateIndex].UpdateState(this);
                }
                while (states[stateIndex + 1].HasTimeCome())
                {
                    stateIndex++;
                    states[stateIndex].UpdateState(this);

                    if (stateIndex < states.Length - 1)
                    {
                        isStateContinouslyUpdating = states[stateIndex].DoUpdateContinuously();
                    }
                    else
                    {
                        isLoopCompleted = true;
                        break;
                    }
                }
            }
        }
        void IInputUpdate.Update()
        {
            if (IsPaused)
            {
                return;
            }

            // Dialog update.
            if (isInDialog && inputs.Action.triggered)
            {
                LevelManager.Instance.EndDialog();
            }

            if (isPlayable)
            {
                // Hacking update.
                if (isHacking)
                {
                    if (hacking.UpdateHack())
                    {
                        isHacking = false;
                        animator.SetBool(Hack_Anim, false);
                    }
                }
                else
                {
                    Move(inputs.Move.ReadValue <Vector2>());

                    if (inputs.Forward.triggered)
                    {
                        if (GameManager.Instance.TimeCoef >= 1)
                        {
                            GameManager.Instance.SetTimeCoef(GameManager.Instance.TimeCoef == 1 ? 2 : 1);
                        }
                    }
                    else if (GameManager.Instance.TimeCoef > 1)
                    {
                        GameManager.Instance.SetTimeCoef(Mathf.Min(GameManager.Instance.TimeCoef + GameManager.DeltaTime, 32));
                    }

                    // Register current state.
                    if (inputs.Action.triggered &&
                        (collider.OverlapCollider(interactFilter, overlapColliders) > 0) &&
                        overlapColliders[0].GetComponentInParent <IInteractable>().Interact(this))
                    {
                        ghostStates.Add(new PlayerGhostSetPositionState(LevelManager.Instance.LoopTime, rigidbody.position));
                        ghostStates.Add(new PlayerGhostInteractState(LevelManager.Instance.LoopTime));
                    }
                }
            }
            else if (inputs.Loop.triggered)
            {
                LevelManager.Instance.StartLoop();
                return;
            }

            // Reset loop on button trigger.
            if (inputs.ResetLoop.triggered)
            {
                LevelManager.Instance.ResetLoop();
            }
        }