コード例 #1
0
        public void ExecuteState()
        {
            switch (_state)
            {
            case State.Neutral:
                var pos = _intaractableGoal.InteractPosition(_agent.transform.position);
                _interactGoalPosition = new Vector2(pos.x, pos.z);
                _agent.SetDestination(pos);
                _state = State.GoToIntactable;
                return;

            case State.GoToIntactable:
                if (_agent.HasReachedTarget())
                {
                    _agent.ResetPath();

                    if (_agent.enabled)
                    {
                        cam.StartAdjustPosition(_interactGameObject);
                    }

                    _agent.ResetPath();

                    if (_agent.updateRotation)
                    {
                        _agent.ResetPath();
                        var t = Vector2.Distance(_interactGoalPosition,
                                                 new Vector2(_agent.transform.position.x, _agent.transform.position.z));
                        _state = t < .6 ? State.Interact : State.Done;
                    }
                }
                return;

            case State.Interact:
                var puh = _agent.gameObject.GetComponent <PickupHandler>();


                if (_interactGameObject.tag == Constants.Tags.Lever && _intaractableGoal.CanThisBeInteractedWith(puh.CurrentPickup))
                {
                    _agent.gameObject.GetComponent <Animator>().SetTrigger("PullLever");
                }
                else if (_interactGameObject.tag == Constants.Tags.Brazier && _intaractableGoal.CanThisBeInteractedWith(puh.CurrentPickup))
                {
                    _agent.gameObject.GetComponent <Animator>().SetTrigger("LightFire");
                }
                else if (_interactGameObject.tag == Constants.Tags.Keyhole)
                {
                    if (_intaractableGoal.CanThisBeInteractedWith(puh.CurrentPickup))
                    {
                        _agent.gameObject.GetComponent <Animator>().SetTrigger("OpenDoor");
                    }
                    else
                    {
                        _agent.gameObject.GetComponent <Animator>().SetTrigger("DoorLocked");
                    }
                }
                else if (_interactGameObject.tag == Constants.Tags.Key ||
                         _interactGameObject.tag == Constants.Tags.Stick)
                {
                    _agent.gameObject.GetComponent <Animator>().SetTrigger("PickUp");
                }

                var returnItem = _intaractableGoal.Interact(puh.CurrentPickup);
                puh.PickUpItem(returnItem);
                _agent.ResetPath();

                _waitUntill = Time.time + WaitingTime;
                _state      = State.WaitSomeTime;
                return;

            case State.WaitSomeTime:
                _agent.ResetPath();
                if (_waitUntill < Time.time)
                {
                    _state = State.Done;
                }
                return;

            default:
                return;
            }
        }