示例#1
0
    // Use this for initialization
    void Awake()
    {
        DontDestroyOnLoad(gameObject);
        Debug.Log("FSMBehavior - Awake");

        // TODO: add all initial constructors here
        foreach(string szType in _FSMConstructorTypes)
        {
            Type constructorType = Type.GetType(szType);
            if(constructorType != null)
            {
                if (constructorType.IsSubclassOf(typeof(IFSMConstructor)))
                {
                    RetroFSM.AddConstructor(constructorType);
                }
                else
                {
                    Debug.LogError(string.Format("Type \"{0}\" not derived IFSMConstructor type!", szType));
                }

            }
            else
            {
                Debug.LogError(string.Format("Constructor Type \"{0}\" not found!", szType));
            }
        }

        // build all constructors
        RetroFSM.Build();

        // Start Library here because OnStart() needs to happen before OnEnable, and Start() doesnt
        RetroFSM.StartLibrary();
    }
    public override void Destroy()
    {
        Dictionary <string, StateInfo> FinalMachine = GenerateMachine();

        foreach (KeyValuePair <string, StateInfo> pair in FinalMachine)
        {
            RetroFSM.Chapter(ChapterHash).RemoveState(pair.Value);
        }
    }
    private string _FSMID = "FSMOverride";     // "FSMOverride" can be set to any ID we want

    void Start()
    {
        // We can start an FSM through the FSMBehavior by giving it a list of the FSMConstructors we created.
        // This will start the FSM when the game starts(useful for gameplay states e.g. splashscreen, main menu, gameplay, pause, etc)
        // OR we can manually start a new FSM through this function.  This is helpful for when you want a bunch of gameobjects to share an FSM(e.g AI)
        RetroFSM.StartNewChapter <ExampleFSMOverrideConstructor>(_FSMID);

        // this is how we can get a handle to an FSM so we can change states
        _FSMOverride = RetroFSM.Chapter(_FSMID);
    }
    public override void Build()
    {
        Dictionary <string, StateInfo> FinalMachine = GenerateMachine();

        foreach (KeyValuePair <string, StateInfo> pair in FinalMachine)
        {
            RetroFSM.Chapter(ChapterHash).AddState(pair.Value);

            // check for default
            if (pair.Value.Attribute.IsDefault)
            {
                RetroFSM.Chapter(ChapterHash).SetDefaultState(pair.Value);
            }
        }
    }
 void OnDestroy()
 {
     // this is how we stop an FSM
     RetroFSM.StopChapter <ExampleFSMOverrideConstructor>(_FSMID);
 }
示例#6
0
 void LateUpdate()
 {
     RetroFSM.LateUpdate();
 }
示例#7
0
 // Update is called once per frame
 void Update()
 {
     RetroFSM.PriorityUpdate();
     RetroFSM.Update();
 }
示例#8
0
 void OnDisable()
 {
     Debug.Log("FSMBehavior - OnDisable");
     RetroFSM.PauseLibrary();
 }
示例#9
0
 void OnEnable()
 {
     Debug.Log("FSMBehavior - OnEnable");
     RetroFSM.ResumeLibrary();
 }
示例#10
0
 void OnDestroy()
 {
     Debug.Log("FSMBehavior - OnDestroy");
     RetroFSM.StopLibrary();
 }