Ejemplo n.º 1
0
 public void Reset()
 {
     m_Callback    = null;
     m_ResCallback = null;
     m_ResObj      = null;
     param1        = null;
     param2        = null;
     param3        = null;
 }
Ejemplo n.º 2
0
    /// <summary>
    /// 异步加载(实例化)
    /// </summary>
    /// <param name="path"></param>
    /// <param name="resObj"></param>
    /// <param name="callback"></param>
    /// <param name="priority"></param>
    public void AsyncLoadResource(string path, ResourceObject resObj, AsyncResObjFinishCallback callback, ResLoadPriority priority)
    {
        if (m_StartCoroutine == null)
        {
            Debug.LogError("ResourceManager.AsyncLoadResource 协程未启动,无法使用异步加载");
            return;
        }
        WashOut();
        ResourceItem item = GetCacheResourceItem(resObj.m_Crc);

        //如果资源已经加载
        if (item != null)
        {
            resObj.m_ResItem = item;
            if (callback != null)
            {
                callback(path, resObj, resObj.param1, resObj.param2, resObj.param3);
            }
            return;
        }
        //判断是否正在加载
        AsyncLoadResParam asyncParam = null;

        if (!m_AsyncLoadDic.TryGetValue(resObj.m_Crc, out asyncParam))
        {
            //添加到正在加载
            asyncParam            = m_AsyncLoadResParamPool.Spawn(true);
            asyncParam.m_Crc      = resObj.m_Crc;
            asyncParam.m_Path     = path;
            asyncParam.m_Priority = priority;
            m_AsyncLoadDic.Add(resObj.m_Crc, asyncParam);
            m_AsyncLoadingList[(int)priority].Add(asyncParam);
        }
        //缓存回调信息
        AsyncCallback asyncCallback = m_AsyncCallbackPool.Spawn(true);

        asyncCallback.m_ResCallback = callback;
        asyncCallback.m_ResObj      = resObj;
        asyncParam.m_AsyncCallbackList.Add(asyncCallback);
        //异步加载在AsyncLoadCoroutine 里执行
    }