private void InitAssetBundleDependencies() { foreach (var assetBundleData in _assetBundleDataDic.Values) { if (assetBundleData.Dependencies == null) { assetBundleData.DependencyDatas = null; continue; } var dependencyIds = assetBundleData.Dependencies; var dependencyDatas = new List <AssetBundleData> (dependencyIds.Count); foreach (var dependencyId in dependencyIds) { var dependencyData = GetAssetBundleData(dependencyId); if (dependencyData == null) { ResourceDebug.Log("{0}->GetDependencyDatas: can NOT found dependency data [{1}] for asset bundle [{2}]!", GetType().Name, dependencyId, assetBundleData.Id); continue; } dependencyDatas.Add(dependencyData); } assetBundleData.DependencyDatas = dependencyDatas; } }
private static List <AssetBundleData> GetAssetBundleDependenceDatas(AssetBundleData assetBundleData) { var dependencyDatas = new List <AssetBundleData> (); foreach (var dependency in assetBundleData.Dependencies) { var dependencyData = GetAssetBundleData(dependency); if (dependencyData == null) { ResourceDebug.Log("ResourceManager->GetAssetBundleDependenceDatas: assetBundle data [{0}]: dependency data [{1}] NOT found.", assetBundleData.Id, dependency); continue; } var depthDependencyDatas = GetAssetBundleDependenceDatas(dependencyData); if (depthDependencyDatas.Count > 0) { dependencyDatas.AddRange(depthDependencyDatas); } dependencyDatas.Add(dependencyData); } return(dependencyDatas); }
protected override void InitMainRequest() { _mainOdrRequest = ResourceODRLocation.PreloadAsync(new[] { _odrTag }); _mainOdrRequest.OnCompleted += OnODRRequestCompleted; ResourceDebug.Log("{0}->InitMainRequest: odrTag [{1}]", GetType().Name, _odrTag); }
protected override bool LoadTick() { if (_currRequest == null) { return(true); } if (_currRequest.MoveNext()) { ResourceDebug.Log("{0}->LoadTick: index [{1}] - progress [{2}]", GetType().Name, _currProviderIndex, _currRequest.Progress); return(false); } ResourceDebug.Log("{0}->LoadTick: finish index [{1}]: - progress [{2}], error [{3}]", GetType().Name, _currProviderIndex, _currRequest.Progress, _currRequest.Error); // end current if (!string.IsNullOrEmpty(_currRequest.Error)) { Error = string.Format("{0}{1}: error [{2}].\n", Error, _currProviderIndex, _currRequest.Error); } // move next _currRequest = ProvideNextRequest(); return(false); }
protected override bool LoadFinish() { Asset = MainLoadFinish(); ReferenceDependencies(); ResourceDebug.Log("{0}->LoadFinish: name [{1}], finished [{2}]", GetType().Name, _holder.Name, Asset != null); return(Asset != null); }
public bool MoveNext() { if (!LoadTick()) { return(true); } IsDone = true; var result = LoadFinish(); if (!result && string.IsNullOrEmpty(Error)) { Error = "load finish [failed]."; } ResourceDebug.Log("{0}->MoveNext: load finish: error [{1}]", GetType().Name, Error); if (_onCompleted != null) { _onCompleted(this); } return(false); }
private void InitDataDic() { _locationDataDic.Clear(); _assetBundleDataDic.Clear(); _resourceDataDic.Clear(); _sceneDataDic.Clear(); foreach (var locationData in LocationDatas) { if (_locationDataDic.ContainsKey(locationData.Id)) { ResourceDebug.Log("{0}->InitData: location [{1}] duplicated !", GetType().Name, locationData.Id); continue; } _locationDataDic.Add(locationData.Id, locationData); // collect asset bundle data foreach (var assetBundleData in locationData.AssetBundleDatas) { if (_assetBundleDataDic.ContainsKey(assetBundleData.Id)) { ResourceDebug.Log("{0}->InitData: asset bundle [{1}] duplicated !", GetType().Name, assetBundleData.Id); continue; } assetBundleData.InLocation = locationData; _assetBundleDataDic.Add(assetBundleData.Id, assetBundleData); // collect resource data foreach (var resourceData in assetBundleData.ResourceDatas) { var key = GetResourceKey(resourceData.Path, resourceData.Type); if (_resourceDataDic.ContainsKey(key)) { ResourceDebug.Log("{0}->InitData: resource [{1}({2})] duplicated !", GetType().Name, key, assetBundleData.Id); continue; } resourceData.InAssetBundle = assetBundleData; _resourceDataDic.Add(key, resourceData); } // collect scene data foreach (var sceneData in assetBundleData.SceneDatas) { if (_sceneDataDic.ContainsKey(sceneData.SceneName)) { ResourceDebug.Log("{0}->InitData: scene [{1}({2})] duplicated !", GetType().Name, sceneData.SceneName, assetBundleData.Id); continue; } sceneData.InAssetBundle = assetBundleData; _sceneDataDic.Add(sceneData.SceneName, sceneData); } } } }
private static void OnVirtualTagsDownloadFinish(string[] tags) { foreach (var tag in tags) { ResourceDebug.Log("ResourceODRLocation->OnVirtualTagsDownloadFinish: [{0}]", tag); _downloadedVirtualTags.Add(tag); } }
private void MainDispose() { if (_mainOdrRequest == null) { return; } _mainOdrRequest.Dispose(); ResourceDebug.Log("{0}->MainDispose: odrTag [{1}] dispose", GetType().Name, _odrTag); }
protected override void MainAbort() { if (_mainOdrRequest == null) { return; } _mainOdrRequest.OnCompleted -= OnODRRequestCompleted; _mainOdrRequest.Dispose(); ResourceDebug.Log("{0}->MainAbort: odrTag [{1}] dispose", GetType().Name, _odrTag); }
protected override AssetBundle MainLoadFinish() { if (_mainResRequest == null) { return(null); } ResourceDebug.Log("{0}->MainLoadFinish: odrTag [{1}] isDone [{2}], name [{3}]", GetType().Name, _odrTag, _mainResRequest.isDone, _mainResRequest.assetBundle != null ? _mainResRequest.assetBundle.name : "null"); return(_mainResRequest.assetBundle); }
public void Reference() { if (Entity == null) { return; } ReferenceCount++; ResourceDebug.Log("{0}->Reference: [{1}] count ({2})", GetType().Name, Name, ReferenceCount); }
protected override bool LoadFinish() { ResourceDebug.Log("{0}->LoadFinish: odr {1}", GetType().Name, _odrTag); if (string.IsNullOrEmpty(_odrRequest.Error)) { return(true); } Error = _odrRequest.Error; return(false); }
public TRequest LoadAsync(TData data) { var holder = GetOrCreateHolder(data); if (holder == null) { ResourceDebug.Log("{0}->Load: holder [{1}({2})] NOT be supported.", GetType().Name, data.Id, data.GetType().Name); return(null); } return(holder.LoadAsync()); }
public static AssetBundleLoadRequest LoadAssetBundleAsync(string assetBundleId) { var data = GetAssetBundleData(assetBundleId); if (data == null) { ResourceDebug.Log("ResourceManager->LoadAssetBundleAsync: assetBundle data [{0}] NOT be configured.", assetBundleId); return(null); } return(_assetBundleUnit.LoadAsync(data)); }
public static void UnloadAssetBundle(string assetBundleId) { var data = GetAssetBundleData(assetBundleId); if (data == null) { ResourceDebug.Log("ResourceManager->UnloadAssetBundle: assetBundle data [{0}] NOT exists.", assetBundleId); return; } _assetBundleUnit.Unload(data); }
public static LocationLoadRequest LoadLocationAsync(string locationId) { var data = GetLocationData(locationId); if (data == null) { ResourceDebug.Log("ResourceManager->LoadLocation: location data [{0}] NOT be configured.", locationId); return(null); } return(_locationUnit.LoadAsync(data)); }
public void Unload(TData data) { var holder = GetOrCreateHolder(data); if (holder == null) { ResourceDebug.Log("{0}->Unload: holder [{1}({2})] NOT be supported.", GetType().Name, data.Id, data.GetType().Name); return; } holder.Unload(); }
protected override AssetBundleHolder CreateHolder(AssetBundleData data) { var locationHolder = ResourceManager.GetLoadedLocationHolder(data.InLocation.Id); if (locationHolder == null) { ResourceDebug.Log("{0}->CreateHolder: can NOT create asset bundle holder because location [{1}] not be loaded.", GetType().Name, data.InLocation.Id); return(null); } var dependencies = GetDependencies(data.DependencyDatas); return(new AssetBundleHolder(data.Id, dependencies, locationHolder)); }
public override AssetBundleLoadRequest LoadAssetBundleAsync(AssetBundleHolder assetBundleHolder) { var path = GetAssetBundleResourcePath(assetBundleHolder.Name); var request = new AssetBundleODRLoadRequest(assetBundleHolder, path, _odrTag); request.OnCompleted += loadRequest => { ResourceDebug.Log("{0}->LoadAssetBundleAsync: request finish: name {1}, same {2}, done {3}, path {4}", GetType().Name, assetBundleHolder.Name, loadRequest == request, request.IsDone, path); if (loadRequest == request) { assetBundleHolder.OnUnload += () => request.Dispose(); } }; return(request); }
private static string[] CollectUnDownloadedVirtualTags(string[] tags) { var virtualTags = new List <string> (tags.Length); foreach (var tag in tags) { if (_downloadedVirtualTags.Contains(tag)) { continue; } virtualTags.Add(tag); ResourceDebug.Log("ResourceODRLocation->CollectUnDownloadedVirtualTags: [{0}]", tag); } return(virtualTags.ToArray()); }
protected THolder GetOrCreateHolder(TData data) { if (_loadHolderDic.ContainsKey(data.Id)) { return(_loadHolderDic [data.Id]); } var holder = CreateHolder(data); if (holder == null) { ResourceDebug.Log("{0}->GetOrCreateHolder: holder [{1}({2})] NOT be supported.", GetType().Name, data.Id, data.GetType().Name); return(null); } _loadHolderDic.Add(data.Id, holder); return(holder); }
public THolder GetLoadedHolder(string id) { if (!_loadHolderDic.ContainsKey(id)) { ResourceDebug.Log("{0}->GetLoadedHolder: holder [{1}] not be created.", GetType().Name, id); return(null); } var holder = _loadHolderDic [id]; if (!holder.IsLoaded) { ResourceDebug.Log("{0}->GetLoadedHolder: holder [{1}] not be loaded.", GetType().Name, id); return(null); } return(holder); }
public THolder Load(TData data) { var holder = GetOrCreateHolder(data); if (holder == null) { return(null); } var result = holder.Load(); if (!result) { ResourceDebug.Log("{0}->Load: holder [{1}({2})] load failed.", GetType().Name, data.Id, data.GetType().Name); } return(holder); }
private LoadRequest ProvideNextRequest() { _currProviderIndex++; for (; _currProviderIndex < _providers.Count; _currProviderIndex++) { var request = _provideFunc(_providers [_currProviderIndex]); if (request != null) { return(request); } ResourceDebug.Log("{0}-ProvideNextRequest: get null request from provider [{1}], maybe already loaded, skipped ...", GetType().Name, _currProviderIndex); } ResourceDebug.Log("{0}-ProvideNextRequest: all requests be provided.", GetType().Name); return(null); }
public static AsyncOperation LoadSceneAsync(string sceneName, LoadSceneMode mode = LoadSceneMode.Single) { var data = GetSceneData(sceneName); if (data == null) { return(SceneManager.LoadSceneAsync(sceneName, mode)); } var assetBundleHolder = GetLoadedAssetBundleHolder(data.InAssetBundle.Id); if (assetBundleHolder == null) { ResourceDebug.Log("ResourceManager->LoadSceneAsync: can NOT load because the asset bundle [{0}] not loaded.", data.InAssetBundle.Id); return(null); } return(SceneManager.LoadSceneAsync(sceneName, mode)); }
public static Object Load(string path, System.Type type) { var data = GetResourceData(path, type); if (data == null) { return(Resources.Load(path, type)); } var assetBundleHolder = GetLoadedAssetBundleHolder(data.InAssetBundle.Id); if (assetBundleHolder == null) { ResourceDebug.Log("ResourceManager->Load: can NOT load because the asset bundle [{0}] not loaded.", data.InAssetBundle.Id); return(null); } var assetName = Path.GetFileName(path); return(assetBundleHolder.Entity.LoadAsset(assetName, type)); }
public static ResourceLoadRequest LoadAsync(string path, System.Type type) { var data = GetResourceData(path, type); if (data == null) { return(new ResourceDefaultLoadRequest(path, type)); } var assetBundleHolder = GetLoadedAssetBundleHolder(data.InAssetBundle.Id); if (assetBundleHolder == null) { ResourceDebug.Log("ResourceManager->LoadAsync: can NOT load because the asset bundle [{0}] not loaded.", data.InAssetBundle.Id); return(null); } var assetName = Path.GetFileName(path); return(new ResourceInAssetBundleLoadRequest(assetName, type, assetBundleHolder.Entity)); }
private void OnODRRequestCompleted(LoadRequest loadRequest) { if (loadRequest != _mainOdrRequest) { return; } ResourceDebug.Log("{0}->OnODRRequestCompleted: isDone [{1}], error [{2}]", GetType().Name, _mainOdrRequest.IsDone, _mainOdrRequest.Error); _mainOdrRequest.OnCompleted -= OnODRRequestCompleted; if (!string.IsNullOrEmpty(_mainOdrRequest.Error)) { Error = _mainOdrRequest.Error; return; } ResourceDebug.Log("{0}->OnODRRequestCompleted: LoadFromFileAsync [{1}]", GetType().Name, _resPath); _mainResRequest = AssetBundle.LoadFromFileAsync(_resPath); }
public bool Load() { if (IsLoaded) { return(true); } if (IsLoading) { ResourceDebug.Log("{0}->Load: async request is loading. ", GetType().Name); return(false); } if (!IsSyncLoadSupported) { ResourceDebug.Log("{0}->Load: synchronous load is NOT supported. ", GetType().Name); return(false); } IsLoaded = LoadProcess(); return(IsLoaded); }