//private void LoadQueue()
    //{
    //    if (currentNum >= count)
    //    {
    //        RunCallBack();
    //        Destroy();
    //        return;
    //    }
    //    PreloadResourcesDataGenerate da = queueRes[currentNum];
    //    currentNum++;
    //    //Debug.Log("da.m_key " + da.m_key);
    //    try
    //    {
    //        string typeStr = da.m_ResType.ToString().Replace("_", ".");
    //        Type resType= ReflectionUtils.GetTypeByTypeFullName(typeStr);

    //        //  object loadRes = ResourceManager.Load(da.m_key);
    //        ResourceManager.LoadAsync(da.m_key, resType, (LoadState loadState, object loadRes) =>
    //         {
    //         if (loadState.isDone)
    //         {

    //             if (loadRes != null )
    //                {
    //                    if (loadRes is GameObject )
    //                    {
    //                        GameObject prefab = (GameObject)loadRes;
    //                        List<GameObject> resList = new List<GameObject>();
    //                        for (int i = 0; i < da.m_instantiateNum; i++)
    //                        {
    //                            GameObject obj = GameObjectManager.CreateGameObjectByPool(prefab);
    //                            resList.Add(obj);

    //                        }
    //                        foreach (var obj in resList)
    //                        {
    //                            GameObjectManager.DestroyGameObjectByPool(obj, !da.m_createInstanceActive);
    //                        }
    //                    }
    //                    else
    //                    {
    //                        ResourceManager.DestroyByPool(da.m_key);
    //                    }
    //                }
    //                else
    //                {
    //                    if (loadRes == null)
    //                    {
    //                        Debug.LogError("Error: 预加载失败  key:" + da.m_key);
    //                    }
    //                }
    //                RunCallBack();
    //                LoadQueue();
    //            }
    //         });
    //    }
    //    catch (Exception e)
    //    {
    //        Debug.LogError(e);
    //        LoadQueue();
    //    }
    //}
    private IEnumerator LoadQueue()
    {
        while (true)
        {
            if (currentNum >= count)
            {
                RunCallBack();
                Destroy();
                break;
            }
            PreloadResourcesDataGenerate da = queueRes[currentNum];
            currentNum++;
            //Debug.Log("预加载:" + da.m_key);
            try
            {
                string typeStr = da.m_ResType.ToString().Replace("_", ".");
                Type   resType = ReflectionUtils.GetTypeByTypeFullName(typeStr);

                if (resType == typeof(GameObject))
                {
                    List <GameObject> resList = new List <GameObject>();
                    for (int i = 0; i < da.m_instantiateNum; i++)
                    {
                        GameObject obj = GameObjectManager.CreateGameObjectByPool(da.m_key);
                        if (obj)
                        {
                            resList.Add(obj);
                        }
                    }
                    foreach (var obj in resList)
                    {
                        GameObjectManager.DestroyGameObjectByPool(obj, !da.m_createInstanceActive);
                    }
                }
                else
                {
                    object loadRes = ResourceManager.Load(da.m_key);
                    if (loadRes == null)
                    {
                        Debug.LogError("Error: 预加载失败  key:" + da.m_key);
                    }
                    else
                    {
                        ResourceManager.DestoryAssetsCounter(da.m_key);
                    }
                }
                RunCallBack();
                if (currentNum >= count)
                {
                    Destroy();
                    break;
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            yield return(new WaitForEndOfFrame());
        }
    }
Esempio n. 2
0
    private void LoadQueue()
    {
        if (currentNum >= count)
        {
            RunCallBack();
            Destroy();
            return;
        }
        PreloadResourcesDataGenerate da = queueRes[currentNum];

        currentNum++;
        //Debug.Log("da.m_key " + da.m_key);
        try
        {
            Type resType = ReflectionUtils.GetTypeByTypeFullName(da.m_ResType);

            //  object loadRes = AssetsPoolManager.Load(da.m_key);
            AssetsPoolManager.LoadAsync(da.m_key, resType, (LoadState loadState, object loadRes) =>
            {
                if (loadState.isDone)
                {
                    if (loadRes != null)
                    {
                        if (loadRes is GameObject)
                        {
                            GameObject prefab         = (GameObject)loadRes;
                            List <GameObject> resList = new List <GameObject>();
                            for (int i = 0; i < da.m_instantiateNum; i++)
                            {
                                GameObject obj = GameObjectManager.CreateGameObjectByPool(prefab);
                                resList.Add(obj);
                            }
                            foreach (var obj in resList)
                            {
                                GameObjectManager.DestroyGameObjectByPool(obj, !da.m_createInstanceActive);
                            }
                        }
                        else
                        {
                            AssetsPoolManager.DestroyByPool(da.m_key);
                        }
                    }
                    else
                    {
                        if (loadRes == null)
                        {
                            Debug.LogError("Error: 预加载失败  key:" + da.m_key);
                        }
                    }
                    RunCallBack();
                    LoadQueue();
                }
            });
        }
        catch (Exception e)
        {
            Debug.LogError(e);
            LoadQueue();
        }
    }