예제 #1
0
 public void Reset()
 {
     m_AsyncCallbackList.Clear();
     m_Crc      = 0;
     m_Path     = string.Empty;
     m_IsSprite = false;
     m_Priority = ResLoadPriority.RES_SLOW;
 }
예제 #2
0
    /// <summary>
    /// 异步加载创建实例
    /// </summary>
    /// <param name="path"></param>
    /// <param name="callback"></param>
    /// <param name="priority"></param>
    /// <param name="isSceneObj"></param>
    /// <param name="isClear"></param>
    /// <param name="param1"></param>
    /// <param name="param2"></param>
    /// <param name="param3"></param>
    /// <returns></returns>
    public long InstantiateObjectAsyn(string path, AsyncObjFinishCallback callback, ResLoadPriority priority,
                                      bool isSceneObj = false, bool isClear = true,
                                      object param1   = null, object param2 = null, object param3 = null)
    {
        if (string.IsNullOrEmpty(path))
        {
            return(0);
        }
        uint           crc    = Crc32.GetCrc32(path);
        ResourceObject resObj = GetObjectFromPool(crc);

        if (resObj != null)
        {
            if (isSceneObj)
            {
                resObj.m_CloneObj.transform.SetParent(SceneTrs);
            }
            if (callback != null)
            {
                callback(path, resObj.m_CloneObj, param1, param2, param3);
            }
            return(resObj.m_Guid);
        }
        long guid = m_AsynGuid;

        resObj              = m_ResourceObjectPool.Spawn(true);
        resObj.m_Crc        = crc;
        resObj.m_IsClear    = isClear;
        resObj.m_IsSceneObj = isSceneObj;
        resObj.m_Callback   = callback;
        resObj.m_Guid       = guid;
        resObj.param1       = param1;
        resObj.param2       = param2;
        resObj.param3       = param3;
        ResourceManager.Instance.AsyncLoadResource(path, resObj, OnResObjFinish, priority);
        m_AsynLoadingDic.Add(guid, resObj);
        return(guid);
    }
예제 #3
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 里执行
    }
예제 #4
0
    /// <summary>
    /// 异步加载资源(普通的)
    /// </summary>
    /// <param name="path"></param>
    /// <param name="callback"></param>
    /// <param name="priority"></param>
    /// <param name="param1"></param>
    /// <param name="param2"></param>
    /// <param name="param3"></param>
    public void AsyncLoadResource(string path, AsyncObjFinishCallback callback, bool isSprite = false, object param1 = null, object param2 = null, object param3 = null, ResLoadPriority priority = ResLoadPriority.RES_NORMAL)
    {
        if (m_StartCoroutine == null)
        {
            Debug.LogError("ResourceManager.AsyncLoadResource 协程未启动,无法使用异步加载");
            return;
        }
        WashOut();
        uint         crc  = Crc32.GetCrc32(path);
        ResourceItem item = GetCacheResourceItem(crc);

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

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

        asyncCallback.m_Callback = callback;
        asyncCallback.param1     = param1;
        asyncCallback.param2     = param2;
        asyncCallback.param3     = param3;
        asyncParam.m_AsyncCallbackList.Add(asyncCallback);
        //异步加载在AsyncLoadCoroutine 里执行
    }