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

            newState.Init();

            states.Add(newState.Name, newState);
        }
Ejemplo n.º 2
0
        protected void SwitchState(string stateName)
        {
            IntelliMonoFSMState2D 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 <Collision2D> a = null;
                        if (result.collisionMethods.TryGetValue(key, out a))
                        {
                            if (a != null)
                            {
                                AssignDelegates(key, a);
                            }
                        }
                    }

                    foreach (var key in result.triggerMethods.Keys)
                    {
                        Action <Collider2D> 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");
            }
        }