예제 #1
0
        private void AddObject(ObjectCrtn objectCoroutine)
        {
            _allCoroutines.Add(objectCoroutine);
#if DEBUG && UNITY_EDITOR
            _leafCoroutines = _allCoroutines.FindAll(x => x.ChildCoroutine == null);
#endif
        }
예제 #2
0
        public ObjectCrtnLeafInspector(ObjectCrtn objCrtn)
        {
            Name = objCrtn.Name;
//			Id = objCrtn.Id;
            GameObject       = objCrtn.GameObject;
            EnvironmentStack = objCrtn.Stack;
        }
예제 #3
0
        private void OnCoroutineEnd(ObjectCrtn objectCoroutine)
        {
            Debug.Log("START CoroutineManager.OnCoroutineEnd " + objectCoroutine + " remaining " + _allCoroutines.Count + " coroutines.");

            if (objectCoroutine.ParentCoroutine != null)
            {
                Debug.Assert(objectCoroutine.ParentCoroutine.ChildCoroutine == objectCoroutine, "OnCoroutineEnd parent " + objectCoroutine.ParentCoroutine + " has child " + objectCoroutine.ParentCoroutine.ChildCoroutine + " instead of my " + objectCoroutine, true);
                objectCoroutine.ParentCoroutine.SetChild(null);
            }

            if (objectCoroutine.ChildCoroutine != null && objectCoroutine.ChildCoroutine.DestroyWithParent)             // TODO: GS && objectCoroutine.ChildCoroutine.GameObject == objectCoroutine.GameObject
            {
// TODO: GS now GO is not deleted				Debug.Assert(objectCoroutine.GameObject == null, "Killing coroutine " + objectCoroutine.Name + ", but it still has child " + objectCoroutine.ChildCoroutine.Name + " active. I am killing it too.", true);
                objectCoroutine.ChildCoroutine.Kill();
            }
#if DEBUG && UNITY_EDITOR
            if (objectCoroutine.GameObject && objectCoroutine != ObjectCrtn.ActiveCoroutine)
            {
                Picus.Utils.GO.Finder.FindComponentAddIfNotExist <GameObjectInfoCrtn>(objectCoroutine.GameObject).Remove(objectCoroutine);
            }
#endif
            RemoveObject(objectCoroutine);

            Debug.Log("END CoroutineManager.OnCoroutineEnd " + objectCoroutine + " remaining " + _allCoroutines.Count + " coroutines.");
        }
예제 #4
0
        public void Remove(ObjectCrtn objectCoroutine)
        {
            Debug.Log("Removing coroutineObject " + objectCoroutine + " from " + gameObject);
            bool removed = _coroutines.Remove(objectCoroutine);

            Debug.Assert(removed, "CoroutineGameObject " + gameObject + " trying to remove not existing coroutine " + objectCoroutine, true);

            if (objectCoroutine.ToString().Contains("CallAfterTime"))
            {
                Picus.Sys.Debug.Empty();
            }

            if (removed)
            {
                return;
            }

            for (int i = 0, cnt = _coroutines.Count; i < cnt; ++i)
            {
                if (_coroutines[i].Equals(objectCoroutine))
                {
                    _coroutines.RemoveAt(i);
                    break;
                }
            }
        }
예제 #5
0
        public IEnumerator CurrentCoroutineId()
        {
            ObjectCrtn active = ObjectCrtn.ActiveCoroutine;

            Debug.Assert(active != null, "Coroutine.Manager.CurrentCoroutineId but no coroutine active!", true);
            return(active == null ? default(IEnumerator) : active.CoroutineEnumerator);
        }
예제 #6
0
        public void KillCoroutine(IEnumerator id)
        {
            ObjectCrtn obj = _allCoroutines.Find(x => x.CoroutineEnumerator == id);

            if (obj != null)
            {
                obj.Kill();
            }
        }
예제 #7
0
        private string _name; // first field will be showed in inspector

        #endregion Fields

        #region Constructors

        public ObjectCrtn(MethodOneParam<ObjectCrtn> onEnd, IEnumerator coroutineEnumerator, MethodExceptionParam onException, GameObject obj, ObjectCrtn parentCoroutine)
        {
            _onException = onException;
            _onEnd = onEnd;
            _gameObject = obj;
            _name = "NOT STARTED YET";

            ParentCoroutine = parentCoroutine;
            CoroutineEnumerator = coroutineEnumerator;

            if (parentCoroutine != null)
                parentCoroutine.SetChild(this);
        }
예제 #8
0
        private void PurgeDeletedCoroutines()
        {
            List <ObjectCrtn> objectCoroutinesCopy = new List <ObjectCrtn>(_allCoroutines);
            int cnt = objectCoroutinesCopy.Count;

            for (int i = 0; i < cnt; ++i)
            {
                ObjectCrtn coroutineObj = objectCoroutinesCopy[i];
                if (coroutineObj.GameObject == null)
                {
                    OnCoroutineEnd(coroutineObj);
                }
            }
        }
예제 #9
0
        public ObjectCrtn(MethodOneParam <ObjectCrtn> onEnd, IEnumerator coroutineEnumerator, MethodExceptionParam onException, GameObject obj, ObjectCrtn parentCoroutine)
        {
            _onException = onException;
            _onEnd       = onEnd;
            _gameObject  = obj;
            _name        = "NOT STARTED YET";

            ParentCoroutine     = parentCoroutine;
            CoroutineEnumerator = coroutineEnumerator;

            if (parentCoroutine != null)
            {
                parentCoroutine.SetChild(this);
            }
        }
