private void AddObject(ObjectCrtn objectCoroutine) { _allCoroutines.Add(objectCoroutine); #if DEBUG && UNITY_EDITOR _leafCoroutines = _allCoroutines.FindAll(x => x.ChildCoroutine == null); #endif }
public ObjectCrtnLeafInspector(ObjectCrtn objCrtn) { Name = objCrtn.Name; // Id = objCrtn.Id; GameObject = objCrtn.GameObject; EnvironmentStack = objCrtn.Stack; }
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."); }
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; } } }
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); }
public void KillCoroutine(IEnumerator id) { ObjectCrtn obj = _allCoroutines.Find(x => x.CoroutineEnumerator == id); if (obj != null) { obj.Kill(); } }
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); }
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); } } }
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); } }
/// <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); }
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); }
public void SetChild(ObjectCrtn child) { ChildCoroutine = child; }
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; }
public void Add(ObjectCrtn objectCoroutine) { Debug.Log("Adding coroutineObject " + objectCoroutine + " to " + gameObject); _coroutines.Add(objectCoroutine); }
public ObjectRetCrtn(MethodOneParam <ObjectCrtn> onEnd, IEnumerator enumerator, MethodExceptionParam onException, GameObject obj, ObjectCrtn parent) : base(onEnd, enumerator, onException, obj, parent) { }
public void SetChild(ObjectCrtn child) { ChildCoroutine = child; }
public bool IsCoroutineActive(IEnumerator id) { ObjectCrtn finded = _allCoroutines.Find(x => x.CoroutineEnumerator == id); return(finded != null); }