Exemple #1
0
        public static ITriggerAction <T> Then <T>(this ITriggerAction <ITriggerAction <T> > self)
        {
            Trigger <T> trigger = new Trigger <T>(oneShot: self.OneShot);

            self.Add((item1, ex1) =>
            {
                if (ex1 != null)
                {
                    trigger.Error(ex1);
                }
                else
                {
                    item1.Add((item2, ex2) =>
                    {
                        if (ex2 != null)
                        {
                            trigger.Error(ex2);
                        }
                        else
                        {
                            trigger.Fire(item2);
                        }
                    });
                }
            });
            return(trigger.Action);
        }
Exemple #2
0
        public static ITriggerAction <T[]> Combine <T>(params ITriggerAction <T>[] actions)
        {
            Trigger <T[]> trigger = new Trigger <T[]>();

            T[] ret = new T[actions.Length];
            if (actions == null || actions.Length == 0)
            {
                trigger.Fire(ret);
                return(trigger.Action);
            }
            int count = 0;

            for (int i = 0; i < actions.Length; i++)
            {
                int index = i;
                ITriggerAction <T> action = actions[i];
                action.Add((x) =>
                {
                    ret[index] = x;
                    count++;
                    if (count == ret.Length)
                    {
                        trigger.Fire(ret);
                    }
                });
                action.OnFail += trigger.Error;
            }
            return(trigger.Action);
        }
Exemple #3
0
        public static ITriggerAction <T> Select <T>(this ITriggerAction self, Func <T> func, bool oneShot = true)
        {
            Trigger <T> trigger = new Trigger <T>(oneShot: self.OneShot);

            self.OnFail += trigger.Error;
            self.Add(() => trigger.Fire(func()));
            return(trigger.Action);
        }
Exemple #4
0
        public static ITriggerAction <bool> Any <T>(this ITriggerAction <T> self)
        {
            Trigger <bool> trigger = new Trigger <bool>(true);

            self.Add((item, ex) =>
            {
                if (ex != null)
                {
                    trigger.Fire(true);
                }
            });
            return(trigger.Action);
        }
Exemple #5
0
        public static ITriggerAction <T> Timeout <T>(this ITriggerAction <T> self, float time, bool realtime = false)
        {
            Trigger <T> trigger = new Trigger <T>(oneShot: self.OneShot);

            self.Add(trigger);
            var timeout = realtime ? TriggerBehaviour.Realtime(time) : TriggerBehaviour.Time(time);

            timeout.Add(ret =>
            {
                if (!trigger.Action.Fired)
                {
                    trigger.Error(new TimeoutException("trigger timeout"));
                }
            });
            return(trigger.Action);
        }
Exemple #6
0
        public static ITriggerAction <T> Where <T>(this ITriggerAction <T> self, Func <T, bool> func)
        {
            Trigger <T> trigger = new Trigger <T>(oneShot: false);

            self.Add((item, ex) =>
            {
                if (ex != null)
                {
                    trigger.Error(ex);
                }
                else if (func(item))
                {
                    trigger.Fire(item);
                }
            });
            return(trigger.Action);
        }
Exemple #7
0
        public static ITriggerAction <U> Select <T, U>(this ITriggerAction <T> self, Func <T, U> func, bool oneShot = true)
        {
            Trigger <U> trigger = new Trigger <U>(oneShot: self.OneShot);

            self.Add((item, ex) =>
            {
                if (ex != null)
                {
                    trigger.Error(ex);
                }
                else
                {
                    trigger.Fire(func(item));
                }
            });
            return(trigger.Action);
        }
Exemple #8
0
        public static ITriggerAction Then(this ITriggerAction <ITriggerAction> self)
        {
            Trigger trigger = new Trigger(oneShot: self.OneShot);

            self.Add((item1, ex1) =>
            {
                if (ex1 != null)
                {
                    trigger.Error(ex1);
                }
                else
                {
                    item1.Add(trigger.Fire);
                    item1.OnFail += trigger.Error;
                }
            });
            return(trigger.Action);
        }
Exemple #9
0
        public static ITriggerAction <T> Realtime <T>(this ITriggerAction <T> self, float time)
        {
            Trigger <T> trigger = new Trigger <T>(oneShot: self.OneShot);

            self.Add((item, ex) =>
            {
                if (ex != null)
                {
                    trigger.Error(ex);
                }
                else
                {
                    TriggerBehaviour.Realtime(time)
                    .Add(x => trigger.Fire(item))
                    .AddFail(trigger.Error);
                }
            });
            return(trigger.Action);
        }
Exemple #10
0
 public static ITriggerAction <T> Add <T>(this ITriggerAction <T> self, Trigger <T> trigger)
 {
     self.Add(trigger.Fire);
     self.AddFail(trigger.Error);
     return(self);
 }