// Update is called once per frame
    void Update()
    {
        switch (currState)
        {
        case GameState_Enum.STATE_CIRCLESHOWING:
            StateFunc.CircleShowing();
            break;

        case GameState_Enum.STATE_INCIRCLE:
            StateFunc.InCircle();
            break;

        case GameState_Enum.STATE_OUTCIRCLE:
            StateFunc.OutCircle();
            break;

        case GameState_Enum.STATE_TRIALSUCCEED:
            StateFunc.TaskSucceed();
            break;

        case GameState_Enum.STATE_TRIALFAIL:
            StateFunc.TaskFail();
            break;

        case GameState_Enum.STATE_BREAK:
            StateFunc.Break();
            break;

        case GameState_Enum.STATE_NULL:
            break;
        }
    }
Beispiel #2
0
 public static Result Change(StateFunc nextFunc)
 {
     return(new Result()
     {
         nextFunc = nextFunc
     });
 }
Beispiel #3
0
        public void Add(T stateId, StateFunc onEnter = null, StateFunc onUpdate = null, StateFunc onLeave = null)
        {
            // 枚举类型内部是整型, int的hashcode就是其本身, 因此枚举值的hashcode就是其对应的整型值
            int int_id = stateId.GetHashCode();

            m_States.Add(int_id, new State(int_id, onEnter, onUpdate, onLeave));
        }
Beispiel #4
0
 //El primer parámetro es la nueva función que queremos asignar al delegate, el segundo es el tiempo.
 public void ChangeState(StateFunc newState,float newtimer)
 {
     stateStartTime=Time.time;
         initVar=true;
         timer=newtimer;
         stateAction = newState;
 }
Beispiel #5
0
 public SimpleState(TId id, StateFunc enter, StateFunc update, StateFunc leave)
 {
     this.id     = id;
     this.Enter  = enter;
     this.Update = update;
     this.Leave  = leave;
 }
Beispiel #6
0
 public State(T id, StateFunc enter, StateFunc update, StateFunc leave)
 {
     Id     = id;
     Enter  = enter;
     Update = update;
     Leave  = leave;
 }
        public State(int id, StateFunc enter = null, StateFunc update = null, StateFunc leave = null)
        {
            m_Id = id;

            m_OnEnter  = enter;
            m_OnUpdate = update;
            m_OnLeave  = leave;
        }
Beispiel #8
0
 private static StateResult ToState(StateFunc state, string description = null)
 {
     return(new StateResult
     {
         NextState = state,
         Description = description
     });
 }
Beispiel #9
0
 public void Run()
 {
     while (true)
     {
         stateFunc = stateFunc();
         if (stateFunc == Completed)
         {
             break;
         }
     }
 }
    //注册状态
    public void RegistState(T state, StateFunc.EnterFunc enter, StateFunc.UpdateFunc update, StateFunc.ExitFunc exit)
    {
        StateFunc func = new StateFunc
        {
            enterFunc  = enter,
            updateFunc = update,
            exitFunc   = exit
        };

        this.m_StateFunc.Add(state, func);
        //Debug.Log("State:" + state);
    }
Beispiel #11
0
 // Update is called once per frame
 void Update()
 {
     if (nextStateFunc_ != null)
     {
         var next = nextStateFunc_;
         nextStateFunc_   = null;
         stateFunc_       = next;
         stateFrameCount_ = 0;
     }
     stateFunc_(this);
     stateFrameCount_++;
 }
