public static void Trigger <TEvent>(FlowMachine target, params object[] arguments) where TEvent : MachineEvent
        {
            var events = EventsToTrigger <TEvent>(target);

            foreach (var @event in events)
            {
                @event.Trigger(arguments);
            }

            FreeEventsToTrigger(events);
        }
        public override void Initialize()
        {
            base.Initialize();

            if ((FlowMachine)this.graph.owner != null)
            {
                flowmachine = (FlowMachine)this.graph.owner;
            }
            else
            {
                statemachine = (StateMachine)this.graph.owner;
            }
        }
        private static HashSet <TEvent> EventsToTrigger <TEvent>(FlowMachine target) where TEvent : MachineEvent
        {
            // Avoiding ToHashSetPooled because IEnumerable allocates memory,
            // whereas HashSet has a struct enumerator. Using HashSet instead
            // of array to avoid iterating twice for the count.

            var toTrigger = HashSetPool <TEvent> .New();

            if (events.ContainsKey(target))
            {
                foreach (var @event in events[target])
                {
                    if (@event is TEvent)
                    {
                        toTrigger.Add((TEvent)@event);
                    }
                }
            }

            return(toTrigger);
        }
Exemplo n.º 4
0
 public static void Trigger(FlowMachine target, string name, params object[] args)
 {
     Trigger <CustomMachineEvent>(target, CombineArgs(name, args));
 }