private void DestroyActComponent(bool onlyDestory = false) { for (int i = 0; i < ListComponent.Count; ++i) { ListComponent[i].OnDestroy(); } if (!onlyDestory) { ListComponent.Clear(); } }
/// <summary> /// 异步加载assetbundle, 加载ab包分两部分,第一部分是从硬盘加载,第二部分加载all assets。两者不能同时并发 /// </summary> public static async ETTask LoadBundleAsync(this ResourcesComponent self, string assetBundleName) { assetBundleName = assetBundleName.BundleNameToLower(); string[] dependencies = self.GetSortedDependencies(assetBundleName); //Log.Debug($"-----------dep load async start {assetBundleName} dep: {dependencies.ToList().ListToString()}"); using (ListComponent <ABInfo> abInfos = ListComponent <ABInfo> .Create()) { async ETTask LoadDependency(string dependency, List <ABInfo> abInfosList) { CoroutineLock coroutineLock = null; try { coroutineLock = await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Resources, dependency.GetHashCode()); ABInfo abInfo = await self.LoadOneBundleAsync(dependency); if (abInfo == null || abInfo.RefCount > 1) { return; } abInfosList.Add(abInfo); } finally { coroutineLock?.Dispose(); } } // LoadFromFileAsync部分可以并发加载 using (ListComponent <ETTask> tasks = ListComponent <ETTask> .Create()) { foreach (string dependency in dependencies) { tasks.Add(LoadDependency(dependency, abInfos)); } await ETTaskHelper.WaitAll(tasks); // ab包从硬盘加载完成,可以再并发加载all assets tasks.Clear(); foreach (ABInfo abInfo in abInfos) { tasks.Add(self.LoadOneBundleAllAssets(abInfo)); } await ETTaskHelper.WaitAll(tasks); } } }
//--------------------------------------------------------------------- // 直接销毁该Entity internal void _destroy() { if (SignDestroy) { return; } SignDestroy = true; // 先销毁所有子Entity if (mMapChild != null) { Dictionary <string, Dictionary <string, Entity> > map_children = new Dictionary <string, Dictionary <string, Entity> >(mMapChild); foreach (var i in map_children) { List <string> list_entity = new List <string>(i.Value.Keys); foreach (var j in list_entity) { EntityMgr.destroyEntity(j); } } map_children.Clear(); } // 销毁Entity上挂接的所有组件 ListComponent.Reverse(); foreach (var i in ListComponent) { //if (!EbTool.isNull(i)) { i.release(); i.Entity = null; i.EntityMgr = null; } } ListComponent.Clear(); mMapComponent.Clear(); //if (mPublisher != null) //{ // mPublisher.removeHandler(this); //} //if (mMapCacheData != null) //{ // mMapCacheData.Clear(); //} if (mMapChild != null) { mMapChild.Clear(); mMapChild = null; } // 从父Entity中移除 if (Parent != null) { Parent.removeChild(this); } Type = ""; Guid = ""; mParent = null; }