//void Awake() //{ // Init(); //} public void Init(Action <bool> callback = null) { Application.lowMemory += OnLowMemory; //add search paths AssetPaths.AddSearchPath(AssetPaths.Combine(Application.persistentDataPath, AssetPaths.bundlesPath)); #if UNITY_EDITOR //bunlde out path AssetPaths.AddSearchPath( AssetPaths.Combine( System.IO.Path.GetFullPath("."), AssetPaths.bundleOutPaths, UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString() ) ); #endif m_LoaderManager = new LoaderManager(this); m_RequestManager = new RequestManager(this); m_InfoManager = new InfoManager(this); if (callback != null) { m_InfoManager.onInitComplete += callback; } m_InfoManager.Load(AssetPaths.GetFullPath(AssetPaths.bundleManifestFile)); }
void LoadFromAssetBundle() { if (info != null) { #if SUPPORT_ASSET_ALIAS string assetName = info.aliasName; #else string assetName = AssetPaths.AddAssetPrev(info.fullName); #endif if (type == null) { asset = assetBundleReference.assetBundle.LoadAsset(assetName); } else { asset = assetBundleReference.assetBundle.LoadAsset(assetName, type); } Complete(); } else { Error(); Debug.LogError("Load Asset with no info"); } }
public AssetReference LoadAssetSync(string path, string tag, Type type) { if (!string.IsNullOrEmpty(path)) { path = AssetPaths.AddAssetPrev(path); } AssetReference ar = null; AssetLoader loader = null; if (m_Assets.ContainsKey(path)) { #if ASSETMANAGER_LOG Debug.Log("LoadAssetSync asset is loaded " + path + "," + Time.frameCount); #endif ar = m_Assets[path]; //refresh ar.AddTag(tag); //in chain will check is chained. ar.Chain(); } else { if (m_LoadingAssetLoaders.ContainsKey(path)) { #if ASSETMANAGER_LOG Debug.Log("LoadAssetSync async load staring " + path + "," + Time.frameCount); #endif //TODO Stop async loader return(null); } else { #if ASSETMANAGER_LOG Debug.Log("LoadAssetSync create new loader " + path + "," + Time.frameCount); #endif loader = m_LoaderManager.CreateAssetSyncLoader(path); } loader.AddParamTag(tag); if (type != null) { loader.type = type; } loader.state = Loader.State.Inited; loader.Start(); ar = loader.result; OnAssetLoaded(loader); } return(ar); }
void LoadBundle() { string assetPath = AssetPaths.GetFullPath(info.fullName); #if ASSETMANAGER_LOG Debug.Log("LoadBundle " + assetPath + "," + Time.frameCount); #endif LoadFromFileSync(assetPath); Complete(); }
void LoadFromResources() { if (info != null) { string resourcePath = Path.Combine(Path.GetDirectoryName(info.fullName), Path.GetFileNameWithoutExtension(info.fullName)); resourcePath = AssetPaths.RemoveAssetPrev(resourcePath); Request request = RequestManager.CreateResouceLoaderRequest(resourcePath, type); request.onComplete += OnRequestComplete; assetManager.requestManager.ActiveRequest(request); } else { Error(); Debug.LogError("Load Asset with no info"); } }
void LoadBundle() { string assetPath = AssetPaths.GetFullPath(info.fullName); #if ASSETMANAGER_LOG Debug.Log("LoadBundle " + assetPath + "," + Time.frameCount); #endif if (assetPath.Contains("://")) { LoadFromPackage(assetPath); } else { LoadFromFile(assetPath); } }
public AssetInfo FindAssetInfo(string key) { if (m_AssetInfos != null && !string.IsNullOrEmpty(key)) { if (m_AssetInfos.ContainsKey(key)) { return(m_AssetInfos[key]); } string fixKey = AssetPaths.AddAssetPrev(key); if (!fixKey.Equals(key)) { if (m_AssetInfos.ContainsKey(fixKey)) { return(m_AssetInfos[fixKey]); } } } return(null); }
void LoadFromResources() { if (info != null) { string resourcePath = Path.Combine(Path.GetDirectoryName(info.fullName), Path.GetFileNameWithoutExtension(info.fullName)); resourcePath = AssetPaths.RemoveAssetPrev(resourcePath); if (type == null) { asset = Resources.Load(resourcePath); } else { asset = Resources.Load(resourcePath, type); } Complete(); } else { Error(); Debug.LogError("Load Asset with no info"); } }
void LoadFromResources() { if (info != null) { string resPath = AssetPaths.AddAssetPrev(info.fullName); if (type == null) { m_Request = new SyncLoaderRequest(); m_Request.data = AssetDatabase.LoadMainAssetAtPath(resPath); } else { m_Request = new SyncLoaderRequest(); m_Request.data = AssetDatabase.LoadAssetAtPath(resPath, type); } Complete(); } else { Error(); } }
void LoadFromAssetBundle() { if (info != null) { #if SUPPORT_ASSET_ALIAS string assetName = info.aliasName; #else string assetName = AssetPaths.AddAssetPrev(info.fullName); #endif #if ASSETMANAGER_LOG Debug.LogFormat("Load asset {0}", assetName); #endif Request request = RequestManager.CreateAssetLoaderRequest(assetBundleReference.assetBundle, assetName, type); request.onComplete += OnRequestComplete; assetManager.requestManager.ActiveRequest(request); } else { Error(); Debug.LogError("Load Asset with no info"); } }
/// <summary> /// 资源加载 /// 资源加载完成,返回一个关于资源的refrence,记录资源的使用情况。 /// 资源使用的三种方式: /// 1.Retain(),使用完成时需要执行Release()。 /// 2.Retain(Object),使用完成时可以不用执行Release(Object),等待UnloadUnuseds清理。 /// 3.Monitor(GameObject),当GameObject被删除时,会自动执行Release(Object)。 /// 对于手动删除资源最好执行RemoveAsset。 /// </summary> /// <param name="path"></param> /// <param name="tag"></param> /// <param name="type"></param> /// <param name="completeHandle"></param> /// <returns></returns> public AssetLoader LoadAsset(string path, string tag, Type type, Action <AssetReference> completeHandle = null) { if (!string.IsNullOrEmpty(path)) { path = AssetPaths.AddAssetPrev(path); } AssetLoader loader = null; if (m_Assets.ContainsKey(path)) { #if ASSETMANAGER_LOG Debug.Log("LoadAsset asset is loaded " + path + "," + Time.frameCount); #endif AssetReference ar = m_Assets[path]; //refresh ar.AddTag(tag); //in chain will check is chained. ar.Chain(); loader = m_LoaderManager.CreateAssetAsyncLoader(path); loader.forceDone = true; loader.result = ar; if (completeHandle != null) { completeHandle(ar); } } else { if (m_LoadingAssetLoaders.ContainsKey(path)) { #if ASSETMANAGER_LOG Debug.Log("LoadAsset using loading loader " + path + "," + Time.frameCount); #endif loader = m_LoadingAssetLoaders[path]; } else { #if ASSETMANAGER_LOG Debug.Log("LoadAsset create new loader " + path + "," + Time.frameCount); #endif loader = m_LoaderManager.CreateAssetAsyncLoader(path); m_LoadingAssetLoaders[path] = loader; } loader.AddParamTag(tag); loader.onComplete += completeHandle; if (type != null) { loader.type = type; } if (loader.state == Loader.State.Idle) { loader.onAfterComplete += OnAssetLoaded; loader.state = Loader.State.Inited; m_LoaderManager.ActiveLoader(loader); } } return(loader); }