private AssetBundleCreateRequest CreateBundleLoadRequest() { Logger.LogInfo("Bundle load request does not exist, create it from file: {0}", _path); foreach (var basePath in _searchPaths) { var path = PathUtility.Combine(basePath, _path); // Avoid throwing error messages. if (PathUtility.IsFileInPersistentDataPath(path) && !File.Exists(path)) { Logger.LogInfo("AssetBundle cannot load at path: {0}, searching next ... ", path); continue; } Profiler.BeginSample("BundleLoaderAsync:CreateBuiltinBundleLoadRequest - AssetBundle.LoadFromFileAsync"); var bundleLoadRequest = LoadAssetBundleAsync(path); Profiler.EndSample(); if (bundleLoadRequest != null) { return(bundleLoadRequest); } Logger.LogInfo("AssetBundle cannot load at path: {0}, searching next ... ", path); } throw new BundleLoadFailedException(string.Format("Cannot load assetbundle: {0}", this)); }
public void RetainRef <TSetter>(AssetBase asset) { if (null == _typedAssets) { _typedAssets = DictionaryPool <Type, AssetBase> .Get(); } var type = typeof(TSetter); if (_typedAssets.ContainsKey(type)) { Logger.LogVerbose("BundlerMessenger::RetainRef<T>: {0}, Setter exist: {1}, release previous asset: {2}", this, type.FullName, _typedAssets[type].AssetPath); _typedAssets[type].Release(); Logger.LogVerbose("BundlerMessenger::RetainRef<T>: {0}, Setter exist: {1}, release previous asset: {2}, finished!", this, type.FullName, _typedAssets[type].AssetPath); } _typedAssets[type] = asset; Logger.LogVerbose("BundlerMessenger::RetainRef<T>: {0}, loader: {1}", this, asset.Loader); asset.Retain(); Logger.LogVerbose("BundlerMessenger::RetainRef<T>: {0}, loader: {1}, finished!", this, asset.Loader); Messengers.Add(this); }
public IEnumerator OnAsyncProcess() { if (_assetBundle) { yield break; } Profiler.BeginSample("BundleLoaderAsync:Await"); Logger.LogInfo("Bundle load async start: {0}", _path); if (_bundleLoadRequest == null) { _bundleLoadRequest = CreateBundleLoadRequest(); } yield return(_bundleLoadRequest); Logger.LogInfo("Bundle load request finished: {0}", _path); LoadAndCache(_bundleLoadRequest); Logger.LogInfo("AssetBundle asynchronously loading finished, path: {0}", _path); Profiler.EndSample(); }
public void ReleaseRef() { if (null != _assets) { foreach (var asset in _assets) { Logger.LogVerbose("BundlerMessenger::ReleaseRef: {0}, loader: {1}", this, asset.Loader); asset.Release(); Logger.LogVerbose("BundlerMessenger::ReleaseRef: {0}, loader: {1}, finished!", this, asset.Loader); } HashSetPool <AssetBase> .Return(_assets); } if (null != _typedAssets) { foreach (var kv in _typedAssets) { Logger.LogVerbose("BundlerMessenger::ReleaseRef: {0}, loader: {1}", this, kv.Value.Loader); kv.Value.Release(); Logger.LogVerbose("BundlerMessenger::ReleaseRef: {0}, loader: {1}, finished!", this, kv.Value.Loader); } DictionaryPool <Type, AssetBase> .Return(_typedAssets); } Messengers.Remove(this); }
private static IEnumerator ProcessAsync(IAsyncProcessor processor) { Logger.LogVerbose("ProcessAsync begin: {0}", processor); yield return(processor.OnAsyncProcess()); processor.ThreadHandle = 0; Logger.LogVerbose("ProcessAsync end: {0}", processor); }
protected override void OnLoadProcess() { Logger.LogInfo("Start asynchronously loading process: {0}", _path); IsLoading = true; AsyncRequestHelper.Setup(_context.CoroutinePool, this); }
public override void Release() { ReleaseDependencies(); base.Release(); Logger.LogVerbose("Release loader: {0}, ref: {1}", _path, _references); }
public override Object GetAsset() { if (null == _request) { _request = CreateLoadRequest(); } if (!IsDone) { Logger.LogError("Asset not loaded, force load complete: {0}", _path); } return(_request.asset); }
public static void Setup(CoroutinePool pool, IAsyncProcessor processor) { if (null == pool) { throw new ArgumentNullException("pool"); } if (processor.IsSetup) { throw new AsyncRequestAlreadySetupException("Async processor cannot setup twice!"); } processor.IsSetup = true; processor.ThreadHandle = pool.StartCoroutine(ProcessAsync(processor)); Logger.LogVerbose("Coroutine setup, processor: {0}, handle: {1}", processor, processor.ThreadHandle); }
public void ForceLoadComplete() { if (_assetBundle) { return; } Logger.LogInfo("Force load asset bundle: {0}", _path); if (null == _bundleLoadRequest) { Logger.LogInfo("Force load asset bundle, but load request not exist, create it: {0}", _path); _bundleLoadRequest = CreateBundleLoadRequest(); } LoadAndCache(_bundleLoadRequest); }
protected override void LoadAssetInternal() { Logger.LogInfo("Start asynchronously loading asset from bundle: {0}", _path); _request = CreateLoadRequest(); if (_request == null) { throw new BundleAssetLoadFailedException( string.Format("Cannot load asset {0} from bundle: {1}", GetAssetName(), _path)); } // Avoid releasing reference when loading assets. _loader.Retain(); AsyncRequestHelper.Setup(_context.CoroutinePool, this); }
public void ForceUnload() { Logger.LogVerbose("ForceUnload - {0}", this); if (_assetBundle) { _assetBundle.Unload(true); _assetBundle = null; } foreach (var loader in Dependencies) { loader.ForceUnload(); } ListPool <BundleLoaderBase> .Return(Dependencies); }
public IEnumerator OnAsyncProcess() { if (_request == null) { yield break; } IsStarted = true; yield return(_request); Logger.LogInfo("End asynchronously loading asset from bundle: {0}, object: {1}", _path, _request.asset); // Must release reference after assets loaded. _loader.Release(); IsDone = true; }
private void Awake() { _targetObject = gameObject; _targetName = name; if (!string.IsNullOrEmpty(_instanceId)) { if (!RecoverRefs()) { Logger.LogError("BundlerMessenger:Awake - Recover refs failed, see console output!"); } } _instanceId = GetInstanceID().ToString(); Logger.LogVerbose("BundlerMessenger::Awake: {0}", this); hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor; }
private bool RecoverRefs() { Logger.LogVerbose("BundlerMessenger::RecoverRefs: {0}", this); var clonedFromMessenger = FindMessengerInstance(_instanceId); if (!clonedFromMessenger) { Logger.LogError("BundlerMessenger::RecoverRefs: Messenger not found, instance id: {0}", _instanceId); return(false); } _assets = new HashSet <AssetBase>(); if (null != clonedFromMessenger._assets) { foreach (var asset in clonedFromMessenger._assets) { Logger.LogVerbose("BundlerMessenger::RecoverRefs: {0}, loader: {1}", this, asset.Loader); asset.Retain(); Logger.LogVerbose("BundlerMessenger::RecoverRefs: {0}, loader: {1}, finished!", this, asset.Loader); _assets.Add(asset); } } _typedAssets = new Dictionary <Type, AssetBase>(); if (null != clonedFromMessenger._typedAssets) { foreach (var kv in clonedFromMessenger._typedAssets) { Logger.LogVerbose("BundlerMessenger::RecoverRefs: {0}, loader: {1}", this, kv.Value.Loader); kv.Value.Retain(); Logger.LogVerbose("BundlerMessenger::RecoverRef: {0}, loader: {1}, finished", this, kv.Value.Loader); _typedAssets.Add(kv.Key, kv.Value); } } Logger.LogVerbose("BundlerMessenger::RecoverRef: {0}, finished!", this); Messengers.Add(this); return(true); }
protected override void OnLoadProcess() { Logger.LogInfo("Start synchronously loading process: {0}", _path); Profiler.BeginSample("BundleLoaderSync:LoadProcess"); foreach (var basePath in _searchPaths) { var path = PathUtility.Combine(basePath, _path); // Avoid throwing error messages. if (PathUtility.IsFileInPersistentDataPath(path) && !File.Exists(path)) { IsDone = false; Logger.LogInfo("AssetBundle cannot load at path: {0}, searching next ... ", path); continue; } Profiler.BeginSample("BundleLoader:LoadProcess - AssetBundle.LoadFromFile"); _assetBundle = LoadAssetBundle(path); Profiler.EndSample(); if (_assetBundle) { IsDone = true; Logger.LogInfo("AssetBundle synchronously loading finished, path: {0}", _path); break; } IsDone = false; Logger.LogInfo("AssetBundle cannot load at path: {0}, searching next ... ", path); } if (!IsDone) { throw new BundleNotFoundException( string.Format("AssetBundle synchronously loading failed: {0}", this)); } Logger.LogInfo("End synchronously loading process: {0}", _path); Profiler.EndSample(); }
public void RetainRef(AssetBase asset) { if (null == _assets) { _assets = HashSetPool <AssetBase> .Get(); } if (_assets.Contains(asset)) { return; } _assets.Add(asset); Logger.LogVerbose("BundlerMessenger::RetainRef: {0}, loader: {1}", this, asset.Loader); asset.Retain(); Logger.LogVerbose("BundlerMessenger::RetainRef: {0}, loader: {1}, finished!", this, asset.Loader); Messengers.Add(this); }
public void Unload() { Logger.LogInfo("Unload loader: {0}", this); if (_references > 0) { throw new BundleException( string.Format("Cannot unload, references: {0}, {1}", _references, this)); } if (_assetBundle) { _assetBundle.Unload(true); _assetBundle = null; } UnloadProcess(); IsDone = false; ListPool <BundleLoaderBase> .Return(Dependencies); }
private void Initialize(BundlerManifest manifest, BundlerOptions options) { Instance = this; _manifest = manifest; _coroutinePool = new CoroutinePool("Bundler", options.MaxAsyncUploadCount); _context = new BundlerContext { Options = options, CoroutinePool = _coroutinePool, }; _modes = new Dictionary <BundleModeType, ModeBase>(2); _modes[BundleModeType.Bundle] = new BundleMode(manifest, _searchPaths, _context); _modes[BundleModeType.Resource] = new ResourceMode(manifest, _searchPaths, _context); var bundleMode = true; var logLevel = Logger.LogLevel.ERROR; #if UNITY_EDITOR bundleMode = EditorPrefs.GetBool("vFrameBundlerModePreferenceKey", false); logLevel = EditorPrefs.GetInt("vFrameBundlerLogLevelPreferenceKey", Logger.LogLevel.ERROR - 1) + 1; #endif if (bundleMode) { if (manifest != null) { SetMode(BundleModeType.Bundle); return; } Logger.LogInfo("Bundle manifest does not provided, bundle mode will disable."); } SetMode(BundleModeType.Resource); SetLogLevel(logLevel); }
public GameObject InstantiateGameObject() { if (!IsDone) { throw new BundleAssetNotReadyException( string.Format("Asset not ready, path: {0}, loader: {1}", _path, _loader)); } var prefab = GetAsset() as GameObject; if (!prefab) { throw new BundleAssetTypeNotMatchException( string.Format("Asset not typeof GameObject, path: {0}, loader: {1}", _path, _loader)); } var go = Object.Instantiate(prefab); Logger.LogVerbose("Instantiate gameObject: {0}, from bundle: {1}", AssetPath, LoaderPath); SubscribeDestroyedMessenger(go); return(go); }
public void SetLogLevel(int level) { Logger.SetLogLevel(level); }
private void OnDestroy() { Logger.LogVerbose("BundlerMessenger::OnDestroy: {0}", this); ReleaseRef(); }