Exemple #1
0
        /// <summary>
        /// 释放引用的指定资源
        /// </summary>
        /// <param name="url_"></param>
        /// <param name="refer_"></param>
        public void ReleaseByUrl(object refer_, string url_)
        {
            url_ = url_.ToLower();
            if (!m_url2data.ContainsKey(url_))
            {
                return;
            }

            AssetData data = m_url2data[url_];

            if (data.Release(refer_))
            {
                data.active_time = DateUtil.TimeFromStart;  //刷新时间
            }

            //DetachBy_Type_Refer(url_, refer_)
        }
Exemple #2
0
        IEnumerator __LoadAsync(string url_)
        {
            ResourceRequest req;

            if (m_url2req.ContainsKey(url_))
            {
                Log.Assert("[LoadAsync] 错误的启动: " + url_, this);
                req = m_url2req[url_];
            }
            else
            {
                req = Resources.LoadAsync(url_);
            }

            m_url2req[url_] = req;
            Log.Info("☆ load async start: " + url_, this);

            while (!req.isDone)
            {
                yield return(0);
                //yield return new WaitForEndOfFrame();
            }

            if (req.asset)
            {
                OnAssetLoaded(url_, req.asset);
            }

            AssetData data = GetData(url_);

            if (data != null)
            {
                if (req.asset)
                {
                    AddAsset(url_, req.asset);

                    Log.Info("★ load async success: " + url_, this);

                    Notify(url_, data);                     //这里实际上是调用完成回调
                    //Notify(RES_EVT.LOAD_COMPLETE, data);    //派发完成事件
                    LuaEvtCenter.AddEvent(RES_EVT.LOAD_COMPLETE, data);
                }
                else
                {
                    Log.Assert("x 异步加载失败: " + url_, this);
                    //Notify(url_, data);                     //加载失败了, 也会调用完成回调
                    // Notify(RES_EVT.LOAD_EXCEPTION, url_);   //派发异常事件
                    LuaEvtCenter.AddEvent(RES_EVT.LOAD_EXCEPTION, url_);
                }

                data.Release(this); //释放之前的引用
            }
            else
            {
                Log.Warn("加载完成但data已被卸载:" + url_, this);
                if (req.asset)
                {
                    UnloadAsset(url_, req.asset);
                }
                //Notify(RES_EVT.LOAD_EXCEPTION, url_);   //派发异常事件
                LuaEvtCenter.AddEvent(RES_EVT.LOAD_EXCEPTION, url_);
            }

            m_url2req.Remove(url_);
            DetachByType(url_); //移除所有完成回调
        }