コード例 #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("Load Asset with no info");
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
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);
        }
コード例 #4
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);
         }
         Complete();
     }
     else
     {
         Error();
     }
 }
コード例 #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
                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");
            }
        }
コード例 #6
0
        /// <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);
        }