Exemplo n.º 1
0
 protected void Dispose(bool value)
 {
     if (this.m_isDispose)
     {
         return;
     }
     if (value || this.m_assetCollectDepResource != null)
     {
         Debug.Log("AssetRequest Dispose");
         this.m_assetCollectDepResource.RemoveAssetRequest(this);
         this.m_assetCollectDepResource = null;
         this.handler = null;
     }
     this.m_isDispose = true;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 构造函数,初始化需要下载的资源和下载完成之后的委托回调
        /// </summary>
        /// <param name="assetCollectDepResource"></param>
        /// <param name="handler"></param>
        public LocalAssetRequest(IAssetCollectDepResource assetCollectDepResource, AssetRequestFinishedEventHandler handler)
        {
            LocalAssetCollectDepResource colldepResource = assetCollectDepResource as LocalAssetCollectDepResource;

            if (colldepResource == null || colldepResource.GetAssetResource() == null)
            {
                this.m_isErroe = true;
                return;
            }
            this.handler = handler;
            this.m_assetCollectDepResource = colldepResource;
            this.m_assetCollectDepResource.AddAssetRequest(this);
            if (handler != null && this.m_assetCollectDepResource.HasCallBack())
            {
                LocalResourceManager.GetInstance().StartCoroutine(this.DelayCallBack(handler, this));
            }
        }
        public IAssetRequest CreateAssetRequest(ResourceData resourceData, List <ResourceData> depResourceList, AssetRequestFinishedEventHandler callback, AssetPRI assetPRI)
        {
            if (resourceData == null)
            {
                return(null);
            }
            AssetLogger.Debug("CreateAssetRequest:" + resourceData.mResourceName);
            if (string.IsNullOrEmpty(resourceData.mPath))
            {
                return(null);
            }
            LocalAssetCollectDepResource depResource = null;

            if (this.m_dicAssetCollectDepResource.TryGetValue(resourceData.mPath, out depResource))
            {
                return(new LocalAssetRequest(depResource, callback));
            }
            depResource     = LocalAssetCollectDepResource.Create();
            depResource.URL = resourceData.mPath;
            this.m_dicAssetCollectDepResource.Add(depResource.URL, depResource);
            if (depResourceList != null)
            {
                depResource.SetDepSize(depResourceList.Count);//初始化depAssetResource[],引用资源的数组
                for (int i = 0; i < depResourceList.Count; i++)
                {
                    ResourceData resourceData2 = depResourceList[i];
                    Debug.Log(resourceData2.mResourceName);
                    LocalAssetResource assetResource = this.CreateAssetResource(resourceData2, new AssetLoadFinishedEventHandler(depResource.AssetComplete), assetPRI);
                    depResource.AddDep(assetResource, i);//赋值depAssetResource[]
                    Debug.Log(assetResource == null);
                }
            }
            LocalAssetResource asset = this.CreateAssetResource(resourceData, new AssetLoadFinishedEventHandler(depResource.AssetComplete), assetPRI);

            depResource.SetAsset(asset);
            depResource.EndCreate();
            return(new LocalAssetRequest(depResource, callback));
        }
        /// <summary>
        /// 释放没用的资源
        /// </summary>
        /// <returns></returns>
        private bool UnLoadNotUsedResource()
        {
            bool          result = false;
            List <string> list   = new List <string>();

            foreach (var current in this.m_dicAssetResoure)
            {
                //如果资源被引用的次数为0,就加入到需要被卸载的列表内
                if (0 >= current.Value.RefCount)
                {
                    Debug.Log("UnloadADd:" + current.Key);
                    list.Add(current.Key);
                }
            }
            //遍历所有需要卸载的列表,释放资源
            for (int i = 0; i < list.Count; i++)
            {
                string             key           = list[i];
                LocalAssetResource assetResource = null;
                if (this.m_dicAssetResoure.TryGetValue(key, out assetResource))
                {
                    if (assetResource != null)
                    {
                        Debug.Log("dispose" + assetResource.URL);
                        assetResource.Dispose();
                        result = true;
                    }
                    this.m_dicAssetResoure.Remove(key);
                }
            }
            bool          flag  = false;
            List <string> list2 = new List <string>();

            foreach (var current2 in this.m_dicAssetCollectDepResource)
            {
                if (0 >= current2.Value.RefCount)
                {
                    if (!flag)
                    {
                        list2.Add(current2.Key);
                        flag = true;
                    }
                    else
                    {
                        if (current2.Value.GetRemoveQuickly())
                        {
                            list2.Add(current2.Key);
                        }
                    }
                }
            }
            for (int j = 0; j < list2.Count; j++)
            {
                string key2 = list2[j];
                LocalAssetCollectDepResource assetCollectDepResource = null;
                if (this.m_dicAssetCollectDepResource.TryGetValue(key2, out assetCollectDepResource))
                {
                    if (assetCollectDepResource != null)
                    {
                        Debug.Log("Unload:" + assetCollectDepResource.URL);
                        assetCollectDepResource.Dispose();
                        result = true;
                    }
                    this.m_dicAssetCollectDepResource.Remove(key2);
                }
            }
            return(result);
        }