Files
2025-01-25 04:38:09 +08:00

114 lines
3.2 KiB
C#

using System.Collections;
using Thousandto.Code.Center;
using Thousandto.Code.Global;
using Thousandto.Core.Asset;
using UnityEngine;
using UnityEngine.SceneManagement;
using CoroutinePool = UnityEngine.Gonbest.MagicCube.CoroutinePool;
namespace Thousandto.Code.Logic
{
public class RetToUpdateState : GameStateBase
{
#region//构造函数
public RetToUpdateState(GameStateId id) : base(id)
{
}
#endregion
#region//重写父类GameStateBase的函数
protected override GameStateId OnGetStateID()
{
return GameStateId.RetToUpdate;
}
protected override void OnLoad()
{
}
protected override void OnRelease()
{
}
protected override void OnEnter()
{
GameCenter.HeartSystem.SendReqQuit();
//打开Loading窗体
GameCenter.LuaSystem.Adaptor.OpenLoadingForm(() => {
//先关闭所有窗体
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_CLOSE_ALL_FORM, new string[] { "UILoadingForm" });
//1.清理逻辑型数据
GameCenter.ResetLogicSystem(true);
GameCenter.GameSceneSystem.ClearMapID();
CoroutinePool.AddTask(ReturnToUpdateProcess());
});
}
protected override void OnLeave()
{
}
protected override bool OnUpdate(float deltaTime)
{
return true;
}
#endregion
#region//私有方法
//切换到开始场景的一些处理
private IEnumerator ReturnToUpdateProcess()
{
try
{
yield return null;
GameCenter.LuaSystem.Adaptor.SetLoadingFormProgress(0.3f);
GameCenter.GameSceneSystem.SetImmortalInfo(true);
LocalPlayerRoot.Uninitialize();
//清除其他Prefab
GameCenter.GameSceneSystem.SceneSweepPrefab();
yield return null;
//清除所有非激活窗体
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_CLEAR_ALL_FORM_ASSET);
yield return null;
//5.删除所有没有使用的资源
Resources.UnloadUnusedAssets();
GameCenter.LuaSystem.Adaptor.SetLoadingFormProgress(0.7f);
yield return null;
//切换到一个中间型场景
SceneManager.LoadScene(AssetConstDefine.SceneOffName);
GameCenter.LuaSystem.Adaptor.SetLoadingFormProgress(0.9f);
yield return null;
GameCenter.GameSceneSystem.SceneSweepAsset();
yield return null;
}
finally
{
//GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_RESUME_FORM_EVENT_SYSTEM);
//切换到更新场景
#if UNITY_EDITOR
SceneManager.LoadScene("Start");
#else
SceneManager.LoadScene("Update");
#endif
GameCenter.LuaSystem.Adaptor.SetLoadingFormProgress(1f);
GameCenter.LuaSystem.Adaptor.CloseLoadingForm();
}
}
#endregion
}
}