private static void CoroutineRemoveAtSwap(Coroutine coroutine, bool returnToPool) { Coroutine endCoroutine = coroutines[coroutines.Count - 1]; coroutines.RemoveAtSwapEx(ref coroutine.mainCollectionIndex, ref endCoroutine.mainCollectionIndex); if (returnToPool) { UObject owner; if (coroutine.objectsCollectionIndex >= 0 && ((owner = coroutine.Owner as UObject) != null)) { List <Coroutine> collection; if (coroutinesByObject.TryGetValue(owner, out collection)) { Coroutine end = collection[collection.Count - 1]; collection.RemoveAtSwapEx(ref coroutine.objectsCollectionIndex, ref end.objectsCollectionIndex); } } if (coroutine.tagsCollectionIndex >= 0 && !string.IsNullOrEmpty(coroutine.Tag)) { List <Coroutine> collection; if (coroutinesByTag.TryGetValue(coroutine.Tag, out collection)) { Coroutine end = collection[collection.Count - 1]; collection.RemoveAtSwapEx(ref coroutine.tagsCollectionIndex, ref end.tagsCollectionIndex); } } if (coroutine.IsPooled) { CoroutinePool.ReturnObject(coroutine); } } }
public static Coroutine StartCoroutine(object obj, IEnumerator coroutine, CoroutineGroup group, string tag = null, bool pool = Coroutine.PoolByDefault) { Coroutine result = null; // Let the caller do this check /*if (!FThreading.IsInGameThread()) * { * FThreading.RunOnGameThread(delegate () { result = StartCoroutine(obj, coroutine, group, tag, pool); }); * return result; * }*/ if (pool) { result = CoroutinePool.New(coroutine); } else { result = new Coroutine(coroutine); } result.Owner = obj; result.Group = group; result.Tag = tag; result.mainCollectionIndex = coroutines.Count; coroutines.Add(result); return(result); }
public static Coroutine StartCoroutine(object obj, IEnumerator coroutine, CoroutineGroup group, string tag = null, bool pool = Coroutine.PoolByDefault) { Coroutine result = null; UObject ownerObj = obj as UObject; if (ownerObj != null) { IntPtr world = Native_UObject.GetWorld(ownerObj.Address); Debug.Assert(world != IntPtr.Zero, "UObject coroutines must be objects with a UWorld reference (e.g. AActor) - " + "this is so that the coroutine can be stopped when the world is destroyed."); } // Let the caller do this check /*if (!FThreading.IsInGameThread()) * { * FThreading.RunOnGameThread(delegate () { result = StartCoroutine(obj, coroutine, group, tag, pool); }); * return result; * }*/ if (pool) { result = CoroutinePool.New(coroutine); } else { result = new Coroutine(coroutine); } result.Owner = obj; result.Group = group; result.mainCollectionIndex = coroutines.Count; result.Tag = tag; coroutines.Add(result); if (ownerObj != null) { List <Coroutine> collection; if (!coroutinesByObject.TryGetValue(ownerObj, out collection)) { coroutinesByObject.Add(ownerObj, collection = new List <Coroutine>()); } result.objectsCollectionIndex = collection.Count; collection.Add(result); } if (!string.IsNullOrEmpty(tag)) { List <Coroutine> collection; if (!coroutinesByTag.TryGetValue(tag, out collection)) { coroutinesByTag.Add(tag, collection = new List <Coroutine>()); } result.tagsCollectionIndex = collection.Count; collection.Add(result); } return(result); }
private static void CoroutineRemoveAtSwap(Coroutine coroutine, bool returnToPool) { Coroutine endCoroutine = coroutines[coroutines.Count - 1]; coroutines.RemoveAtSwapEx(ref coroutine.mainCollectionIndex, ref endCoroutine.mainCollectionIndex); if (returnToPool && coroutine.IsPooled) { CoroutinePool.ReturnObject(coroutine); } }