Files
TEngine/Assets/GameScripts/DotNet/Hotfix/Client/Demo/Main/Scene/SceneChangeHelper.cs
ALEXTANG 336d4b2eb9 [+] 接入ET8服务端
[+] 接入ET8服务端
2023-07-13 12:23:48 +08:00

29 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace ET.Client
{
public static partial class SceneChangeHelper
{
// 场景切换协程
public static async ETTask SceneChangeTo(Scene root, string sceneName, long sceneInstanceId)
{
root.RemoveComponent<AIComponent>();
CurrentScenesComponent currentScenesComponent = root.GetComponent<CurrentScenesComponent>();
currentScenesComponent.Scene?.Dispose(); // 删除之前的CurrentScene创建新的
Scene currentScene = CurrentSceneFactory.Create(sceneInstanceId, sceneName, currentScenesComponent);
UnitComponent unitComponent = currentScene.AddComponent<UnitComponent>();
// 可以订阅这个事件中创建Loading界面
EventSystem.Instance.Publish(root, new EventType.SceneChangeStart());
// 等待CreateMyUnit的消息
Wait_CreateMyUnit waitCreateMyUnit = await root.GetComponent<ObjectWait>().Wait<Wait_CreateMyUnit>();
M2C_CreateMyUnit m2CCreateMyUnit = waitCreateMyUnit.Message;
Unit unit = UnitFactory.Create(currentScene, m2CCreateMyUnit.Unit);
unitComponent.Add(unit);
root.RemoveComponent<AIComponent>();
EventSystem.Instance.Publish(currentScene, new EventType.SceneChangeFinish());
// 通知等待场景切换的协程
root.GetComponent<ObjectWait>().Notify(new Wait_SceneChangeFinish());
}
}
}