コード例 #1
0
    private FSMDelegateNew <LightState> FSM;            //泛型FSM狀態機

    // Use this for initialization
    void Start()
    {
        //獲取燈組件,new個泛型狀態機
        //設置FSM狀態機的當前狀態
        //添加燈打開/關閉狀態的委託事件,對應狀態
        light = GetComponent <Light> ();
        FSM   = new FSMDelegateNew <LightState> (LightState.Open);
        FSM.AddCallback(LightState.Open, new BaseDelegateNew(OnOpenState));
        FSM.AddCallback(LightState.Close, new BaseDelegateNew(OnCloseState));
    }
コード例 #2
0
    private Material matCube;                            //Cube的材質參數

    // Use this for initialization
    void Start()
    {
        //獲取Cube的材質
        //建立Cube狀態機並且設置當前默認狀態
        //給狀態機添加對應狀態下的對應狀態事件
        matCube = GetComponent <Renderer>().material;
        FSM     = new FSMDelegateNew <CubeState>(CubeState.Idle);
        FSM.AddCallback(CubeState.Idle, new BaseDelegateNew(OnCuebIdle));
        FSM.AddCallback(CubeState.Move, new BaseDelegateNew(OnCubeMove));
    }