Beispiel #1
0
 //Will stop this coroutine
 public static void DestroyCoroutine(CoroutineBase coroutine)
 {
     if (coroutine == null)
     {
         throw new System.ArgumentException("This coroutine is null");
     }
     RemoveCoroutineFromManager(coroutine);
 }
Beispiel #2
0
        public virtual void TestCleanup()
        {
            int n = 10;

            while (n-- > 0)
            {
                CoroutineBase.UpdateCoroutine();
            }
        }
Beispiel #3
0
 //Will resume all coroutines that were paused
 public static void ResumeAllCoroutines()
 {
     for (int i = 0; i <= coroutine_maxindex; i++)
     {
         CoroutineBase coroutine = coroutines [i];
         if (coroutine != null)
         {
             SetPause(coroutine, false);
         }
     }
 }
Beispiel #4
0
 private static void SetPause(string name, bool pauseValue)
 {
     for (int i = 0; i <= coroutine_maxindex; i++)
     {
         CoroutineBase coroutine = coroutines [i];
         if (coroutine.name == name)
         {
             coroutine.isPaused = pauseValue;
         }
     }
 }
Beispiel #5
0
 //Will reset all coroutines
 public static void ResetAllCoroutines()
 {
     for (int i = 0; i <= coroutine_maxindex; i++)
     {
         CoroutineBase coroutine = coroutines [i];
         if (coroutine != null)
         {
             ResetCoroutineInManager(coroutine);
         }
     }
 }
Beispiel #6
0
 private static void ResetCoroutineInManager(CoroutineBase coroutine)
 {
     if (coroutine.coroutineIEnumerable != null)
     {
         coroutine.coroutine = coroutine.coroutineIEnumerable.GetEnumerator();
         //Reset some members.
         coroutine.isPaused   = false;
         coroutine.isWaiting  = false;
         coroutine.pauseFrame = -1;
         coroutine.pauseTime  = -1.0f;
     }
 }
Beispiel #7
0
    //Will reset the coroutine
    public static void ResetCoroutine(CoroutineBase coroutine)
    {
        if (coroutine == null)
        {
            throw new System.ArgumentException("This coroutine is null");
        }
        int i = coroutine.index;

        if (i >= 0)
        {
            ResetCoroutineInManager(coroutine);
        }
    }
Beispiel #8
0
 public static void DestroyAllCoroutines()
 {
     for (int i = 0; i <= coroutine_maxindex; i++)
     {
         CoroutineBase coroutine = coroutines [i];
         if (coroutine != null)
         {
             coroutine.isFinished = true;
             coroutine.index      = -1;
             coroutines [i]       = null;
         }
     }
 }
Beispiel #9
0
 void Update()
 {
     time  = Time.time;
     frame = Time.frameCount;
     for (int i = 0; i <= coroutine_maxindex; i++)
     {
         CoroutineBase aCoroutine = coroutines [i];
         if (aCoroutine != null)
         {
             ProcessCoroutine(aCoroutine);
         }
     }
 }
Beispiel #10
0
    private static void SetPause(CoroutineBase coroutine, bool pauseValue)
    {
        if (coroutine == null)
        {
            throw new System.ArgumentException("This coroutine does not exist or no longer exists.");
        }
        int i = coroutine.index;

        if (i >= 0)
        {
            coroutines [i].isPaused = pauseValue;
        }
    }
Beispiel #11
0
    public static CoroutineBase StartCoroutine(IEnumerable coroutineEnumerable, CoroutineRunCondition method, bool loop)
    {
        if (coroutineEnumerable == null)
        {
            throw new System.ArgumentException("This coroutine is null");
        }

        CoroutineBase coroutine;

        coroutine = new CoroutineBase(coroutineEnumerable, coroutineEnumerable.GetEnumerator());
        coroutine.coroutineActionCondition = method;
        coroutine.loop = loop;

        PushCoroutineIntoManager(coroutine);
        return(coroutine);
    }
Beispiel #12
0
    //Will return true if the coroutine is running.
    public static bool isCoroutineRunning(CoroutineBase coroutine)
    {
        if (coroutine == null)
        {
            throw new System.ArgumentException("This coroutine is null");
        }
        int i = coroutine.index;

        if (i >= 0)
        {
            return(!coroutines [i].isFinished);
        }
        else
        {
            return(false);            //Not even in the CoroutineManager
        }
    }
Beispiel #13
0
        protected void Run(IEnumerator r)
        {
            runner.Add(r);

            while (runner.Count > 0)
            {
                CoroutineBase.UpdateCoroutine();
                for (int i = 0; i < runner.Count; i++)
                {
                    var item = runner[i];
                    if (!item.MoveNext())
                    {
                        runner.RemoveAt(i);
                        i--;
                    }
                }
            }
        }
