public void StartPreload(NodeAddedEvent e, SingleNode <PreloadAllResourcesComponent> preload, [JoinAll] DataBaseNode db) { if (DiskCaching.Enabled) { AssetBundleDatabase assetBundleDatabase = db.assetBundleDatabase.AssetBundleDatabase; AssetBundleDiskCache assetBundleDiskCache = db.assetBundleDiskCache.AssetBundleDiskCache; List <string> prioritizedAssetsConfigPathList = GetPrioritizedAssetsConfigPathList(); int num = 100 + prioritizedAssetsConfigPathList.Count; List <string> list2 = new List <string>(); for (int i = 0; i < prioritizedAssetsConfigPathList.Count; i++) { AssetReferenceComponent assetReferenceComponent = AssetReferenceComponent.createFromConfig(prioritizedAssetsConfigPathList[i]); string assetGuid = assetReferenceComponent.Reference.AssetGuid; list2.Add(assetGuid); AssetBundleInfo assetBundleInfoByGuid = assetBundleDatabase.GetAssetBundleInfoByGuid(assetGuid); if (!assetBundleDiskCache.IsCached(assetBundleInfoByGuid)) { this.CreateEntityForPreloadingBundles(assetReferenceComponent, num - i); } } foreach (string str2 in assetBundleDatabase.GetRootGuids()) { AssetBundleInfo assetBundleInfoByGuid = assetBundleDatabase.GetAssetBundleInfoByGuid(str2); if (!list2.Contains(str2) && !assetBundleDiskCache.IsCached(assetBundleInfoByGuid)) { AssetReferenceComponent assetReferenceComponent = new AssetReferenceComponent(new AssetReference(str2)); this.CreateEntityForPreloadingBundles(assetReferenceComponent, 0); } } } }
public void LoadMultikillSound(NodeAddedEvent e, SingleNode <MultikillUIComponent> node) { if ((node.component.VoiceReference != null) && !string.IsNullOrEmpty(node.component.VoiceReference.AssetGuid)) { AssetReferenceComponent component = new AssetReferenceComponent(node.component.VoiceReference); node.Entity.AddComponent(component); node.Entity.AddComponent <AssetRequestComponent>(); } }
//对GameObject增加一个资源引用,GameObject被destroy的时候,会自动释放引用 public void ReferenceAssetWithGo(GameObject go, Object asset) { if (go == null) { return; } AssetReferenceComponent comp = TryGetAssetReferenceComponent(go); ReferenceAssetWithGo(comp, asset); }
public void LoadWarmingUpTimerNotificationSound(NodeAddedEvent e, WarmingUpTimerNotificationNode node) { AssetReference voiceReference = node.warmingUpTimerNotificationUI.VoiceReference; if ((voiceReference != null) && !string.IsNullOrEmpty(voiceReference.AssetGuid)) { AssetReferenceComponent component = new AssetReferenceComponent(voiceReference); node.Entity.AddComponent(component); node.Entity.AddComponent <AssetRequestComponent>(); } }
public void ReferenceAssetWithGo(AssetReferenceComponent comp, Object asset) { if (asset == null) { return; } if (comp != null && comp.AddReference(asset)) { //引用计数 +1 ReferenceAsset(asset); } }
private void CreateEntityForPreloadingBundles(AssetReferenceComponent assetReferenceComponent, int loadingPriority) { Entity entity = base.CreateEntity("PreloadBundles"); entity.AddComponent(assetReferenceComponent); entity.AddComponent <PreloadComponent>(); LoadAssetBundlesRequestComponent component = new LoadAssetBundlesRequestComponent { LoadingPriority = loadingPriority }; entity.AddComponent(component); }
public void Init(NodeAddedEvent e, SelfUserNode selfUser) { base.CreateEntity("MandatoryAssetsFirstLoading").AddComponent <MandatoryAssetsFirstLoadingComponent>(); foreach (string str in GetMandatoryAssetGUIDsFromConfig(selfUser.Entity.Id)) { AssetReferenceComponent component = new AssetReferenceComponent(new AssetReference(str)); Entity entity2 = base.CreateEntity("Loader " + str); entity2.AddComponent(component); entity2.AddComponent <PreloadComponent>(); entity2.AddComponent(new AssetRequestComponent(100)); } }
private AssetReferenceComponent TryGetAssetReferenceComponent(GameObject go) { if (go == null) { return(null); } AssetReferenceComponent comp = go.GetComponent <AssetReferenceComponent>(); if (comp == null) { comp = go.AddComponent <AssetReferenceComponent>(); } return(comp); }
public void ReferenceAssetsWithGo(GameObject go, List <Object> assets) { if (assets == null || go == null) { return; } AssetReferenceComponent comp = TryGetAssetReferenceComponent(go); foreach (var asset in assets) { if (asset != null) { ReferenceAssetWithGo(comp, asset); } } }
//将引用计数托管给GameObject public void ReferenceAssetsWithGo(GameObject go, LoadRequest request) { if (request == null || go == null) { return; } AssetReferenceComponent comp = TryGetAssetReferenceComponent(go); foreach (var task in request) { if (task.LoadedAsset != null) { ReferenceAssetWithGo(comp, task.LoadedAsset); } } }
//解掉这个资源的asset 引用 public void UnReferenceAssetWithGo(GameObject go, Object asset) { if (go == null) { return; } AssetReferenceComponent comp = go.GetComponent <AssetReferenceComponent>(); if (comp == null) { return; } if (comp.RemoveRef(asset)) { UnReferenceAsset(asset); } }