通用加载重构

main
yurui 2024-08-28 17:03:50 +08:00
parent bd61f39de0
commit f756e35436
43 changed files with 916 additions and 536 deletions

View File

@ -341,6 +341,11 @@
/// </summary>
PlayerInfoUpdate,
/// <summary>
/// 加载完成
/// </summary>
LoadingExecutorComplete,
#region 新手指引
/// <summary>
/// 新手引导退出关卡
@ -351,10 +356,6 @@
/// </summary>
GuideClickButton,
/// <summary>
/// 加载完成
/// </summary>
GuideLoadingExecutor,
/// <summary>
/// 切换剧情状态
/// </summary>
Guide_ChangeStoryState,

View File

@ -8,6 +8,7 @@ namespace Gameplay.Effect
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.Pause;
using Gameplay.SubSystems;
using UnityEngine;
public class EffectManager
@ -96,9 +97,9 @@ namespace Gameplay.Effect
MonoHelper.instance.AddAction(EActionType.UPDATE, _LogicUpdate);
}
public async UniTask<LoadingResult> PreloadEffects(List<int> effectIds = null)
public async UniTask<E_LoadingResult> PreloadEffects(List<int> effectIds = null)
{
return LoadingResult.Success;
return E_LoadingResult.Success;
if (effectIds == null)
{
// 从配表读取
@ -130,7 +131,7 @@ namespace Gameplay.Effect
await UniTask.DelayFrame(1);
}
return LoadingResult.Success;
return E_LoadingResult.Success;
}
private async void _PreloadEffect(DataEffect config)

View File

@ -24,7 +24,7 @@ namespace Gameplay.FakeFight
SROptions.Current.UseFullCharacters = useFullCharacters;
SROptions.Current.SelfUnbeatable = selfInvincible;
SROptions.Current.EnemyUnbeatable = enemyInvincible;
GameStartLoadingExecutor.newMethodLogin = useNewLoginWindow;
GameStartLoading.newMethodLogin = useNewLoginWindow;
#endif
}

View File

@ -0,0 +1,22 @@
using Framework;
using Gameplay.SubSystems;
using Gameplay;
using Cysharp.Threading.Tasks;
public class GameStateCampScene : IState
{
public void OnEnter()
{
LoadingManager.Instance.ExecuteLoading(new CampSceneLoadingExecutor()).Forget();
}
public void OnExit()
{
}
public void OnUpdate(float deltaTime)
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e76cdfa7ca36d964897116a99a0ca27d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -13,7 +13,7 @@ public class GameStateLevel : IState
}
public void OnEnter()
{
LoadingExecutorManager.Instance.ExecuteLoading(new LevelLoadingExecutor(_levelId)).Forget();
LoadingManager.Instance.ExecuteLoading(new LevelLoadingExecutor(_levelId)).Forget();
EventManager.Instance.Send(EventManager.EventName.Guide_ChangeLevelState);
}

View File

