Пример #1
0
        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("[AssetManage]Load Asset with no info");
            }
        }
Пример #2
0
 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);
         }
         if (m_Request.data != null)
         {
             Complete();
         }
         else
         {
             Error();
         }
     }
     else
     {
         Error();
     }
 }
Пример #3
0
        public AssetReference LoadAssetSync(string path, int 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_ON
                Debug.Log("[AssetManage]LoadAssetSync asset is loaded " + path + "," + Time.frameCount);
#endif
                ar = m_Assets[path];

                //refresh
                ar.AddTag(tag);

                //cache asset
                ar.Cache();
            }
            else
            {
                if (m_LoadingAssetLoaders.ContainsKey(path))
                {
#if ASSETMANAGER_LOG_ON
                    Debug.Log("[AssetManage]LoadAssetSync async load staring " + path + "," + Time.frameCount);
#endif
                    //TODO Stop async loader
                    return(null);
                }
                else
                {
#if ASSETMANAGER_LOG_ON
                    Debug.Log("[AssetManage]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;
                OnAssetBeforeLoaded(loader);
                OnAssetAfterLoaded(loader);
            }

            return(ar);
        }
Пример #4
0
        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;
        }
Пример #5
0
        void LoadFromAssetBundle()
        {
            if (info != null)
            {
#if SUPPORT_ASSET_ALIAS
                string assetName = info.aliasName;
#else
                string assetName = AssetPaths.AddAssetPrev(info.fullName);
#endif
#if ASSETMANAGER_LOG_ON
                Debug.LogFormat("[AssetManage]Load asset {0}", assetName);
#endif

                m_Request             = RequestManager.CreateAssetLoaderRequest(assetBundleReference.assetBundle, assetName, type);
                m_Request.onComplete += OnRequestComplete;
                assetManager.requestManager.ActiveRequest(m_Request);
            }
            else
            {
                Debug.LogError("[AssetManage]Load Asset with no info");
                Error();
            }
        }
Пример #6
0
        /// <summary>
        /// 资源加载
        /// 资源加载完成,返回一个关于资源的refrence,记录资源的使用情况。
        /// 资源使用的三种方式:
        ///     1.Retain(),使用完成时需要执行Release()。
        ///     2.Retain(Object),使用完成时可以不用执行Release(Object),等待UnloadUnuseds清理。
        ///     3.Monitor(GameObject),当GameObject被删除时,会自动执行Release(Object)。
        /// 对于手动删除资源最好执行RemoveAsset。
        /// 同一个资源只有一个正在加载的loader。由Manager负责管理Loader。
        /// </summary>
        /// <param name="path"></param>
        /// <param name="tag"></param>
        /// <param name="type"></param>
        /// <param name="completeHandle"></param>
        /// <returns></returns>
        public AssetLoader LoadAsset(string path, int tag, Type type, Action <AssetReference> completeHandle = null, bool autoReleaseBundle = true, bool autoStart = true)
        {
            AssetLoader loader = null;

            if (!string.IsNullOrEmpty(path))
            {
                path = AssetPaths.AddAssetPrev(path);
            }
            else
            {
                if (completeHandle != null)
                {
                    completeHandle(null);
                }
                return(loader);
            }


            if (m_Assets.ContainsKey(path))
            {
#if ASSETMANAGER_LOG_ON
                Debug.Log("[AssetManage]LoadAsset asset is loaded " + path + "," + Time.frameCount);
#endif
                AssetReference ar = m_Assets[path];

                //refresh
                ar.AddTag(tag);

                //cache asset
                ar.Cache();

                loader           = m_LoaderManager.CreateAssetAsyncLoader(path);
                loader.forceDone = true;
                loader.result    = ar;

                if (completeHandle != null)
                {
                    loader.onComplete += completeHandle;
                }

                loader.onAfterComplete += OnAssetAfterLoaded;
                loader.state            = Loader.State.Completed;
                if (autoStart)
                {
                    m_LoaderManager.ActiveLoader(loader);
                }
            }
            else
            {
                if (m_LoadingAssetLoaders.ContainsKey(path))
                {
#if ASSETMANAGER_LOG_ON
                    Debug.Log("[AssetManage]LoadAsset using loading loader " + path + "," + Time.frameCount);
#endif
                    loader = m_LoadingAssetLoaders[path];
                }
                else
                {
#if ASSETMANAGER_LOG_ON
                    Debug.Log("[AssetManage]LoadAsset create new loader " + path + "," + Time.frameCount);
#endif
                    loader = m_LoaderManager.CreateAssetAsyncLoader(path);
                    m_LoadingAssetLoaders[path] = loader;
                }

                loader.AddParamTag(tag);

                if (type != null)
                {
                    loader.type = type;
                }

                if (!autoReleaseBundle)
                {
                    loader.autoReleaseBundle = autoReleaseBundle;
                }

                if (completeHandle != null)
                {
                    loader.onComplete += completeHandle;
                }

                loader.IncreaseLoadingRequest();

                //only once init
                if (loader.state == Loader.State.Idle)
                {
                    loader.onBeforeComplete += OnAssetBeforeLoaded;
                    loader.onAfterComplete  += OnAssetAfterLoaded;
                    loader.state             = Loader.State.Inited;
                    if (autoStart)
                    {
                        m_LoaderManager.ActiveLoader(loader);
                    }
                }
            }

            return(loader);
        }