예제 #10
0
        /// <summary>
        /// Starts the coroutine.
        /// </summary>
        /// <returns>If not forked, returns coroutine.</returns>
        /// <param name="ecoroutine">Coroutine method</param>
        /// <param name="obj">Start it on this gameObject. If null, start on coroutineManager gameObject.</param>
        /// <param name="forked">When parent coroutine will be stoped, this will remain.</param>
        /// <param name="id">Identifier used for kill coroutine with all notforked childrens.</param>
        /// <param name="onException">On exception call. Not implemented yet!</param>
        public UnityEngine.Coroutine StartCoroutine(IEnumerator ecoroutine, GameObject obj, bool forked, ObjectCrtn.MethodExceptionParam onException = null, bool destroyWithParent = true)
        {
            Debug.Assert(forked || ObjectCrtn.ActiveCoroutine != null, "Starting main coroutine " + ecoroutine + ", but no parent coroutine active.", true);
        #if USE_ORIGINAL_COROUTINES
            return(StartCoroutineOriginal(ecoroutine));
        #endif
            PurgeDeletedCoroutines();

            GameObject onGameObject    = obj ?? gameObject;          // if obj not defined, start it on this gameobject
            ObjectCrtn objectCoroutine = new ObjectCrtn(OnCoroutineEnd, ecoroutine, onException, onGameObject, forked ? null : ObjectCrtn.ActiveCoroutine);
            objectCoroutine.DestroyWithParent = destroyWithParent;
            UnityEngine.Coroutine coroutine = CreateCoroutine(objectCoroutine);

            return(forked ? null : coroutine);
        }
예제 #11
0
        private UnityEngine.Coroutine CreateCoroutine(ObjectCrtn objectCoroutine)
        {
            //		Picus.Sys.Debug.StartLogSection("CoroutineManager.StartCoroutine " + ecoroutine.ToString(), Picus.Sys.Debug.Filter.LOG_COROUTINES);
            Debug.Log("START CoroutineManager.OnCoroutineStart " + objectCoroutine + " totally " + _allCoroutines.Count + " coroutines.");

            AddObject(objectCoroutine);
#if DEBUG && UNITY_EDITOR
            if (objectCoroutine.GameObject)
            {
                Picus.Utils.GO.Finder.FindComponentAddIfNotExist <GameObjectInfoCrtn>(objectCoroutine.GameObject).Add(objectCoroutine);
            }
#endif
            objectCoroutine.Coroutine = objectCoroutine.GameObject.GetComponent <Picus.MonoBehaviourExtend>().StartCoroutineOriginal(objectCoroutine.InternalRoutine(objectCoroutine.CoroutineEnumerator));

            Debug.Log("END CoroutineManager.OnCoroutineStart " + objectCoroutine + " totally " + _allCoroutines.Count + " coroutines.");

            //		Picus.Sys.Debug.StopLogSection();
            return(objectCoroutine.Coroutine);
        }
예제 #12
0
 public void SetChild(ObjectCrtn child)
 {
     ChildCoroutine = child;
 }
예제 #13
0
        public IEnumerator InternalRoutine(IEnumerator coroutine)
        {
            _name = coroutine.ToString();
            SnapStack();

#if DEBUG && UNITY_EDITOR
            ObjectCrtn crtn = this;
            while (crtn != null)
            {
                _coroutinesStack.Add(crtn);
                crtn = crtn.ParentCoroutine;
            }
#endif

#if BUBBLE_EXCEPTION
            bool firstPass = true;
#endif
            while (_active)
            {
                _activeCoroutines.Push(this);
                try
                {
                    if (!coroutine.MoveNext())
                    {
                        SnapStack();
                        _activeCoroutines.Pop();
                        _onEnd(this);
                        yield break;
                    }
                }
                catch (Exception e)
                {
                    _exception = e;
                }
                SnapStack();

                if (_exception != null)
                {
                    _activeCoroutines.Pop();
                    _onEnd(this);

                    if (_onException != null)
                    {
                        _onException(_exception);
                    }
                    else
                    {
#if BUBBLE_EXCEPTION
                        if (firstPass)                         // force first yield (throw before yield has different behaviour than after yield)
                        {
                            yield return(null);
                        }
                        Picus.Sys.Debug.Throw("CoroutineManager coroutine " + Name + " ended on bubbled exception " + _exception.Message + "\n Stack: " + _exception.StackTrace);
#else
                        // can't really throw, only log!! (throw before yield has different behaviour than after yield
                        Picus.Sys.Debug.Throw("CoroutineManager coroutine " + _name + " ended on exception " + _exception.Message + "\n " + ManagerCrtn.CoroutineStackDebugId + "\n" + _exception.StackTrace, true);
#endif
                    }

                    yield break;
                }
#if BUBBLE_EXCEPTION
                firstPass = false;
#endif
                _activeCoroutines.Pop();
                object yielded = coroutine.Current;
                if (SolveYieldEnd(yielded))
                {
                    _onEnd(this);
                    yield break;
                }
                else
                {
                    yield return(yielded);
                }
            }

            _onEnd(this);
            _active = false;
        }
예제 #14
0
        public void Add(ObjectCrtn objectCoroutine)
        {
            Debug.Log("Adding coroutineObject " + objectCoroutine + " to " + gameObject);

            _coroutines.Add(objectCoroutine);
        }
예제 #15
0
 public ObjectRetCrtn(MethodOneParam <ObjectCrtn> onEnd, IEnumerator enumerator, MethodExceptionParam onException, GameObject obj, ObjectCrtn parent) : base(onEnd, enumerator, onException, obj, parent)
 {
 }
예제 #16
0
 public void SetChild(ObjectCrtn child)
 {
     ChildCoroutine = child;
 }
예제 #17
0
        public bool IsCoroutineActive(IEnumerator id)
        {
            ObjectCrtn finded = _allCoroutines.Find(x => x.CoroutineEnumerator == id);

            return(finded != null);
        }