@ -21,14 +21,14 @@ public class GameStateMainScene : IState
IsLogin = isLogin;
}
public async void OnEnter()
public void OnEnter()
{
E_LoadingType loadingType = IsLogin ? E_LoadingType.Login : E_LoadingType.CommonLoading;
if (null == callbackAction)
LoadingExecutorManager.Instance.ExecuteLoading(new MainSceneLoadingExecutor(loadingType)).Forget();
LoadingManager.Instance.ExecuteLoading(new MainSceneLoadingExecutor(loadingType)).Forget();
else
{
await LoadingExecutorManager.Instance.ExecuteLoading(new MainSceneLoadingExecutor(loadingType));
LoadingManager.Instance.ExecuteLoading(new MainSceneLoadingExecutor(loadingType)).Forget();
callbackAction.Invoke();
callbackAction = null;
}

View File

@ -31,11 +31,6 @@ public class GameStateManager : Singlenton<GameStateManager> , IUpdatable, IInit
if (null == TableManager.Instance.Tables)
await TableManager.Instance.Load(); // 打开加载界面时要先加载配置
if(state is GameStateMainScene gameStateMainScene && gameStateMainScene.IsLogin)
await Gameplay.UI.Utils.ShowLoadingUI(Gameplay.E_LoadingType.Login, true);
else
await Gameplay.UI.Utils.ShowLoadingUI(Gameplay.E_LoadingType.CommonLoading, true);
// TODO: 目前看起来没什么用,先注释掉 2024-3-4 14:34 by liutao
// PerformanceManager.ClearRaycasterImage();
_stateMachine.ChangeState(state);

View File

@ -8,7 +8,7 @@ public class GameStateStart : IState
{
public void OnEnter()
{
LoadingExecutorManager.Instance.ExecuteLoading(new GameStartLoadingExecutor()).Forget();
LoadingManager.Instance.ExecuteLoading(new GameStartLoading()).Forget();
#if SDK_TAPTAP
var antiAddictionService = SDKManager.Instance.GetSdkHelper(SDKManager.SdkName.TapTap) as IAntiAddictionService;

View File

@ -39,6 +39,7 @@ namespace Code.Scripts.Gameplay.Game
{
_storyConfig = TableManager.Instance.Tables.StoryMainConfig.Get(storyId);
_autoPlay = autoPlay;
EventManager.Instance.Register(EventManager.EventName.LoadingExecutorComplete, OnLoadingExecutorComplete);
}
public void OnEnter()
@ -47,19 +48,11 @@ namespace Code.Scripts.Gameplay.Game
_isReady = false;
EventManager.Instance.Register(EventManager.EventName.STORY_CLICK_SKIP, _OnRecvExit);
var exe = new StoryLoadingExecutor(_storyConfig);
exe.OnEnd = delegate
{
_isReady = _autoPlay;
};
LoadingExecutorManager.Instance.ExecuteLoading(exe).Forget();
LoadingManager.Instance.ExecuteLoading(new StoryLoadingExecutor(_storyConfig)).Forget();
EventManager.Instance.Send(EventManager.EventName.Guide_ChangeStoryState);
}
public void OnUpdate(float deltaTime)
{
@ -84,8 +77,15 @@ namespace Code.Scripts.Gameplay.Game
}
}
private void OnLoadingExecutorComplete()
{
_isReady = _autoPlay;
}
public void OnExit()
{
EventManager.Instance.Unregister(EventManager.EventName.LoadingExecutorComplete, OnLoadingExecutorComplete);
StoryManager.instance.DisposeForGame();
EffectManager.instance.ClearPool();
GameSceneManager.Instance.UnLoadSceneAsync(_storyConfig.ScenePath).Forget();

View File

@ -25,7 +25,7 @@ public class MyGame : Game
_Register<GameSceneManager>();
_Register<UIManager>();
_Register<AppManager>();
_Register<LoadingExecutorManager>();
_Register<LoadingManager>();
_Register<Gameplay.Net.NetManager>();
_Register<Gameplay.Net.AppConfig>();
_Register<Gameplay.Net.Actor>();

View File

@ -222,14 +222,14 @@ namespace Gameplay.Guide
public override void AddListener()
{
EventManager.Instance.Register(EventManager.EventName.Guide_ChangeLevelState, OnChangeLevelState);
EventManager.Instance.Register(EventManager.EventName.GuideLoadingExecutor, OnLoadingExecutor);
EventManager.Instance.Register(EventManager.EventName.LoadingExecutorComplete, OnLoadingExecutor);
EventManager.Instance.Register(EventManager.EventName.UIClose, (Action<string>)OnLoadingClose);
}
public override void RemoveListener()
{
EventManager.Instance.Unregister(EventManager.EventName.UIClose, (Action<string>)OnLoadingClose);
EventManager.Instance.Unregister(EventManager.EventName.GuideLoadingExecutor, OnLoadingExecutor);
EventManager.Instance.Unregister(EventManager.EventName.LoadingExecutorComplete, OnLoadingExecutor);
EventManager.Instance.Unregister(EventManager.EventName.Guide_ChangeLevelState, OnChangeLevelState);
}
@ -288,14 +288,14 @@ namespace Gameplay.Guide
public override void AddListener()
{
EventManager.Instance.Register(EventManager.EventName.Guide_ChangeStoryState, OnChangeStoryState);
EventManager.Instance.Register(EventManager.EventName.GuideLoadingExecutor, OnLoadingExecutor);
EventManager.Instance.Register(EventManager.EventName.LoadingExecutorComplete, OnLoadingExecutor);
EventManager.Instance.Register(EventManager.EventName.UIClose, (Action<string>)OnLoadingClose);
}
public override void RemoveListener()
{
EventManager.Instance.Unregister(EventManager.EventName.UIClose, (Action<string>)OnLoadingClose);
EventManager.Instance.Unregister(EventManager.EventName.GuideLoadingExecutor, OnLoadingExecutor);
EventManager.Instance.Unregister(EventManager.EventName.LoadingExecutorComplete, OnLoadingExecutor);
EventManager.Instance.Unregister(EventManager.EventName.Guide_ChangeStoryState, OnChangeStoryState);
}

View File

@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.SubSystems;
using PhxhSDK;
namespace Gameplay.Level
@ -10,13 +11,13 @@ namespace Gameplay.Level
{
public Level CurrentLevel { get; private set; }
public async UniTask<LoadingResult> LoadLevel(int leveId)
public async UniTask<E_LoadingResult> LoadLevel(int leveId)
{
CurrentLevel = new Level(leveId, _levelParam);
await CurrentLevel.Load();
await UniTask.NextFrame();
return LoadingResult.Success;
return E_LoadingResult.Success;
}
public async void UnloadLevel()

View File

@ -0,0 +1,27 @@
using cfg.ShowCfg;
using Cysharp.Threading.Tasks;
using Gameplay.SubSystems;
using UnityEngine.SceneManagement;
using static Gameplay.CommonUtils;
using Constants = Framework.Constants;
namespace Gameplay
{
public class CampSceneLoadingExecutor : LoadingExecutor
{
public CampSceneLoadingExecutor() : base(E_LoadingType.CommonLoading)
{
}
protected override async UniTask<E_LoadingResult> OnExecute()
{
progress = 0.5f;
await OpenUIWithScene(UINameConst.UI_Camp, Constants.CAMP_SCENE_PATH, null, true, LoadSceneMode.Single);
ShowManager.Instance.RefreshShow(E_ShowSceneType.Camp);
return E_LoadingResult.Success;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 539f9490efe5afd418c9bfcd4dd73e1c
timeCreated: 1686709906

View File

@ -0,0 +1,254 @@
using System;
using System.IO;
using System.Net.NetworkInformation;
using System.Threading.Tasks;
using CriWare;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.Net;
using Gameplay.Performance;
using Gameplay.SubSystems;
using PhxhSDK;
using UnityEditor;
using UnityEngine;
using UnityEngine.Networking;
using YooAsset;
#if !UNITY_EDITOR
using UnityEngine;
#endif
using Constants = Framework.Constants;
namespace Gameplay
{
public class GameStartLoading : LoadingExecutor
{
public static bool newMethodLogin = true;
public GameStartLoading() : base(E_LoadingType.CommonLoading)
{
}
protected override async UniTask<E_LoadingResult> OnExecute()
{
E_LoadingResult result;
progress = 0.1f;
await Resources.UnloadUnusedAssets();
result = await FirstRunAppCheck();
if (result != E_LoadingResult.Success)
return result;
progress = 0.25f;
result = await AppVersionCheck();
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("AppVersionCheck错误");
return result;
}
progress = 0.4f;
result = await CheckCriAtom();
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("CheckCriAtom错误");
return result;
}
progress = 0.55f;
result = await LoadLoginUI();
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("LoadLoginUI错误");
return result;
}
progress = 0.7f;
result = await PreloadOthers();
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("_PreloadOthers错误");
return result;
}
progress = 0.85f;
result = await LoadPerformance();
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("_LoadPerformance错误");
return result;
}
progress = 0.9f;
result = InitGameSetting();
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("InitGameSetting错误");
return result;
}
progress = 0.95f;
if (!newMethodLogin)//使用原先登录逻辑
await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_LogIn);
else//新版登陆界面
await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_StartGameInterface);
DebugUtil.LogError("GameStart加载完成");
return E_LoadingResult.Success;
}
private async UniTask<E_LoadingResult> PreloadOthers()
{
// 渐变shader需要提前加载
AssetManager.Instance.PostPreload(Constants.SHADER_FADEOUT_PATH);
await AssetManager.Instance.WaitAllPreloads();
return E_LoadingResult.Success;
}
private async UniTask<E_LoadingResult> LoadLoginUI()
{
if (!newMethodLogin)
await UIManager.Instance.LoadWindow(UINameConst.UI_LogIn);
else
await UIManager.Instance.LoadWindow(UINameConst.UI_StartGameInterface);
return E_LoadingResult.Success;
}
/// <summary>
/// 是否是安装后第一次运行
/// </summary>
/// <returns></returns>
private async UniTask<E_LoadingResult> FirstRunAppCheck()
{
var result = await Net.AppConfig.Instance.UnityRequest();
if (result == Net.ACDownloadStatus.Error)
{
DebugUtil.LogError("网络错误或服务器列表没有添加对应渠道");
return E_LoadingResult.DeviceNetError;
}
return E_LoadingResult.Success;
}
/// <summary>
/// 强更检查
/// </summary>
/// <returns></returns>
private async UniTask<E_LoadingResult> AppVersionCheck()
{
var needUpdate = AppConfig.Instance.UpdateInfo.NeedUpdate;
if (needUpdate)
{
string platform = GetPlatform();
if (null != platform && AppConfig.Instance.UpdateInfo.AppUrl.TryGetValue(platform, out string url))
await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_Update, url);
return E_LoadingResult.ErrorTest;
}
return E_LoadingResult.Success;
}
private string GetPlatform()
{
#if UNITY_EDITOR
return EditorUserBuildSettings.activeBuildTarget switch
{
BuildTarget.Android => "android",
BuildTarget.iOS => "ios",
_ => null,
};
#else
return Application.platform switch
{
RuntimePlatform.Android => "android",
RuntimePlatform.IPhonePlayer => "ios",
_ => null,
};
#endif
}
private async UniTask<E_LoadingResult> LoadPerformance()
{
if (PerformanceManager.instance != null)
{
return E_LoadingResult.Success;
}
PerformanceManager.CreateInstance();
if (PerformanceManager.instance == null)
{
DebugUtil.LogError("PerformanceManager 创建失败");
return E_LoadingResult.ErrorTest;
}
await PerformanceManager.instance.LoadRes();
return E_LoadingResult.Success;
}
private E_LoadingResult InitGameSetting()
{
StorageMgr.Instance.InitServerData();
return E_LoadingResult.Success;
}
private async UniTask<E_LoadingResult> CheckCriAtom()
{
const string AUDIO_PATH = "Assets/AudioCPK/";
RawFileHandle rawFileHandle = AssetManager.Instance.LoadRawFileAsync($"{AUDIO_PATH}{CriAtom.instance.acfFile}");
await rawFileHandle;
string realPath = rawFileHandle.GetRawFilePath();
if (realPath.EndsWith(".acf"))
CriAtom.instance.acfRealPath = realPath;
else
CriAtom.instance.acfRealPath = $"{realPath}.acf";
if (!File.Exists(CriAtom.instance.acfRealPath))
File.Copy(realPath, CriAtom.instance.acfRealPath);
foreach (CriAtomCueSheet sheet in CriAtom.instance.cueSheets)
{
#region acb
rawFileHandle = AssetManager.Instance.LoadRawFileAsync($"{AUDIO_PATH}{sheet.acbFile}");
await rawFileHandle;
realPath = rawFileHandle.GetRawFilePath();
if (realPath.EndsWith(".acb"))
sheet.acbRealPath = realPath;
else
sheet.acbRealPath = $"{realPath}.acb";
if (!File.Exists(sheet.acbRealPath))
File.Copy(realPath, sheet.acbRealPath);
#endregion
#region awb
rawFileHandle = AssetManager.Instance.LoadRawFileAsync($"{AUDIO_PATH}{sheet.awbFile}");
await rawFileHandle;
realPath = rawFileHandle.GetRawFilePath();
if (realPath.EndsWith(".awb"))
sheet.awbRealPath = realPath;
else
sheet.awbRealPath = $"{realPath}.awb";
if (!File.Exists(sheet.awbRealPath))
File.Copy(realPath, sheet.awbRealPath);
#endregion
}
CriAtom.instance.Load();
return E_LoadingResult.Success;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 28d835f8dbffd114fac72cd202020707
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +1,13 @@
using System;
using System.IO;
using System.Net.NetworkInformation;
using System.Threading.Tasks;
using System.IO;
using CriWare;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.Net;
using Gameplay.Performance;
using Gameplay.SubSystems;
using PhxhSDK;
using UnityEditor;
using UnityEngine;
using UnityEngine.Networking;
using YooAsset;
@ -22,114 +19,119 @@ using Constants = Framework.Constants;
namespace Gameplay
{
public class GameStartLoadingExecutor : LoadingExecutorWithUILoadingController
public class GameStartLoadingExecutor : LoadingExecutor
{
public static bool newMethodLogin = true;
protected override async UniTask<LoadingResult> _DoLoading()
public GameStartLoadingExecutor() : base(E_LoadingType.CommonLoading)
{ }
protected override async UniTask<E_LoadingResult> OnExecute()
{
LoadingResult result;
_destProgress = 5f;
E_LoadingResult result;
progress = 0.1f;
await Resources.UnloadUnusedAssets();
result = await FirstRunAppCheck();
if (result != LoadingResult.Success)
if (result != E_LoadingResult.Success)
return result;
_destProgress = 10f;
progress = 0.25f;
result = await AppVersionCheck();
if (result != LoadingResult.Success)
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("AppVersionCheck错误");
return result;
}
_destProgress = 15f;
progress = 0.4f;
result = await CheckCriAtom();
if (result != LoadingResult.Success)
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("CheckCriAtom错误");
return result;
}
_destProgress = 30f;
progress = 0.55f;
result = await LoadLoginUI();
if (result != LoadingResult.Success)
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("LoadLoginUI错误");
return result;
}
_destProgress = 80f;
progress = 0.7f;
result = await _PreloadOthers();
if (result != LoadingResult.Success)
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("_PreloadOthers错误");
return result;
}
progress = 0.8f;
result = await _LoadPerformance();
if (result != LoadingResult.Success)
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("_LoadPerformance错误");
return result;
}
progress = 0.9f;
result = await InitGameSetting();
if (result != LoadingResult.Success)
if (result != E_LoadingResult.Success)
{
DebugUtil.LogError("InitGameSetting错误");
return result;
}
_destProgress = 95f;
progress = 0.95f;
if (!newMethodLogin)//使用原先登录逻辑
await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_LogIn);
else//新版登陆界面
await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_StartGameInterface);
//await UI_LoadingProgressInterfaceController.Open();
_destProgress = 100f;
DebugUtil.LogError("GameStart加载完成");
return LoadingResult.Success;
return E_LoadingResult.Success;
}
private async UniTask<LoadingResult> _PreloadOthers()
private async UniTask<E_LoadingResult> _PreloadOthers()
{
// 渐变shader需要提前加载
AssetManager.Instance.PostPreload(Constants.SHADER_FADEOUT_PATH);
await AssetManager.Instance.WaitAllPreloads();
return LoadingResult.Success;
return E_LoadingResult.Success;
}
private async UniTask<LoadingResult> LoadLoginUI()
private async UniTask<E_LoadingResult> LoadLoginUI()
{
if (!newMethodLogin)
await UIManager.Instance.LoadWindow(UINameConst.UI_LogIn);
else
await UIManager.Instance.LoadWindow(UINameConst.UI_StartGameInterface);
return LoadingResult.Success;
return E_LoadingResult.Success;
}
// 是否是安装后第一次运行
private async UniTask<LoadingResult> FirstRunAppCheck()
private async UniTask<E_LoadingResult> FirstRunAppCheck()
{
var result = await Net.AppConfig.Instance.UnityRequest();
if (result == Net.ACDownloadStatus.Error)
{
DebugUtil.LogError("网络错误或服务器列表没有添加对应渠道");
return LoadingResult.DeviceNetError;
return E_LoadingResult.DeviceNetError;
}
return LoadingResult.Success;
return E_LoadingResult.Success;
}
// 强更检查
private async UniTask<LoadingResult> AppVersionCheck()
private async UniTask<E_LoadingResult> AppVersionCheck()
{
var needUpdate = AppConfig.Instance.UpdateInfo.NeedUpdate;
@ -139,10 +141,10 @@ namespace Gameplay
if (null != platform && AppConfig.Instance.UpdateInfo.AppUrl.TryGetValue(platform, out string url))
await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_Update, url);
return LoadingResult.ErrorTest;
return E_LoadingResult.ErrorTest;
}
return LoadingResult.Success;
return E_LoadingResult.Success;
}
private string GetPlatform()
@ -164,41 +166,41 @@ namespace Gameplay
#endif
}
private async UniTask<LoadingResult> LoadConfig()
private async UniTask<E_LoadingResult> LoadConfig()
{
await TableManager.Instance.Load();
return LoadingResult.Success;
return E_LoadingResult.Success;
}
private async UniTask<LoadingResult> _LoadPerformance()
private async UniTask<E_LoadingResult> _LoadPerformance()
{
if (PerformanceManager.instance != null)
{
return LoadingResult.Success;
return E_LoadingResult.Success;
}
PerformanceManager.CreateInstance();
if (PerformanceManager.instance == null)
{
DebugUtil.LogError("PerformanceManager 创建失败");
return LoadingResult.ErrorTest;
return E_LoadingResult.ErrorTest;
}
await PerformanceManager.instance.LoadRes();
// 强行设置默认性能, 防止后续流程忘了设置
PerformanceManager.SetPerformance(PerformanceManager.instance.data);
return LoadingResult.Success;
return E_LoadingResult.Success;
}
private async UniTask<LoadingResult> InitGameSetting()
private async UniTask<E_LoadingResult> InitGameSetting()
{
StorageMgr.Instance.InitServerData();
return LoadingResult.Success;
return E_LoadingResult.Success;
}
private async UniTask<LoadingResult> CheckCriAtom()
private async UniTask<E_LoadingResult> CheckCriAtom()
{
const string AUDIO_PATH = "Assets/AudioCPK/";
@ -244,7 +246,7 @@ namespace Gameplay
CriAtom.instance.Load();
return LoadingResult.Success;
return E_LoadingResult.Success;
}
}
}

