示例#1
0
    void Update()
    {
        _actualState = (PossibleStatesMiner)_finiteStateMachine.GetState();


        switch (_actualState)
        {
        case PossibleStatesMiner.Wait:
            break;

        case PossibleStatesMiner.Mining:
            _timeMining += Time.deltaTime;
            if (_minableMine.TimeToMine / MineVelocity < _timeMining)
            {
                _timeMining = 0;
                if (!_minableMine.GetGold())
                {
                    _finiteStateMachine.SetEvent((int)PossibleEventsMiner.GoToGoldBox);
                    _myAnim.Stop();
                }
                else
                {
                    _goldCollected++;
                    if (_goldCollected == MaximunGoldPerCycle)
                    {
                        _finiteStateMachine.SetEvent((int)PossibleEventsMiner.GoToGoldBox);
                        _myAnim.Stop();
                    }
                }
            }
            break;

        case PossibleStatesMiner.GoMine:
            if (_minableMine != null && _minableMine.AmountOfGold > 0)
            {
                GoToPosition(_minableMine.transform.position);
            }
            else
            {
                if (_minableMine != null)
                {
                    _minableMine = MineManager.GetMineWithGold();
                }
            }
            break;

        case PossibleStatesMiner.ToGoldBox:
            //_myAnim.Stop();
            GoToPosition(GoldBox.transform.position);
            //transform.position = Vector3.MoveTowards(transform.position,GoldBox.transform.position,Time.deltaTime*MoveVelocity);
            break;
        }

        //Debug.Log(_actualState);
    }
示例#2
0
    void Start()
    {
        _finiteStateMachine = new Fsm(4, 4);
        _finiteStateMachine.SetRelation((int)PossibleStatesMiner.Wait, (int)PossibleEventsMiner.GoMine, (int)PossibleStatesMiner.GoMine);

        _finiteStateMachine.SetRelation((int)PossibleStatesMiner.GoMine, (int)PossibleEventsMiner.StartMining, (int)PossibleStatesMiner.Mining);

        _finiteStateMachine.SetRelation((int)PossibleStatesMiner.Mining, (int)PossibleEventsMiner.GoToGoldBox, (int)PossibleStatesMiner.ToGoldBox);

        _finiteStateMachine.SetRelation((int)PossibleStatesMiner.ToGoldBox, (int)PossibleEventsMiner.GoMine, (int)PossibleStatesMiner.GoMine);
        //_myAnim.Stop();
        _myAnim.Stop();
        _minableMine       = MineManager.GetMineWithGold();
        _raycastCheckTimer = new CountdownTimer(TimeBetweenRayCastCheck, TimeBetweenRayCastCheck);
        _finiteStateMachine.SetEvent((int)PossibleEventsMiner.GoMine);
    }