Example #1
0
 private void ActivateLog(SimpleMachine machine)
 {
     if ((listen & LogEntry.MachineChange) > 0)
     {
         machine.Change(RegisterAction(machine, LogEntry.MachineChange, Change, machine));
     }
     if (!(listen == LogEntry.None || listen == LogEntry.MachineChange))
     {
         foreach (State state in machine.states.Values)
         {
             if ((listen & LogEntry.StateEnter) > 0)
             {
                 state.Enter(RegisterAction(machine, LogEntry.StateEnter, Enter, state));
             }
             if ((listen & LogEntry.StateStay) > 0)
             {
                 state.Stay(RegisterAction(machine, LogEntry.StateStay, Stay, state));
             }
             if ((listen & LogEntry.StateExit) > 0)
             {
                 state.Exit(RegisterAction(machine, LogEntry.StateExit, Exit, state));
             }
             foreach (Transition transition in state.transitions)
             {
                 if ((listen & LogEntry.TransitionJump) > 0)
                 {
                     transition.Jump(RegisterAction(machine, LogEntry.TransitionJump, Jump, transition));
                 }
             }
         }
     }
 }
Example #2
0
 // Update is called once per frame
 public void AddMachine(SimpleMachine machine)
 {
     if (!journals.Contains(machine))
     {
         journals.Add(machine);
         ActivateLog(machine);
     }
 }
Example #3
0
 public void RemoveMachine(SimpleMachine machine)
 {
     if (journals.Contains(machine))
     {
         journals.Remove(machine);
         DeactivateLog(machine);
     }
 }
Example #4
0
 public static void Add(SimpleMachine machine)
 {
     if (instance != null)
     {
         if (instance.isActiveAndEnabled)
         {
             instance.AddMachine(machine);
         }
     }
 }
Example #5
0
 private void UnregisterAction(SimpleMachine machine, LogEntry entry, Func <Action, object> eventUnregister)
 {
     if (actions.ContainsKey(machine) && actions[machine].ContainsKey(entry))
     {
         foreach (Action action in actions[machine][entry])
         {
             eventUnregister(action);
         }
     }
 }
Example #6
0
        private void Change(object source)
        {
            SimpleMachine machine = source as SimpleMachine;

            if (machine == null)
            {
                return;
            }
            Debug.Log(string.Format("({0}) Machine: {1} Change {2}-->{3}", TimeStr(), machine, machine.last.name,
                                    machine.current.name));
        }
Example #7
0
        private Action RegisterAction(SimpleMachine machine, LogEntry entry, Action <object> action, object info)
        {
            Action res = (() => action(info));

            if (!actions.ContainsKey(machine))
            {
                actions.Add(machine, new Dictionary <LogEntry, List <Action> >());
            }
            if (!actions[machine].ContainsKey(entry))
            {
                actions[machine].Add(entry, new List <Action>());
            }
            actions[machine][entry].Add(res);
            return(res);
        }
Example #8
0
        private void DeactivateLog(SimpleMachine machine)
        {
            if (!actions.ContainsKey(machine))
            {
                return;
            }
            UnregisterAction(machine, LogEntry.MachineChange, machine.Change);

            foreach (State state in machine.states.Values)
            {
                UnregisterAction(machine, LogEntry.StateEnter, state.Enter);
                UnregisterAction(machine, LogEntry.StateStay, state.Stay);
                UnregisterAction(machine, LogEntry.StateExit, state.Exit);
                foreach (Transition transition in state.transitions)
                {
                    UnregisterAction(machine, LogEntry.TransitionJump, transition.Jump);
                }
            }
        }
Example #9
0
 public virtual void InitFSM()
 {
     fsm = new SimpleMachine("Brain");
 }