View File

@ -1,3 +1,11 @@
fileFormatVersion: 2
guid: 1e79eaebb927476d84d16b585927125e
timeCreated: 1686648562
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -9,50 +9,50 @@ using UnityEngine;
namespace Gameplay
{
public class LevelLoadingExecutor : LoadingExecutorWithUILoadingController
public class LevelLoadingExecutor : LoadingExecutor
{
private int _levelId;
protected override async UniTask<LoadingResult> _DoLoading()
public LevelLoadingExecutor(int leveId) : base(E_LoadingType.CommonLoading)
{
_levelId = leveId;
}
protected override async UniTask<E_LoadingResult> OnExecute()
{
//如果加载返回成功,则继续,否则直接返回错误码
_destProgress = 20f;
progress = 0.2f;
await Resources.UnloadUnusedAssets();
var loadingResult = await TerrainTypeConfig.Load();
if (loadingResult != LoadingResult.Success)
{
if (loadingResult != E_LoadingResult.Success)
return loadingResult;
}
_destProgress = 25f;
progress = 0.5f;
loadingResult = await LevelManager.Instance.LoadLevel(_levelId);
if (loadingResult != LoadingResult.Success)
{
if (loadingResult != E_LoadingResult.Success)
return loadingResult;
}
_destProgress = 80f;
progress = 0.7f;
EffectManager.CreateInstance();
loadingResult = await EffectManager.instance.PreloadEffects();
if (loadingResult != LoadingResult.Success)
if (loadingResult != E_LoadingResult.Success)
{
return loadingResult;
}
loadingResult = await LoadUI();
if (loadingResult != LoadingResult.Success)
if (loadingResult != E_LoadingResult.Success)
{
return loadingResult;
}
_destProgress = 90f;
progress = 0.9f;
loadingResult = await LoadAI();
if (loadingResult != LoadingResult.Success)
if (loadingResult != E_LoadingResult.Success)
{
return loadingResult;
}
_destProgress = 100f;
TeamManager.Instance.TeamUIOpen();
LevelManager.Instance.PlayBGM();
@ -69,22 +69,17 @@ namespace Gameplay
}
#endregion
return LoadingResult.Success;
return E_LoadingResult.Success;
}
public LevelLoadingExecutor(int leveId)
{
_levelId = leveId;
}
private async UniTask<LoadingResult> LoadUI()
private async UniTask<E_LoadingResult> LoadUI()
{
await TeamManager.Instance.TeamUIInit();
return LoadingResult.Success;
return E_LoadingResult.Success;
}
private async UniTask<LoadingResult> LoadAI()
private async UniTask<E_LoadingResult> LoadAI()
{
var level = LevelManager.Instance.CurrentLevel;
if (level != null)
@ -95,7 +90,7 @@ namespace Gameplay
await AIManager.Instance.PreLoadAI(aiNames, 4);
}
return LoadingResult.Success;
return E_LoadingResult.Success;
}
}
}

