Esempio n. 1
0
        protected void AddState(IntelliMonoFSMState newState)
        {
            if (states == null)
            {
                states = new Dictionary <string, IntelliMonoFSMState>();
            }

            newState.Init();

            states.Add(newState.Name, newState);
        }
Esempio n. 2
0
        protected void SwitchState(string stateName)
        {
            IntelliMonoFSMState result = null;

            if (states.TryGetValue(stateName, out result))
            {
                if (result != null)
                {
                    if (ExitState != null)
                    {
                        ExitState();
                    }
                    prevState = curState;
                    curState  = result;
                    foreach (var key in result.stateMethods.Keys)
                    {
                        Action a = null;
                        if (result.stateMethods.TryGetValue(key, out a))
                        {
                            if (a != null)
                            {
                                AssignDelegates(key, a);
                            }
                        }
                    }

                    foreach (var key in result.collisionMethods.Keys)
                    {
                        Action <Collision> a = null;
                        if (result.collisionMethods.TryGetValue(key, out a))
                        {
                            if (a != null)
                            {
                                AssignDelegates(key, a);
                            }
                        }
                    }

                    foreach (var key in result.triggerMethods.Keys)
                    {
                        Action <Collider> a = null;
                        if (result.triggerMethods.TryGetValue(key, out a))
                        {
                            if (a != null)
                            {
                                AssignDelegates(key, a);
                            }
                        }
                    }

                    if (EnterState != null)
                    {
                        EnterState();
                    }
                }
            }
            else
            {
                Debug.LogError("State: " + stateName + " Doesn't exist in IntelliMonoFSM");
            }
        }