コード例 #1
0
        internal void GetAsset(string name, Action <string, UnityEngine.Object> callback, LoadPriority priority = LoadPriority.Default)
        {
            if (name == null || name == string.Empty)
            {
                return;
            }

            if (HasLoaded(name))
            {
                if (callback != null)
                {
                    GetAssetInCache(name, callback, priority);
                }
                return;
            }
#if UNITY_EDITOR
            UnityEngine.Object obj = LoadFromPrefab(name, typeof(UnityEngine.Object));
            if (obj != null)
            {
                SetAsset(name, obj).Reference = 1;
                UnityEngine.Object ins = AssetInfo.IsNeedInstance(obj, name) ? GameObject.Instantiate(obj) : obj;
                if (callback != null)
                {
                    callback(name, ins);
                }
                return;
            }
#endif
            string bundleName = ResourceMgr.GetBundleName(name);
            if (bundleName == string.Empty)
            {
                DebugUtil.LogError("can not find asset: " + name);
                return;
            }

            cacheMgr.AddCallbackToDic(name, callback);
            if (!cacheMgr.HasLoadingInfo(bundleName))
            {
                Resource res = this.GetDownloadResource(bundleName);
                if (res == null)
                {
                    res = this.CreateResource(bundleName, priority);
                    res.LoadRes();
                }
                if (res.InvalidBundle)
                {
                    res.InvalidBundle = false;
                }
                //逻辑加载时,提高优先级//
                if (res.Loader.Priority < priority)
                {
                    this.ResourceMgr.GOELoaderMgr.SetLoaderPriority(res.Loader, priority);
                }
            }
            else
            {
                cacheMgr.CheckAssetLoading(bundleName, name, priority);
            }
        }
コード例 #2
0
        internal ResourceState PreloadBundle(string bundleName, Action <string, AssetBundle> callback, LoadPriority priority = LoadPriority.Default, bool dependencyResource = false)
        {
            BundleInfo bundle = ResourceMgr.Instance().GetBundle(bundleName);

            if (bundle == null)
            {
                var bn = ResourceMgr.GetBundleName(bundleName);
                if (string.IsNullOrEmpty(bn))
                {
                    DebugUtil.LogError("Cannot find asset:" + bundleName);
                    return(ResourceState.Failed);
                }
                bundleName = bn;
            }
            var cb = cacheMgr.Cache[bundleName];

            if (cb != null)
            {
                if (callback != null)
                {
                    callback(bundleName, cb.AssetBundle);
                }
                return(ResourceState.OK);
            }
            Resource res = this.GetDownloadResource(bundleName);

            if (res == null)
            {
                if (!cacheMgr.HasLoadingInfo(bundleName))
                {
                    res = this.CreateResource(bundleName, priority);
                    res.DependencyResource = dependencyResource;
                    res.LoadRes();
                }
                cacheMgr.AddCallbackToDic(bundleName, callback);
            }
            else if (res.ResOK)
            {
                if (callback != null)
                {
                    callback(bundleName, res.Loader.AssetBundle);
                }
                return(ResourceState.OK);
            }
            else
            {
                cacheMgr.AddCallbackToDic(bundleName, callback);
                if (res.Loader.Priority < priority)
                {
                    this.ResourceMgr.GOELoaderMgr.SetLoaderPriority(res.Loader, priority);
                }
            }
            return(ResourceState.Wait);
        }
コード例 #3
0
        internal override bool RemoveAsset(string name, bool force = true, bool removeInBundleAsset = true)
        {
            string             bundleName     = ResourceMgr.GetBundleName(name);
            BundleInfoResource bundleResource = cacheMgr.Cache[bundleName];

            if (bundleResource != null)
            {
                return(bundleResource.RemoveAsset(name, force, removeInBundleAsset));
            }

            return(false);
        }
コード例 #4
0
        internal void EnsureDependencies(string name)
        {
            string bundleName = ResourceMgr.GetBundleName(name);

            if (!string.IsNullOrEmpty(bundleName))
            {
                BundleInfo bundle = ResourceMgr.GetBundle(bundleName);
                if (bundle != null)
                {
                    foreach (var dep in bundle.DependsOn)
                    {
                        BundleInfo depBundle = ResourceMgr.GetBundle(dep);
                        if (depBundle == null)
                        {
                            continue;
                        }
                        if (!HasLoaded(depBundle.FirstAsset))
                        {
                            ResourceModule.Instance.PreloadBundle(dep, null);
                        }
                    }
                }
            }
        }
コード例 #5
0
 public string GetBundleName(string assetname)
 {
     return(resourceMgr.GetBundleName(assetname));
 }
コード例 #6
0
        internal void GetAsset(string name, Action <string, UnityEngine.Object> callback, LoadPriority priority = LoadPriority.Default)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }


            if (HasLoaded(name))
            {
                if (callback != null)
                {
                    GetAssetInCache(name, callback, priority);
                }
                return;
            }

            /*
             #if UNITY_EDITOR
             *          UnityEngine.Object obj = LoadFromPrefab(name, typeof(UnityEngine.Object));
             *          if (obj != null)
             *          {
             *              SetAsset(name, obj).Reference = 1;z
             *              UnityEngine.Object ins = AssetInfo.IsNeedInstance(obj, name) ? GameObject.Instantiate(obj) : obj;
             *              if (callback != null)
             *                  callback(name, ins);
             *              return;
             *          }
             #endif*/
            string bundleName = ResourceMgr.GetBundleName(name);

            if (bundleName == string.Empty)
            {
                DebugUtil.LogError("can not find asset: " + name);
                callback?.Invoke(name, null);           //update: guangze song: 资源没找到时,回调正常调用,防止有的资源(LazyImageLoader)状态还在加载中
                return;
            }

            cacheMgr.AddCallbackToDic(name, callback);
            BundleInfoResource cachedBundleInfo = cacheMgr.Cache[bundleName];

            if (cachedBundleInfo != null)
            {
                cacheMgr.DoEnqueuePending(bundleName, LoadPriority.Default, cachedBundleInfo.AssetBundle);
            }
            else
            {
                if (!cacheMgr.HasLoadingInfo(bundleName))
                {
                    Resource res = this.GetDownloadResource(bundleName);
                    if (res == null)
                    {
                        res = this.CreateResource(bundleName, priority);
                        res.LoadRes();
                    }
                    if (res.InvalidBundle)
                    {
                        res.InvalidBundle = false;
                    }
                    //逻辑加载时,提高优先级//
                    if (res.Loader.Priority < priority)
                    {
                        this.ResourceMgr.GOELoaderMgr.SetLoaderPriority(res.Loader, priority);
                    }
                }
                else
                {
                    cacheMgr.CheckAssetLoading(bundleName, name, priority);
                }
            }
        }