Exemple #1
0
        public static void CallInSequence <T>(System.Action callback, IEnumerable <T> collection, System.Action <T, System.Action> each, bool waitPrevious = false)
        {
            if (collection == null)
            {
                if (callback != null)
                {
                    callback.Invoke();
                }
                return;
            }

            var count = collection.Count();

            var completed = false;
            var counter   = 0;

            System.Action callbackItem = () => {
                ++counter;
                if (counter < count)
                {
                    return;
                }

                completed = true;

                if (callback != null)
                {
                    callback();
                }
            };

            if (waitPrevious == true)
            {
                var ie = collection.GetEnumerator();

                System.Action doNext = null;
                doNext = () => {
                    if (Coroutines.MoveNext(ie, collection) == true)
                    {
                        if (ie.Current != null)
                        {
                            each(ie.Current, () => {
                                callbackItem();
                                doNext();
                            });
                        }
                        else
                        {
                            callbackItem();
                            doNext();
                        }
                    }
                };
                doNext();
            }
            else
            {
                var ie = collection.GetEnumerator();
                while (Coroutines.MoveNext(ie, collection) == true)
                {
                    if (ie.Current != null)
                    {
                        each(ie.Current, callbackItem);
                    }
                    else
                    {
                        callbackItem();
                    }

                    if (completed == true)
                    {
                        break;
                    }
                }
            }

            if (count == 0 && callback != null)
            {
                callback();
            }
        }
Exemple #2
0
 public void Awake()
 {
     Coroutines.instance = this;
 }
Exemple #3
0
 public static void CallInSequence <T>(System.Action callback, bool waitPrevious, System.Action <T, System.Action> each, params T[] collection)
 {
     Coroutines.CallInSequence(callback, (IEnumerable <T>)collection, each, waitPrevious);
 }
Exemple #4
0
 public static void Wait(System.Func <bool> waitFor, System.Action callback)
 {
     Coroutines.instance.StartCoroutine(Coroutines.Waiter_INTERNAL(waitFor, callback));
 }
Exemple #5
0
 public static void WaitTime(float time, System.Action callback)
 {
     Coroutines.instance.StartCoroutine(Coroutines.TimeWaiter_INTERNAL(time, callback));
 }
Exemple #6
0
        public static void CallInSequence <T, TClosure>(ref TClosure closure, ClosureDelegateCallback <TClosure> callback, IEnumerable <T> collection, ClosureDelegateEachCallback <T, TClosure> each, bool waitPrevious = false)
        {
            if (collection == null)
            {
                if (callback != null)
                {
                    callback.Invoke(ref closure);
                }
                return;
            }

            var count = collection.Count();

            var completed = false;
            var counter   = 0;
            ClosureDelegateCallback <TClosure> callbackItem = (ref TClosure cParamsInner) => {
                ++counter;
                if (counter < count)
                {
                    return;
                }

                completed = true;

                if (callback != null)
                {
                    callback.Invoke(ref cParamsInner);
                }
            };

            if (waitPrevious == true)
            {
                var ie = collection.GetEnumerator();

                ClosureDelegateCallback <TClosure> doNext = null;
                doNext = (ref TClosure cParamsInner) => {
                    if (Coroutines.MoveNext(ie, collection) == true)
                    {
                        if (ie.Current != null)
                        {
                            each.Invoke(ie.Current, (ref TClosure cParams) => {
                                callbackItem(ref cParams);
                                doNext(ref cParams);
                            }, ref cParamsInner);
                        }
                        else
                        {
                            callbackItem.Invoke(ref cParamsInner);
                            doNext.Invoke(ref cParamsInner);
                        }
                    }
                };
                doNext.Invoke(ref closure);
            }
            else
            {
                var ie = collection.GetEnumerator();
                while (Coroutines.MoveNext(ie, collection) == true)
                {
                    if (ie.Current != null)
                    {
                        each.Invoke(ie.Current, callbackItem, ref closure);
                    }
                    else
                    {
                        callbackItem.Invoke(ref closure);
                    }

                    if (completed == true)
                    {
                        break;
                    }
                }
            }

            if (count == 0 && callback != null)
            {
                callback(ref closure);
            }
        }
Exemple #7
0
 public static void NextFrame(System.Action callback)
 {
     Coroutines.instance.StartCoroutine(Coroutines.WaitFrames_INTERNAL(callback, 1));
 }