Beispiel #14
0
    private static void RemoveCoroutineFromManager(CoroutineBase coroutine)
    {
        //Built-in Array implementation for mobiles
        int i = coroutine.index;

        if (i > -1)
        {
            coroutines [i]  = null;
            coroutine.index = -1;
            if (i >= coroutine_maxindex)
            {
                coroutine_maxindex = i - 1;
            }
        }
        else
        {
            throw new System.Exception("This coroutine has not been set into the Coroutine Manager");
        }
    }
Beispiel #15
0
 private static void PushCoroutineIntoManager(CoroutineBase coroutine)
 {
     //Built-in Array implementation for mobiles.
     for (int i = 0; i <= MAX_ARRAY_SIZE; i++)
     {
         if (i == MAX_ARRAY_SIZE)
         {
             throw new System.Exception("Coroutine Manager is full of coroutines. Should you increase its allowed size of " + MAX_ARRAY_SIZE);
         }
         if (coroutines [i] == null)
         {
             coroutine.index = i;
             coroutines [i]  = coroutine;
             if (i > coroutine_maxindex)
             {
                 coroutine_maxindex = i;
             }
             break;
         }
     }
 }
Beispiel #16
0
    // Use this for initialization
    void Start()
    {
        GameObject goSphere = GameObject.Find("Sphere");

        resettableCoroutine = CoroutineManager.StartCoroutine(resettableBounce(goSphere), runIfSomeValueIsTrue, false);
    }
Beispiel #17
0
 //Will pause the coroutine
 public static void PauseCoroutine(CoroutineBase coroutine)
 {
     SetPause(coroutine, true);
 }
Beispiel #18
0
 //Will resume all coroutines that have this name
 public static void ResumeCoroutine(CoroutineBase coroutine)
 {
     SetPause(coroutine, false);
 }
Beispiel #19
0
    //Main Processing
    private static void ProcessCoroutine(CoroutineBase coroutine)
    {
        IEnumerator coroutineSteps = coroutine.coroutine;

        if (coroutine.isWaiting == true)
        {
            if (coroutine.pauseTime > 0 && time >= coroutine.pauseTime)
            {
                coroutine.pauseTime = -1.0f;
                coroutine.isWaiting = false;
            }
            else if (coroutine.pauseFrame > 0 && frame >= coroutine.pauseFrame)
            {
                coroutine.pauseFrame = -1;
                coroutine.isWaiting  = false;
            }
            else
            {
                coroutine.isWaiting = true;
            }
        }

        if (coroutine.isPaused == true)
        {
            coroutine.pauseTime  += Time.deltaTime;
            coroutine.pauseFrame += 1;
        }
        if (coroutine.isWaiting == false &&
            coroutine.isPaused == false &&
            (coroutine.coroutineActionCondition == null ||
             (coroutine.coroutineActionCondition != null && coroutine.coroutineActionCondition() == true)))
        {
            if (coroutine.coroutine.MoveNext())
            {
                System.Object step = coroutineSteps.Current;
                if (step == null)
                {
                    step = (System.Object) 0;
                }
                if (step is UnityEngine.WaitForSeconds)
                {
                    throw new System.ArgumentException("You should use CoroutineManager.WaitForSeconds instead of WaitForSeconds. ");
                }
                else if (step is UnityEngine.WaitForFixedUpdate)
                {
                    throw new System.ArgumentException("Sorry WaitForFixedUpdate is not (yet?) supported in CoroutineManager ");
                }
                else if (step is UnityEngine.WaitForEndOfFrame)
                {
                    throw new System.ArgumentException("Sorry WaitForEndOfFrame is not (yet?) supported in CoroutineManager ");
                }
                else if (step is CoroutineManager.WaitForSeconds)
                {
                    coroutine.pauseTime  = ((CoroutineManager.WaitForSeconds)step).seconds;
                    coroutine.pauseTime += time;
                    coroutine.isWaiting  = true;
                }
                else if (step.GetType() == typeof(int))
                {
                    coroutine.pauseFrame  = (int)step;
                    coroutine.pauseFrame += frame;
                    coroutine.isWaiting   = true;
                }
                else
                {
                    throw new System.ArgumentException("this yield expression is not supported by CoroutineManager");
                }
            }
            else
            {
                if (coroutine.coroutineIEnumerable != null && coroutine.loop == true)
                {
                    print("here");
                    coroutine.coroutine = coroutine.coroutineIEnumerable.GetEnumerator();
                }
                else
                {
                    // coroutine finished
                    coroutine.isFinished = true;
                    RemoveCoroutineFromManager(coroutine);
                }
            }
        }
    }