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.
83 lines
3.4 KiB
83 lines
3.4 KiB
using FairyGUI; |
|
using UnityEngine; |
|
|
|
namespace ET |
|
{ |
|
using FUIUnitName; |
|
public class SceneChangeStart_AddComponent: AEvent<EventType.SceneChangeStart> |
|
{ |
|
protected override void Run(EventType.SceneChangeStart args) |
|
{ |
|
RunAsync(args).Coroutine(); |
|
} |
|
private async ETTask RunAsync(EventType.SceneChangeStart args) |
|
{ |
|
|
|
Scene currentScene = args.ZoneScene.CurrentScene(); |
|
|
|
// 加载场景资源 |
|
// await ResourcesComponent.Instance.LoadBundleAsync($"{currentScene.Name}.unity3d"); |
|
// 切换到map场景 |
|
|
|
SceneChangeComponent sceneChangeComponent = null; |
|
try |
|
{ |
|
sceneChangeComponent = Game.Scene.AddComponent<SceneChangeComponent>(); |
|
{ |
|
await sceneChangeComponent.ChangeSceneAsync(currentScene.Name); |
|
} |
|
} |
|
finally |
|
{ |
|
sceneChangeComponent?.Dispose(); |
|
} |
|
|
|
currentScene.AddComponent<GameSceneManagerComponent>(); |
|
currentScene.AddComponent<MapComponent>(); |
|
currentScene.AddComponent<CameraComponent>(); |
|
currentScene.AddComponent<OperationComponent>(); |
|
currentScene.AddComponent<BattleSceneViewComponent>(); |
|
|
|
|
|
Unit unit = UnitComponent.unit; |
|
|
|
// show name ui |
|
var fuiPkgComponent = unit.ZoneScene().GetComponent<FUIPackageComponent>(); |
|
fuiPkgComponent.AddPackage(FUIPackage.Common); |
|
var nameComp = await unit.ZoneScene().GetComponent<FUIComponent>().ShowUIAsync<FUI_UnitNamePanel, FUIUnitNamePanelComponent>(FUI_UnitNamePanel.UIPackageName); |
|
|
|
|
|
// 需要上面的Unit创建消息发送完进行初始化,才能进行下面其它东西的创建消息 |
|
BuildingComponent buildingComponent = unit.GetComponent<BuildingComponent>(); |
|
foreach (var building in buildingComponent.Children) |
|
{ |
|
Game.EventSystem.Publish(new EventType.AfterCreateBuilding() { Unit = unit, Building = (Building)building.Value }); |
|
} |
|
|
|
var cc = unit.GetComponent<ConstructComponent>(); |
|
if (cc != null) |
|
{ |
|
foreach (var construct in cc.Children) |
|
{ |
|
Game.EventSystem.Publish(new EventType.AfterCreateConstruct() { Unit = unit, Construct = (Construct)construct.Value}); |
|
} |
|
} |
|
|
|
var rc = unit.GetComponent<ResourcePointComponent>(); |
|
foreach (var resPair in rc.Children) |
|
{ |
|
Game.EventSystem.Publish(new EventType.AfterCreateResource(){Unit = unit, Resource = (ResourcePoint)resPair.Value}); |
|
} |
|
|
|
// 人的View放在最后面,因为要安排他们去资源和建筑上工作 |
|
var pc = unit.GetComponent<PeopleComponent>(); |
|
foreach (var v in pc.Children) |
|
{ |
|
Game.EventSystem.Publish(new EventType.AfterCreatePeople() { Unit = unit, People = (People)v.Value }); |
|
} |
|
|
|
Game.EventSystem.Publish(new EventType.SceneChangeFinish() {ZoneScene = args.ZoneScene, CurrentScene = currentScene}); |
|
args.ZoneScene.GetComponent<ObjectWait>().Notify(new WaitType.Wait_SceneChangeFinish()); |
|
} |
|
} |
|
} |