You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.8 KiB

namespace ET
{
public static class SceneChangeHelper
{
// 场景切换协程
public static void SceneChangeTo(Scene zoneScene, M2C_CreateMyUnit msg)
{
zoneScene.RemoveComponent<AIComponent>();
CurrentScenesComponent currentScenesComponent = zoneScene.GetComponent<CurrentScenesComponent>();
currentScenesComponent.Scene?.Dispose(); // 删除之前的CurrentScene,创建新的
Scene currentScene = SceneFactory.CreateCurrentScene(msg.SceneInstanceId, zoneScene.Zone, msg.SceneName, currentScenesComponent);
//UnitComponent unitComponent = currentScene.AddComponent<UnitComponent>();
//unit 初始化
UnitComponent unitComponent = currentScene.AddComponent<UnitComponent>();
Unit unit = UnitFactory.Create(currentScene, msg.Unit);
unitComponent.Add(unit);
// 可以订阅这个事件中创建Loading界面
Game.EventSystem.Publish(new EventType.SceneChangeStart() {ZoneScene = zoneScene});
/*
// 等待CreateMyUnit的消息
WaitType.Wait_CreateMyUnit waitCreateMyUnit = await zoneScene.GetComponent<ObjectWait>().Wait<WaitType.Wait_CreateMyUnit>();
M2C_CreateMyUnit m2CCreateMyUnit = waitCreateMyUnit.Message;
Unit unit = UnitFactory.Create(currentScene, m2CCreateMyUnit.Unit);
unitComponent.Add(unit);
zoneScene.RemoveComponent<AIComponent>();
Game.EventSystem.Publish(new EventType.SceneChangeFinish() {ZoneScene = zoneScene, CurrentScene = currentScene});
// 通知等待场景切换的协程
zoneScene.GetComponent<ObjectWait>().Notify(new WaitType.Wait_SceneChangeFinish());
*/
}
}
}