/// <summary> /// async to instantiate the gameObjects. /// if the FPS is lower. the interval between instantiations will expend. /// </summary> /// <param name="source">which one</param> /// <param name="count">the amount</param> /// <param name="onInst">callback when instaniate every one</param> /// <param name="result">the container if you want to collect the result</param> /// <param name="autoCollectResult">true if you want to collect the result, but you dont need the cache result.</param> /// <param name="toBeContinue">To be continue or stop immediately. true if continue, false otherwise. it accept a index of cloning gameObject</param> public void InstantiateAsync(GameObject source, int count, Action <GameObject, int> onInst, Action <GameObject> onCompleted, IList <GameObject> result = null, bool autoCollectResult = true, Predicate <int> toBeContinue = null) { if (count <= 0) { throw new Exception(string.Format("InstantiateAsync do not allow the count ({0}) equals to or less than zero.", count)); } if (result == null && autoCollectResult) { result = new List <GameObject>(count); } mAsyncInstAssetsInfo.Add(AsyncInstAssetInfo.Alloc(source, count, onInst, onCompleted, result, toBeContinue)); }
private void CleanupInvalidTasks() { if (mAsyncInstTransiting) { DebugUtility.LogError(LoggerTags.AssetManager, "Check the error call."); return; } mAsyncInstTransiting = true; int length = mAsyncInstAssetsInfo.Count; for (int i = 0; i < length; i++) { var task = mAsyncInstAssetsInfo[i]; if (task.state == AsyncInstAssetInfo.EAsyncState.ToStop) { task.Reset(); AsyncInstAssetInfo.Dealloc(ref task); } } mAsyncInstTransiting = false; mAsyncInstAssetsInfo.RemoveAll(task => task.state == AsyncInstAssetInfo.EAsyncState.ToStop); }
internal static void Dealloc(ref AsyncInstAssetInfo info) { MemoryPool <AsyncInstAssetInfo> .defaultInstance.Push(info); info = null; }