コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        CurrentLevelIndex = 0;
        Debug.Log("level : " + CurrentLevelIndex);
        GameFSM.GetState(GameStateLevel).OnStateInEvent.AddListener(() =>
        {
            LevelFsm = new FSMLite();
            LevelFsm.RegisterState(new FSMLite.State()
            {
                Name = LevelStateOpen
            });
            LevelFsm.RegisterState(new FSMLite.State()
            {
                Name = LevelStateClose
            });
            LevelFsm.GetState(LevelStateOpen).OnStateInEvent.AddListener(() =>
            {
                DistortionMask.SetActive(false);
            });
            LevelFsm.GetState(LevelStateClose).OnStateInEvent.AddListener(() =>
            {
                DistortionMask.SetActive(true);
            });

            UI.SetLevelFSM(LevelFsm);
            LevelFsm.Start(LevelStateOpen);

            if (LevelPrefabList.Count > CurrentLevelIndex)
            {
                var levelPrefab = LevelPrefabList[CurrentLevelIndex];
                var levelGo     = Instantiate(levelPrefab, transform);
                if (!(levelGo is null))
                {
                    Level = levelGo.GetComponent <Level.Level>();
                }
                switchCameraLimit();
            }
        });
        GameFSM.GetState(GameStateLevel).OnStateOutEvent.AddListener(() =>
        {
            UI.UnSetLevelFSM(LevelFsm);
            LevelFsm.Clear();
            LevelFsm = null;
            Destroy(Level.gameObject);
        });

        UI.SetGameFSM(GameFSM);

        GameFSM.Start(GameStateMenu);
    }
コード例 #2
0
ファイル: FSMLite.cs プロジェクト: zswDev/myMd
    public Test()
    {
        FSMLite fsmLite = new FSMLite();

        //设置多个状态
        fsmLite.AddState("IDLE");
        fsmLite.AddState("WALK");
        fsmLite.AddState("RUN");
        fsmLite.AddState("FLY");
        //加入转换条件,以及触发回调
        fsmLite.AddTranslation("IDLE", "CLICK", "WALK", onWalk);
        fsmLite.AddTranslation("WALK", "CLICK", "RUN", this.onRun);
        //启动状态机,默认第一个状态
        fsmLite.Start("IDLE");
    }