Exemple #1
0
    public void AddState(string stateName, FSMDelegate executeDelegate, FSMDelegate enterDelegate, FSMDelegate exitDelegate)
    {
        if (executeDelegate == null && enterDelegate == null && exitDelegate == null)
        {
            if (DEBUG)
            {
                Debug.Log("Pass at least one delegate!");
            }
            return;
        }

        if (stateNames.Contains(stateName))
        {
            if (DEBUG)
            {
                Debug.Log("State with this name already exists!");
            }
            return;
        }

        stateNames.Add(stateName);
        executeDelegates.Add(stateName, executeDelegate);
        enterDelegates.Add(stateName, enterDelegate);
        exitDelegates.Add(stateName, exitDelegate);
    }
    private FSMDelegate FSM;                            //FSM狀態機參數

    // Use this for initialization
    void Start()
    {
        //獲取燈組件。獲取FSM狀態機組件
        //設置FSM狀態機的當前狀態
        //添加燈打開/關閉狀態的委託事件,對應好下標
        light            = GetComponent <Light> ();
        FSM              = gameObject.AddComponent <FSMDelegate> ();
        FSM.currentState = (int)LightState.Open;
        FSM.states.Add(new BaseDelegate(OnOpenState));
        FSM.states.Add(new BaseDelegate(OnCloseState));
    }
Exemple #3
0
	public void AddState( string stateName, FSMDelegate executeDelegate, FSMDelegate enterDelegate, FSMDelegate exitDelegate ){
		if( executeDelegate == null && enterDelegate == null && exitDelegate == null ){
			if( DEBUG )Debug.Log("Pass at least one delegate!");
			return;
		}

		if( stateNames.Contains( stateName ) ){
			if( DEBUG )Debug.Log("State with this name already exists!");
			return;
		}

		stateNames.Add( stateName );
		executeDelegates.Add( stateName, executeDelegate );
		enterDelegates.Add( stateName, enterDelegate );
		exitDelegates.Add( stateName, exitDelegate );
	}