View File

@ -0,0 +1,74 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Gameplay
{
/// <summary>
/// 加载表现类
/// </summary>
public class LoadingDisplay
{
/// <summary>
/// 进度变化的插值时间
/// </summary>
private float changeProgressTime;
/// <summary>
/// 上次获取时间
/// </summary>
private float preGetTime;
/// <summary>
/// 目标进度
/// </summary>
private float targerProgress;
/// <summary>
/// 开始进度
/// </summary>
private float beginProgress;
/// <summary>
/// 加载完成的等待时间
/// </summary>
public float LoadingCompleteWaitTime { get; private set; }
/// <summary>
/// 表现进度
/// </summary>
public float ShowProgress { get; private set; }
public void SetInfo(float changeProgressTime, float loadingCompleteWaitTime)
{
this.changeProgressTime = Mathf.Max(0f, changeProgressTime);
LoadingCompleteWaitTime = Mathf.Max(0f, loadingCompleteWaitTime);
preGetTime = Time.realtimeSinceStartup;
beginProgress = 0f;
targerProgress = 0f;
ShowProgress = 0f;
}
public void Update(float realProgress)
{
if (0f >= changeProgressTime) // 没有插值时间
{
targerProgress = realProgress;
preGetTime = Time.realtimeSinceStartup;
ShowProgress = targerProgress;
return;
}
float realtimeSinceStartup = Time.realtimeSinceStartup;
if (!Mathf.Approximately(targerProgress, realProgress))
{
preGetTime = realtimeSinceStartup;
beginProgress = ShowProgress;
targerProgress = realProgress;
}
float timer = realtimeSinceStartup - preGetTime;
ShowProgress = Mathf.Lerp(beginProgress, targerProgress, Mathf.Clamp01(timer / changeProgressTime));
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 432b3ea13336a864ea0c4a82a72a8563
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,44 +1,130 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.SubSystems;
using UnityEngine;
namespace Gameplay
{
/// <summary>
/// 加载器基类
/// </summary>
public abstract class LoadingExecutor
{
protected float _destProgress; //0-100
/// <summary>
/// 打开加载UI类型
/// </summary>
private readonly E_LoadingType loadingType;
protected bool _goOnLoading = true;
/// <summary>
/// 进度0f-1f
/// </summary>
protected float progress;
/// <summary>
/// 是否运行中
/// </summary>
protected bool isRunning;
public float DestProgress => _destProgress;
public Func<float> GetProgress;
public Func<float> getProgress;
public abstract UniTask OnExecute();
#region 属性
/// <summary>
/// 是否等待中
/// </summary>
public bool IsWait { get; set; }
protected bool _isRunning = false;
/// <summary>
/// 进度0f-1f
/// </summary>
public float Progress { get { return progress; } }
public bool IsWait = true;
/// <summary>
/// 是否正在运行
/// </summary>
public bool IsRunning { get { return isRunning; } }
#endregion
public async UniTask Excute()
public LoadingExecutor(E_LoadingType type)
{
await OnExecute();
progress = 0f;
isRunning = false;
loadingType = type;
}
public bool IsExcuting()
public async UniTask Excute(float loadingCompleteWaitTime)
{
return _isRunning;
#region 加载之前
progress = 0f;
isRunning = true;
await UI.Utils.ShowLoadingUI(loadingType, true);
GC.Collect();
#endregion
#region 正式加载
E_LoadingResult loadingResult = await OnExecute();
DealWithResult(loadingResult);
#endregion
#region 加载结束
progress = 1f;
await UniTask.WaitForSeconds(loadingCompleteWaitTime);
isRunning = false;
await TransitionManager.Instance.OpenNormalTransitionUI();
TransitionManager.Instance.ReadyShowNormalTransition();
EventManager.Instance.Send(EventManager.EventName.LoadingExecutorComplete);
#endregion
}
/// <summary>
/// 开始执行
/// </summary>
/// <returns></returns>
protected abstract UniTask<E_LoadingResult> OnExecute();
/// <summary>
/// 刷新进度
/// </summary>
public virtual void RefreshProgress()
{
if (getProgress != null)
if (null != GetProgress)
progress = GetProgress.Invoke();
}
private async void Reloading()
{
await Excute(0f);
}
protected virtual void DealWithResult(E_LoadingResult result)
{
switch (result)
{
_destProgress = getProgress.Invoke();
}
case (E_LoadingResult.ErrorTest):
{
DebugUtil.LogError("加载错误");
break;
}
case (E_LoadingResult.DeviceNetError):
{
//启动游戏网络连接错误
string title = "网络错误";
string desc = "加载错误,请检查网络连接后重启";
UITipsManager.ShowConfirmOne(title, desc, (Action)Application.Quit);
break;
}
case (E_LoadingResult.GameStartSevNetError):
{
string title = "网络错误";
string desc = "加载错误,请检查网络连接后重启";
UITipsManager.ShowConfirmTwo(title, desc, (Action)Reloading, (Action)Application.Quit);
}
break;
default:
break;
}
}
}
}

View File

@ -1,117 +0,0 @@
using System;
using Cysharp.Threading.Tasks;
using Gameplay.SubSystems;
using Application = UnityEngine.Application;
namespace Gameplay
{
public class LoadingExecutorWithUILoadingController : LoadingExecutor
{
public Action OnEnd;
public Action OnEndUI;
private readonly E_LoadingType loadingType;
public LoadingExecutorWithUILoadingController(E_LoadingType type = E_LoadingType.CommonLoading)
{
loadingType = type;
}
public override async UniTask OnExecute()
{
await TransitionManager.Instance.OpenNormalTransitionUI();
OnEndUI = () => { TransitionManager.Instance.ReadyShowNormalTransition(); };
switch (loadingType)
{
case E_LoadingType.Login:
{
await UI_LoadingProgressInterfaceController.Open(OnEnd, OnEndUI);
}
break;
default:
{
await UI_LoadingInterfaceController.Open(OnEnd, OnEndUI);
}
break;
}
//EventManager.Instance.Send(EventManager.EventName.ClearUIStack);
LoadingResult result = await _DoLoading();
DealWithResult(result);
_isRunning = false;
if (_destProgress < 100f)
{
//DebugUtil.LogError(" LoadingExecutorWithUILoadingController {0} < 100f", _destProgress);
}
}
protected virtual void DealWithResult(LoadingResult result)
{
switch (result)
{
case (LoadingResult.ErrorTest):
{
//展示加载错误
// string title = "加载错误!";
// string desc = "加载错误,请返回登录界面重试。";
// UITipsManager.ShowConfirmOne(title, desc, (Action)GameClientReconnect.BackToStart);
DebugUtil.LogError("加载错误");
break;
}
case (LoadingResult.DeviceNetError):
{
//启动游戏网络连接错误
string title = "网络错误";
string desc = "加载错误,请检查网络连接后重启";
UITipsManager.ShowConfirmOne(title, desc, (Action)Application.Quit);
break;
}
case (LoadingResult.GameStartSevNetError):
{
string title = "网络错误";
string desc = "加载错误,请检查网络连接后重启";
UITipsManager.ShowConfirmTwo(title, desc, (Action)Reloading, (Action)Application.Quit);
Reloading();
}
break;
default:
break;
}
}
private void Reloading()
{
if (LoadingExecutorManager.Instance.CurrentExcutor != null)
{
_isRunning = false;
LoadingExecutorManager.Instance.CurrentExcutor.Excute().Forget();
}
}
protected async virtual UniTask<LoadingResult> _DoLoading()
{
await UniTask.NextFrame();
return LoadingResult.Success;
}
}
/// <summary>
/// loading界面类型
/// </summary>
public enum E_LoadingType
{
/// <summary>
/// 登录游戏
/// </summary>
Login,
/// <summary>
/// 通用加载
/// </summary>
CommonLoading,
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: b783547057a24a43afdb687ab1cddc7f
timeCreated: 1686710316

View File

@ -1,40 +0,0 @@
namespace Gameplay
{
public class LoadingInfo
{
public enum EStatus
{
None,
Loading,
Finish,
Failed,
}
public int Current;
public int Max;
public string Desc;
public EStatus Status;
}
public enum LoadingResult
{
/// <summary>
/// 完成加载
/// </summary>
Success = 0,
/// <summary>
/// 加载出错(测试)
/// </summary>
ErrorTest = 1,
/// <summary>
/// 启动游戏时网络连接出错
/// </summary>
GameStartSevNetError = 2,
/// <summary>
/// 当前设备网络问题
/// </summary>
DeviceNetError = 3,
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: a38a2bfdad33488492b2c2301b78ea59
timeCreated: 1691480870

View File

@ -3,6 +3,7 @@ using cfg.MainSceneCfg;
using cfg.ShowCfg;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.SubSystems;
using UnityEngine.SceneManagement;
using static Gameplay.CommonUtils;
using static UI_MainPanelController;
@ -10,17 +11,16 @@ using Constants = Framework.Constants;
namespace Gameplay
{
// define a class named LoginLoadingExecutor which extends from LoadingExecutor
class MainSceneLoadingExecutor : LoadingExecutorWithUILoadingController
public class MainSceneLoadingExecutor : LoadingExecutor
{
private E_LoadingType loadingType;
private readonly E_LoadingType loadingType;
public MainSceneLoadingExecutor(E_LoadingType loadingType) : base(loadingType)
public MainSceneLoadingExecutor(E_LoadingType type) : base(type)
{
this.loadingType = loadingType;
loadingType = type;
}
protected override async UniTask<LoadingResult> _DoLoading()
protected override async UniTask<E_LoadingResult> OnExecute()
{
if (E_LoadingType.Login == loadingType) // 加载很卡导致视频很卡,这里先让加载视频正常播放两秒
{
@ -33,26 +33,23 @@ namespace Gameplay
MainEnterData mainEnterData = StorageMgr.Instance.GetStorage<MainEnterData>("MAIN_ENTER_DATA");
int enterCount = mainEnterData.EnterCount;
_destProgress = 10f;
GC.Collect();
//await Resources.UnloadUnusedAssets();
_destProgress = 20f;
progress = 0.1f;
await GameSceneHelper.Instance.LoadSceneForUIView(Constants.UI_LEVEL_SELECTED_SCENE_PATH, LoadSceneMode.Single); // 加载关卡选择场景
_destProgress = 35;
await GameSceneHelper.Instance.LoadSceneForUIView(Constants.UI_SHOP_SCENE_PATH);
_destProgress = 45f;
progress = 0.25f;
await GameSceneHelper.Instance.LoadSceneForUIView(Constants.UI_VEHICLE_CHOOSE_SCENE_PATH);
_destProgress = 50f;
await GameSceneHelper.Instance.LoadSceneForUIView(Constants.RAFFLE_SCENE_PATH, LoadSceneMode.Additive); // 加载抽卡场景
await GameSceneHelper.Instance.LoadSceneForUIView(Constants.UI_SHOP_SCENE_PATH); // 商店场景
_destProgress = 60f;
progress = 0.4f;
await GameSceneHelper.Instance.LoadSceneForUIView(Constants.UI_VEHICLE_CHOOSE_SCENE_PATH); // 载具场景
progress = 0.55f;
await GameSceneHelper.Instance.LoadSceneForUIView(Constants.RAFFLE_SCENE_PATH); // 抽卡场景
progress = 0.7f;
string scenePath;//= Constants.MAIN_SCENE_PATH;
//====场景选择测试=====
@ -72,16 +69,14 @@ namespace Gameplay
}
//==================
UISceneResult uiSceneResult = await OpenUIWithScene(UINameConst.UI_MainPanel, scenePath, null, false,
LoadSceneMode.Additive);
UISceneResult uiSceneResult = await OpenUIWithScene(UINameConst.UI_MainPanel, scenePath, null, false, LoadSceneMode.Additive);
_destProgress = 80f;
progress = 0.8f;
if (GetSceneRootComponent<ShowComponent>(uiSceneResult.sceneHandle.Scene) == null)
{
DebugUtil.LogError($"无法进入主场景,{typeof(ShowComponent).Name}不存在,scene path:{scenePath}");
return LoadingResult.ErrorTest;
return E_LoadingResult.ErrorTest;
}
if (enterCount < 1)
@ -89,11 +84,9 @@ namespace Gameplay
else
SetCurMainSceneCameraStand(CameraIndex);
ShowManager.Instance.RefreshShow(E_ShowSceneType.Main);
ShowManager.Instance.RefreshShow(E_ShowSceneType.Main); // 刷新主场景演出
_destProgress = 100f;
return LoadingResult.Success;
return E_LoadingResult.Success;
}
}
}

View File

@ -2,36 +2,36 @@
using cfg.MainSceneCfg;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.SubSystems;
namespace Gameplay
{
public class MainSceneReLoadingExecutor: LoadingExecutorWithUILoadingController
public class MainSceneReLoadingExecutor: LoadingExecutor
{
protected override async UniTask<LoadingResult> _DoLoading()
public MainSceneReLoadingExecutor() : base(E_LoadingType.CommonLoading)
{
}
protected override async UniTask<E_LoadingResult> OnExecute()
{
_destProgress = 10f;
GC.Collect();
_destProgress = 20f;
await UniTask.Yield();
progress = 0.5f;
MainPanelSceneStoreData storeData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
MainSceneConfig mainSceneConfig = TableManager.Instance.Tables.MainSceneConfig;
int CameraIndex = storeData.CameraPosIdx;
int index = storeData.SceneIdx + 1;
if (index >= mainSceneConfig.DataList.Count)
{
_destProgress = 100f;
return LoadingResult.Success;
}
return E_LoadingResult.Success;
string path = mainSceneConfig[index].Path;
CommonUtils.ChangeUIScene(path);
_destProgress = 100f;
//====场景镜头测试=====
CommonUtils.SetCurMainSceneCameraStand(CameraIndex);
//==================
return LoadingResult.Success;
return E_LoadingResult.Success;
}
}
}

View File

@ -9,11 +9,11 @@ using Constants = Framework.Constants;
namespace Gameplay
{
public class StoryLoadingExecutor : LoadingExecutorWithUILoadingController
public class StoryLoadingExecutor : LoadingExecutor
{
private readonly DataStoryMain _cfg;
public StoryLoadingExecutor(DataStoryMain cfg)
public StoryLoadingExecutor(DataStoryMain cfg) : base(E_LoadingType.CommonLoading)
{
_cfg = cfg;
if (_cfg == null)
@ -21,31 +21,30 @@ namespace Gameplay
DebugUtil.LogError("StoryLoadingExecutor: DataStoryMain is null");
}
}
protected override async UniTask<LoadingResult> _DoLoading()
{
_destProgress = 10f;
Resources.UnloadUnusedAssets();
protected override async UniTask<E_LoadingResult> OnExecute()
{
progress = 0.1f;
await Resources.UnloadUnusedAssets();
await AssetManager.Instance.PostPreload<GameObject>(Constants.STORY_HEAD_CAMERA_PATH);
await _LoadScene();
_destProgress = 50;
progress = 0.5f;
// 设置阴影距离
ShadowEx.SetShadowDistance(_cfg.ShadowDistance);
_destProgress = 51;
progress = 0.7f;
await StoryManager.instance.InitForGame(_cfg);
_destProgress = 90
;
progress = 0.9f;
await UIManager.Instance.CreateAndOpenWindow(UINameConst.UIStoryMain);
_destProgress = 100;
return LoadingResult.Success;
return E_LoadingResult.Success;
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.SubSystems;
using PhxhSDK.Phxh;
using UnityEditor;
using UnityEngine;
@ -34,7 +35,7 @@ namespace Gameplay
}
private static List<TerrainTypeProperty> _terrainTypeProperties;
public static async UniTask<LoadingResult> Load()
public static async UniTask<E_LoadingResult> Load()
{
if (Application.isPlaying)
{
@ -44,7 +45,7 @@ namespace Gameplay
if (!Application.isPlaying)
_terrainTypeProperties = JsonHelper.LoadJson<List<TerrainTypeProperty>>(Constants.TERRAIN_TYPE_CONFIG_PATH);
#endif
return LoadingResult.Success;
return E_LoadingResult.Success;
}
public static void Save(List<TerrainTypeProperty> terrainTypeProperties)

View File

@ -95,7 +95,7 @@ namespace Gameplay.Net
// if (!GuideManager.Instance.BeginGuide())
// GameStateManager.Instance.ChangeState(new GameStateMainScene(true));
//
if (!GameStartLoadingExecutor.newMethodLogin)
if (!GameStartLoading.newMethodLogin)
{
OnEnterGame();
}

View File

@ -0,0 +1,12 @@
using Cysharp.Threading.Tasks;
namespace Gameplay
{
public interface ILoadingUI
{
/// <summary>
/// 打开
/// </summary>
UniTask<UIWindow> OpenUI();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a849f3ad59435b408df0954d68e4b75
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,26 +0,0 @@
using Cysharp.Threading.Tasks;
using Framework;
using PhxhSDK;
namespace Gameplay.SubSystems
{
public class LoadingExecutorManager : Singlenton<LoadingExecutorManager>
{
private LoadingExecutor _currentloadingExecutor;
public async UniTask ExecuteLoading(LoadingExecutor executer)
{
if (executer == null)
return;
if (_currentloadingExecutor != null && _currentloadingExecutor.IsExcuting())
return;
_currentloadingExecutor = executer;
await _currentloadingExecutor.Excute();
EventManager.Instance.Send(EventManager.EventName.GuideLoadingExecutor);
}
public LoadingExecutor CurrentExcutor => _currentloadingExecutor;
}
}

View File

@ -0,0 +1,163 @@
using Cysharp.Threading.Tasks;
using Framework;
using PhxhSDK;
namespace Gameplay.SubSystems
{
/// <summary>
/// 加载管理器
/// </summary>
public class LoadingManager : Singlenton<LoadingManager>, IInitable
{
/// <summary>
/// 当前加载
/// </summary>
private LoadingExecutor curLoadingExecutor;
/// <summary>
/// 加载表现
/// </summary>
private LoadingDisplay loadingDisplay;
#region 进度
/// <summary>
/// 是否正在运行
/// </summary>
public bool IsRuning
{
get
{
if (null == curLoadingExecutor)
return false;
return curLoadingExecutor.IsRunning;
}
}
/// <summary>
/// 实际进度
/// </summary>
public float Progress
{
get
{
if (null == curLoadingExecutor)
return 0f;
return curLoadingExecutor.Progress;
}
}
/// <summary>
/// 表现进度
/// </summary>
public float ShowProgress
{
get
{
if (null == loadingDisplay)
return Progress;
loadingDisplay.Update(Progress);
return loadingDisplay.ShowProgress;
}
}
/// <summary>
/// 是否等待中
/// </summary>
public bool IsWait
{
get
{
if (null == curLoadingExecutor)
return true;
return curLoadingExecutor.IsWait;
}
set
{
curLoadingExecutor.IsWait = value;
}
}
#endregion
public void Init()
{
loadingDisplay = new();
}
public void Release()
{
loadingDisplay = null;
}
/// <summary>
/// 开始加载
/// </summary>
/// <param name="executer"></param>
/// <param name="changeProgressTime"></param>
/// <param name="loadingCompleteWaitTime"></param>
/// <returns></returns>
public async UniTask ExecuteLoading(LoadingExecutor executer, float changeProgressTime = 1f, float loadingCompleteWaitTime = 0.2f)
{
if (null == executer)
{
DebugUtil.LogError("错误,启动空的加载器");
return;
}
if (IsRuning)
{
DebugUtil.LogError("错误,有加载器没有加载完");
return;
}
loadingDisplay.SetInfo(changeProgressTime, loadingCompleteWaitTime);
curLoadingExecutor = executer;
await curLoadingExecutor.Excute(changeProgressTime + loadingCompleteWaitTime);
}
}
/// <summary>
/// loading界面类型
/// </summary>
public enum E_LoadingType
{
/// <summary>
/// 登录游戏
/// </summary>
Login,
/// <summary>
/// 通用加载
/// </summary>
CommonLoading,
}
/// <summary>
/// 加载结果
/// </summary>
public enum E_LoadingResult
{
/// <summary>
/// 完成加载
/// </summary>
Success = 0,
/// <summary>
/// 加载出错(测试)
/// </summary>
ErrorTest = 1,
/// <summary>
/// 启动游戏时网络连接出错
/// </summary>
GameStartSevNetError = 2,
/// <summary>
/// 当前设备网络问题
/// </summary>
DeviceNetError = 3,
}
}

View File

@ -22,14 +22,6 @@ public class UI_LoadingInterfaceController : UIWindow
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_LoadingInterface);
}
/// <summary>
/// 打开加载界面
/// </summary>
public static async UniTask<UIWindow> Open(Action onLoadingEnd, Action onLoadingUIEnd)
{
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_LoadingInterface, (onLoadingEnd, onLoadingUIEnd));
}
/// <summary>
/// 背景
/// </summary>
@ -48,27 +40,11 @@ public class UI_LoadingInterfaceController : UIWindow
/// 更新提示文本
/// </summary>
private GameObject goUpdateText;
private float lastUpdate = 0f;
/// <summary>
/// 显示进度
/// </summary>
private float displayProgress = 0f;
private bool loadResEnd;
/// <summary>
/// 加载显示数据
/// </summary>
private DataLoadinfCfg loadingData;
/// <summary>
/// 加载结束回调
/// </summary>
public Action OnLoadingEnd { get; set; }
/// <summary>
/// 加载UI结束回调
/// </summary>
public Action OnLoadingUIEnd { get; set; }
public override async void PreLoad(object data = null)
{
if (null == TableManager.Instance.Tables)
@ -90,49 +66,26 @@ public class UI_LoadingInterfaceController : UIWindow
textProgess = GetComponent<TMP_Text>("Slider/Handle Slide Area/Handle/Text_Progress");
textTitle = GetComponent<TMP_Text>("Text_Title");
textContent = GetComponent<TMP_Text>("Text_Info");
EventManager.Instance.Register(EventManager.EventName.LoadingExecutorComplete, OnLoadingComplete);
}
protected override void OnShowWindow(object data = null)
{
if (data is ValueTuple<Action, Action> callback)
{
OnLoadingEnd = callback.Item1;
OnLoadingUIEnd = callback.Item2;
}
goUpdateText.IsScaleShow(false);
displayProgress = 0f;
SetPrecentageShow(displayProgress);
SetPrecentageShow(0f);
RefreshUI();
}
protected override async void OnUpdate()
protected override void OnUpdate()
{
if (IsHide())
return;
LoadingExecutor currentExcutor = LoadingExecutorManager.Instance.CurrentExcutor;
if (currentExcutor != null)
{
currentExcutor.RefreshProgress();
LoadingText();
if (displayProgress < currentExcutor.DestProgress)
{
float diffValue = currentExcutor.DestProgress - displayProgress;
float deltaValue;
if (!LoadingManager.Instance.IsRuning)
return;
if (loadResEnd) //资源文件下载完后进度条最小走1
deltaValue = Mathf.Max(1f, diffValue * 0.1f);
else if (diffValue < 0.5f) //资源下载过程中进度条精确到小数点后2位
deltaValue = Mathf.Max(0.02f, diffValue * 0.1f);
else
deltaValue = Mathf.Max(0.1f, diffValue * 0.1f);
displayProgress += deltaValue;
displayProgress = Mathf.Min(100f, displayProgress);
await SetLoadingPrecentage(displayProgress);
}
}
SetPrecentageShow(LoadingManager.Instance.ShowProgress);
}
protected override void OnHideWindow()
@ -149,6 +102,13 @@ public class UI_LoadingInterfaceController : UIWindow
base.OnHideWindow();
}
public override void OnRelease()
{
EventManager.Instance.Unregister(EventManager.EventName.LoadingExecutorComplete, OnLoadingComplete);
base.OnRelease();
}
public override async UniTask<bool> OnBack(object data = null)
{
await UniTask.Yield();
@ -156,34 +116,6 @@ public class UI_LoadingInterfaceController : UIWindow
return false;
}
private async void LoadingText()
{
const float EPSINON = 0.000001f;
if (Math.Abs(lastUpdate) < EPSINON)
await SetLoadingPrecentage(0f);
if (Math.Abs(lastUpdate) < EPSINON || Time.unscaledTime > (lastUpdate + 5f))
lastUpdate = Time.unscaledTime;
}
/// <summary>
/// 设置加载进度
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
private async UniTask SetLoadingPrecentage(float num)
{
SetPrecentageShow(num * 0.01f);
if (num >= 100f)
{
await UniTask.NextFrame();
OnLoadingEnd?.Invoke();
OnLoadingUIEnd?.Invoke();
CloseWindow();
}
}
/// <summary>
/// 设置加载显示
/// </summary>
@ -196,12 +128,6 @@ public class UI_LoadingInterfaceController : UIWindow
textProgess.text = $"{progress:P0}";
}
public void SetAction(Action loadingEnd, Action loadingUIEnd)
{
OnLoadingEnd = loadingEnd;
OnLoadingUIEnd = loadingUIEnd;
}
private void RefreshUI()
{
if (null == loadingData)
@ -211,4 +137,12 @@ public class UI_LoadingInterfaceController : UIWindow
textContent.text = CommonUtils.GetLocalizeText(loadingData.ContentText);
imageBg.sprite = AssetManager.Instance.GetPreLoadResult<Sprite>(loadingData.BGPath);
}
/// <summary>
/// 加载完成
/// </summary>
private void OnLoadingComplete()
{
CloseWindow();
}
}

View File

@ -10,20 +10,15 @@ using System.Text;
using PhxhSDK;
using YooAsset;
using System.IO;
using Framework;
public class UI_LoadingProgressInterfaceController : UIWindow
{
public static async UniTask<UIWindow> Open()
{
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_LoadingProgressInterface);
}
LoadingManager.Instance.IsWait = true;
/// <summary>
/// 打开加载界面
/// </summary>
public static async UniTask<UIWindow> Open(Action onLoadingEnd, Action onLoadingUIEnd)
{
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_LoadingProgressInterface, (onLoadingEnd, onLoadingUIEnd));
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_LoadingProgressInterface);
}
#region UI
@ -58,13 +53,6 @@ public class UI_LoadingProgressInterfaceController : UIWindow
/// 多少秒后显示进度条
/// </summary>
private const float LATER_SHOW_PROGRESS_TIME = 2f;
/// <summary>
/// 进度条最小显示时间
/// </summary>
private const float PROGRESS_SHOW_TIME = 0.1f;
/// <summary>
/// 显示计时器
/// </summary>
private float timer;
private StringBuilder sb;
/// <summary>
@ -72,16 +60,6 @@ public class UI_LoadingProgressInterfaceController : UIWindow
/// </summary>
private RenderTexture renderTexture;
/// <summary>
/// 加载结束回调
/// </summary>
public Action OnLoadingEnd { get; set; }
/// <summary>
/// 加载UI结束回调
/// </summary>
public Action OnLoadingUIEnd { get; set; }
/// <summary>
/// 是否显示进度条
/// </summary>
@ -112,30 +90,20 @@ public class UI_LoadingProgressInterfaceController : UIWindow
videoPlayer.loopPointReached += OnEndPlayer;
videoPlayer.prepareCompleted += OnPreCompleted;
videoPlayer.errorReceived += OnErrorReceived;
EventManager.Instance.Register(EventManager.EventName.LoadingExecutorComplete, OnLoadingComplete);
}
protected override async void OnShowWindow(object data)
{
base.OnShowWindow(data);
timer = 0f;
rawImageBg.color = Color.black;
IsShowProgess = false;
renderTexture.Release();
videoPlayer.Stop();
timer = 0f;
SetPrecentageShow(0f);
if (data is ValueTuple<Action, Action> callback)
{
OnLoadingEnd = callback.Item1;
OnLoadingUIEnd = callback.Item2;
}
else
{
OnLoadingEnd = null;
OnLoadingUIEnd = null;
}
string mp4Path;
RawFileHandle rawFileHandle = AssetManager.Instance.LoadRawFileAsync(LOADING_VIDEO);
await rawFileHandle;
@ -158,13 +126,12 @@ public class UI_LoadingProgressInterfaceController : UIWindow
videoPlayer.Prepare();
}
protected override async void OnUpdate()
protected override void OnUpdate()
{
if (IsHide())
return;
LoadingExecutor currentExcutor = LoadingExecutorManager.Instance.CurrentExcutor;
if (null == currentExcutor)
if (!LoadingManager.Instance.IsRuning)
{
if (videoPlayer.isPlaying)
videoPlayer.Stop();
@ -185,19 +152,14 @@ public class UI_LoadingProgressInterfaceController : UIWindow
timer = (float)videoPlayer.time;
if (timer >= LATER_SHOW_PROGRESS_TIME)
{
currentExcutor.IsWait = false;
LoadingManager.Instance.IsWait = false;
IsShowProgess = true;
}
}
else
timer += Time.deltaTime;
float percentage = Mathf.Min(timer - LATER_SHOW_PROGRESS_TIME, PROGRESS_SHOW_TIME) / PROGRESS_SHOW_TIME;
currentExcutor.RefreshProgress();
if(currentExcutor.DestProgress >= 100f)
await SetLoadingPrecentage(currentExcutor.DestProgress);
else
await SetLoadingPrecentage(currentExcutor.DestProgress * percentage);
SetPrecentageShow(LoadingManager.Instance.ShowProgress);
}
public override async UniTask<bool> OnBack(object data = null)
@ -210,27 +172,11 @@ public class UI_LoadingProgressInterfaceController : UIWindow
public override void OnRelease()
{
RenderTexturePool.Instance.Destroy(renderTexture);
EventManager.Instance.Unregister(EventManager.EventName.LoadingExecutorComplete, OnLoadingComplete);
base.OnRelease();
}
/// <summary>
/// 设置加载进度
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
private async UniTask SetLoadingPrecentage(float num)
{
SetPrecentageShow(num * 0.01f);
if (num >= 100f)
{
await UniTask.Yield();
OnLoadingEnd?.Invoke();
OnLoadingUIEnd?.Invoke();
HideWindow();
}
}
/// <summary>
/// 设置加载显示
/// </summary>
@ -281,4 +227,12 @@ public class UI_LoadingProgressInterfaceController : UIWindow
{
DebugUtil.LogError($"加载视频播放错误:{message}");
}
/// <summary>
/// 加载完成
/// </summary>
private void OnLoadingComplete()
{
CloseWindow();
}
}

View File

@ -1341,7 +1341,7 @@ public class UICameraAndPosterChangeController : UIWindow
{
oldSaveData.SceneIdx = _saveData.SceneIdx;
oldSaveData.CameraPosIdx = _saveData.CameraPosIdx;
LoadingExecutorManager.Instance.ExecuteLoading(new MainSceneReLoadingExecutor()).Forget();
LoadingManager.Instance.ExecuteLoading(new MainSceneReLoadingExecutor()).Forget();
DebugUtil.Log("保存场景调整数据,当前场景: " + _saveData.SceneIdx);
}
StorageMgr.Instance.SyncForce = true;

View File

@ -1576,11 +1576,9 @@ public class UI_MainPanelController : UIWindow
/// <summary>
/// 营地
/// </summary>
private async void OnCamp()
private void OnCamp()
{
await OpenUIWithScene(UINameConst.UI_Camp, Framework.Constants.CAMP_SCENE_PATH, null, true, LoadSceneMode.Single);
ShowManager.Instance.RefreshShow(E_ShowSceneType.Camp);
GameStateManager.Instance.ChangeState(new GameStateCampScene());
}
private async void OnNotice()

View File

@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using Gameplay.SubSystems;
namespace Gameplay.UI
{
@ -16,6 +17,7 @@ namespace Gameplay.UI
UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_LoadingProgressInterface, false);
}
break;
case E_LoadingType.CommonLoading:
default:
{
UIWindow ui = await UI_LoadingInterfaceController.Open();

View File

@ -1550,16 +1550,16 @@ namespace Gameplay
Action<SceneHandle> loadSceneFinish = null)
{
//隐藏上层UI
UIManager.Instance.HideAllUI(UINameConst.UI_LoadingInterface);
UIManager.Instance.HideAllUI(UINameConst.UI_LoadingInterface, UINameConst.UI_LoadingProgressInterface);
//先加载场景
if (openLoadingUI)
{
{/*
//如果要打开加载UI
LoadingExecutorWithUILoadingController loadingExecutor = new()
{
getProgress = () => GameSceneManager.Instance.GetSceneLoadingProgress(scenePath)
GetProgress = () => GameSceneManager.Instance.GetSceneLoadingProgress(scenePath)
};
await LoadingExecutorManager.Instance.ExecuteLoading(loadingExecutor);
await LoadingManager.Instance.ExecuteLoading(loadingExecutor);*/
}
SceneHandle sceneHandle = await GameSceneHelper.Instance.LoadSceneForUIView(scenePath, loadSceneMode);