Beispiel #12
0
    // Update is called once per frame
    void Update()
    {
        if (EMG.IsConnected())
        {
            EMG.Update();
        }

        switch (currState)
        {
        case GameState_Enum.STATE_CMD2ROBOT:
            StateFunc.Cmd2Robot();
            break;

        case GameState_Enum.STATE_MOVE2START:
            StateFunc.Move2Start();
            break;

        case GameState_Enum.STATE_TRIALSTART:
            StateFunc.TrialStart();
            break;

        case GameState_Enum.STATE_INCIRCLE:
            StateFunc.InCircle();
            break;

        case GameState_Enum.STATE_OUTCIRCLE:
            StateFunc.OutCircle();
            break;

        case GameState_Enum.STATE_TRIALSUCCEED:
            StateFunc.TaskSucceed();
            break;

        case GameState_Enum.STATE_BREAK:
            StateFunc.Break();
            break;

        case GameState_Enum.STATE_BLOCKSET:
            StateFunc.BlockSet();
            break;

        case GameState_Enum.NULL:
            break;
        }
    }
Beispiel #13
0
    public void Update(T owner)
    {
        var evt = new StateEvent()
        {
            owner = owner,
            sm    = this,
        };

        if (nextState_ != null)
        {
            curState_  = nextState_;
            nextState_ = null;
            evt.type   = StateMachineEventType.Enter;
            time       = 0f;
            curState_(evt);
        }
        evt.type   = StateMachineEventType.Update;
        nextState_ = curState_(evt);
        time      += Time.deltaTime;
    }
        public void Run(string input)
        {
            _input = input;
            _start = 0;
            _pos   = 0;
            _line  = 1;
            _items = new List <Item>();

            try
            {
                StateFunc state = LexFunc.Start(this);
                while (state != null)
                {
                    state = state(this);
                }
            }
            catch (Exception ex)
            {
                Error(String.Format("Exception occured: {0}", ex));
            }
        }
        public void Process()
        {
            if (StateFunc == null)
            {
                return;
            }
            var state = StateFunc.Invoke(hud);

            if (state == LastState)
            {
                return;
            }

            if (state == DefaultState && ExitFunc != noop)
            {
                ExitFunc(hud);
            }
            if (state != DefaultState && EnterFunc != noop)
            {
                EnterFunc(hud);
            }

            LastState = state;
        }
Beispiel #16
0
            public void Update(IController control, Event e, ref AirlockStatus status)
            {
                if (state == null || e == Event.RESET)
                {
                    state     = IDLE;
                    stateTime = DateTime.UtcNow;
                    Update(control, Event.INIT, ref status);

                    if (e == Event.RESET)
                    {
                        return;
                    }
                }

                var ctx = new StateCtx
                {
                    Event   = e,
                    Status  = status,
                    Control = control,
                    Time    = (DateTime.UtcNow - stateTime).TotalSeconds
                };
                var result = state(ref ctx);

                if (result != null)
                {
                    description = result.Value.Description;

                    if (state != result.Value.NextState)
                    {
                        state     = result.Value.NextState;
                        stateTime = DateTime.UtcNow;

                        Update(control, Event.INIT, ref status);
                    }
                }
            }
Beispiel #17
0
 internal StateM(StateFunc <S, A> func)
 {
     Func = func;
 }
Beispiel #18
0
 protected Job(string name)
 {
     this.name = name;
     stateFunc = InitialState;
 }
Beispiel #19
0
 public State(StateFunc enter, StateFunc exit, StateFunc main)
 {
     enterState = enter;
     exitState  = exit;
     state      = main;
 }
Beispiel #20
0
 public State(StateFunc main)
 {
     state = main;
 }
Beispiel #21
0
 protected StateFunc Completed()
 {
     stateFunc = Completed;
     return(Completed);
 }
Beispiel #22
0
 public StateMachine(StateFunc firstState)
 {
     nextState_ = firstState;
 }
Beispiel #23
0
 public void Add(T id, StateFunc enter, StateFunc update, StateFunc leave)
 {
     m_States.Add(id, new State(id, enter, update, leave));
 }
Beispiel #24
0
 // Use this for initialization
 void Start()
 {
     nextStateFunc_ = stateInit;
 }
Beispiel #25
0
 public FSM(StateFunc startStateMainFunc)
 {
     stack = new List <State> {
         new State(startStateMainFunc)
     };
 }