Пример #1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="sceneType"></param>
    /// <param name="isCloseLoadingAfter">为true需要自己关闭进度条</param>
    /// <returns></returns>
    public async Task ChangeSceneAsync(EnumScene sceneType, bool isCloseLoadingAfter = false)
    {
        //加载进度条
        await UIComponent.CreateUIAsync(UIType.UISceneLoading, isTopCanvas : true);

        uISceneLoadingComponent.Reset();

        //关闭聊天相关界面
        ChatTool.CloseChat();
        var scencePath = EnumScene.Empty.ToString();

        _currSceneTage = sceneType;
        //加载空场景
        scencePath = "Scenes/" + scencePath;
        SceneManager.LoadScene(scencePath);
        var bundleType = sceneType.ToString();

        if (sceneType != EnumScene.Empty)//空场景为退出到大厅
        {
            List <string> bundleNameList = new List <string>();

            if (preLoadMap.ContainsKey(sceneType))
            {
                bundleNameList.AddRange(preLoadMap[sceneType]);
            }
            //加上自己的场景ab包
            var sceneBundleName = ABManager.GetBundleNameByAssetNameAndType(sceneType.ToString(), typeof(GameObject));
            bundleNameList.Add($"{sceneBundleName}");

            List <string> allBundleNameList = new List <string>();
            foreach (var bundleName in bundleNameList)
            {
                string[] dependencies = ResourcesHelper.GetSortedDependencies(bundleName.ToLower());
                if (dependencies != null)
                {
                    foreach (var item in dependencies)
                    {
                        if (allBundleNameList.Contains(item))
                        {
                            continue;
                        }
                        allBundleNameList.Add(item);
                    }
                }
            }
            ResourcesComponent resourcesComponent = ResourcesComponent.instance;
            for (int i = 0; i < allBundleNameList.Count; i++)
            {
                await resourcesComponent.LoadOneBundleAsync(allBundleNameList[i], (real) => UpdateProgress(i, allBundleNameList.Count, real, allBundleNameList[i]));
            }
        }


        await AddSceneAsyncTask(bundleType, LoadSceneMode.Single);

        //await StaticData.CreateChatMini();
        if (isCloseLoadingAfter == false)
        {
            UIComponent.HideUI(UIType.UISceneLoading);
        }
    }