public void PooledLinkedList_CanAddItems()
        {
            var list = new PooledLinkedList<Int32>();

            list.AddLast(1);
            list.AddFirst(2);
            list.AddLast(3);

            TheResultingCollection(list)
                .ShouldBeExactly(2, 1, 3);
        }
Esempio n. 2
0
        public void PooledLinkedList_CanAddItems()
        {
            var list = new PooledLinkedList <Int32>();

            list.AddLast(1);
            list.AddFirst(2);
            list.AddLast(3);

            TheResultingCollection(list)
            .ShouldBeExactly(2, 1, 3);
        }
Esempio n. 3
0
        // this method has gotten out of hand..
        private static bool UpdateCoroutine(float scaledTime, float unscaledTime, BetterCoroutine coroutine)
        {
            if (coroutine.IsDone)
            {
                return(false);
            }

            if (coroutine.IsLinkedToObject && (!coroutine.LinkedObject || !coroutine.LinkedObject.activeInHierarchy))
            {
                return(false);
            }

            if (coroutine.IsLinkedToComponent && (!coroutine.LinkedComponent || !coroutine.LinkedComponent.isActiveAndEnabled))
            {
                return(false);
            }

            if (coroutine.IsPaused || coroutine.IsParentPaused)
            {
                return(true);
            }

            if (coroutine.Child != null)
            {
                return(true);
            }

            if (coroutine.WaitingForEndOfFrame)
            {
                return(true);
            }

            var time = coroutine.WaitTimeIsUnscaled ? unscaledTime : scaledTime;

            if (coroutine.WaitTillTime > time)
            {
                return(true);
            }

            var enumerator = coroutine.Enumerator;

            try
            {
                if (!enumerator.MoveNext())
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                // something bad happened in the coroutine, just print out the error and stop the problematic routine.
                // todo: should this stop parent coroutines as well?
                Debug.LogError(e);
                return(false);
            }

            var current = enumerator.Current;

            if (current == null)
            {
                return(true);
            }

            var subroutineId = current as int?;

            if (subroutineId != null)
            {
                var subroutine = IdToCoroutine[subroutineId.Value];

                if (subroutine != null)
                {
                    coroutine.Child   = subroutine;
                    subroutine.Parent = coroutine;
                }
                return(true);
            }

            var subEnumerator = current as IEnumerator;

            if (subEnumerator != null)
            {
                StartChild(subEnumerator, coroutine);
                return(true);
            }

            var waitForSeconds = current as WaitForSecondsLite;

            if (waitForSeconds != null)
            {
                time = waitForSeconds.Unscaled ? unscaledTime : scaledTime;
                coroutine.WaitTimeIsUnscaled = waitForSeconds.Unscaled;
                coroutine.WaitTillTime       = time + waitForSeconds.Duration;
                return(true);
            }

            if (current is WaitForEndOfFrame)
            {
                coroutine.WaitingForEndOfFrame = true;
                CoroutinesWaitingForEndOfFrame.AddFirst(coroutine);
                return(true);
            }

            var www = current as WWW;

            if (www != null)
            {
                if (!www.isDone)
                {
                    StartChild(Coroutines.WaitForWWW.Create(www), coroutine);
                }
                return(true);
            }

            var asyncOperation = current as AsyncOperation;

            if (asyncOperation != null)
            {
                if (!asyncOperation.isDone)
                {
                    StartChild(Coroutines.WaitForAsyncOperation.Create(asyncOperation), coroutine);
                }
                return(true);
            }

            // we could use reflection, but it's slow and users really should switch over.
            if (current is WaitForSeconds)
            {
                Debug.LogError("UnityEngine.WaitForSeconds is not supported in BetterCoroutines. Please use BetterCoroutines.WaitForSeconds() instead.");
            }

            return(true);
        }
Esempio n. 4
0
        public void Count_KeepsUpWithAdd()
        {
            Assert.AreEqual(0, PooledLinkedList.Count);

            PooledLinkedList.AddFirst(1);
            Assert.AreEqual(1, PooledLinkedList.Count);

            PooledLinkedList.AddFirst(2);
            Assert.AreEqual(2, PooledLinkedList.Count);

            PooledLinkedList.AddFirst(3);
            Assert.AreEqual(3, PooledLinkedList.Count);
        }