using System; using ET.EventType; using FairyGUI; using UnityEngine; namespace ET { using FUIBuilding; public class CreateBuildingViewComponentAwakeSystem : AwakeSystem { public override void Awake(CreateBuildingViewComponent self) { self.Awake(); } } public class CreateBuildingViewComponentUpdateSystem : UpdateSystem { public override void Update(CreateBuildingViewComponent self) { self.Update(); } } public class CreateBuildingViewComponentDestorySystem : DestroySystem { public override void Destroy(CreateBuildingViewComponent self) { self.Destroy(); } } [FriendClass(typeof(CreateBuildingViewComponent))] [FriendClass(typeof(FUIBuildingEditComponent))] [FriendClass(typeof(MapUnitOperationComponent))] public static class CreateBuildingViewComponentSystem { public static void Edit(this CreateBuildingViewComponent self, Transform buildingRoot, int buildingSynthesisId) { self.CurEditBuildingRoot = buildingRoot; self.CurEditBuildingSynthesisId = buildingSynthesisId; var buildingSR = self.CurEditBuildingRoot.GetComponentInChildren(); // 显示编辑按钮 self.EditUI = self.ZoneScene().GetComponent() .ShowWindow(); self.EditUI.OnCreateBuildingConfirm = self.OnCreateBuildingConfirm; self.EditUI.OnCreateBuildingCancle = self.OnCreateBuildingCancel; var mapUnitOper = self.Parent.AddComponent(); mapUnitOper.Edit(buildingRoot, buildingSR); // 默认设置到屏幕中间 mapUnitOper.UpdateUnitPos(new Vector2(Screen.width / 2 , Screen.height / 2)); mapUnitOper.UnitPosUpdate += self.UpdateEditUIPos; // 设置编辑按钮位置 self.UpdateEditUIPos(); } public static void UpdateEditUIPos(this CreateBuildingViewComponent self) { var mapUnitOper = self.Parent.GetComponent(); self.EditUI.SetConfirmButtonPos(mapUnitOper.GetMidLeftPos()); self.EditUI.SetCancelButtonPos(mapUnitOper.GetMidRightPos()); } public static void Awake(this CreateBuildingViewComponent self) { } public static void Destroy(this CreateBuildingViewComponent self) { self.Parent.RemoveComponent(); } public static void Update(this CreateBuildingViewComponent self) { } public static void OnCreateBuildingConfirm(this CreateBuildingViewComponent self) { self.CreateBuilding().Coroutine(); } public static async ETTask CreateBuilding(this CreateBuildingViewComponent self) { var mapUnitOper = self.Parent.GetComponent(); Unit unit = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()); if (mapUnitOper.IsPlaceValid()) { var pos = self.CurEditBuildingRoot.position; int errorCode = await ConstructHelper.CreateConstruct(unit, self.CurEditBuildingSynthesisId, pos.x, pos.y); if (errorCode != ErrorCode.ERR_Success) { Debug.LogWarning("Create Building Failed"); } } else { CommonHelper.ShowHint(self.ZoneScene(), TextHelper.Building_Place_Invalid); } // 删除临时的建筑 GameObject.Destroy(self.CurEditBuildingRoot.gameObject); Game.EventSystem.Publish(new QuitCreateBuildingEdit() { Unit = unit}); } public static void OnCreateBuildingCancel(this CreateBuildingViewComponent self) { GameObject.Destroy(self.CurEditBuildingRoot.gameObject); Unit unit = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()); Game.EventSystem.Publish(new QuitCreateBuildingEdit(){ Unit = unit}); } } }