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.
109 lines
4.0 KiB
109 lines
4.0 KiB
3 years ago
|
using System;
|
||
|
using ET.EventType;
|
||
|
using FairyGUI;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace ET
|
||
|
{
|
||
|
using FUIBuilding;
|
||
|
public class CreateBuildingViewComponentAwakeSystem : AwakeSystem<CreateBuildingViewComponent>
|
||
|
{
|
||
|
public override void Awake(CreateBuildingViewComponent self)
|
||
|
{
|
||
|
self.Awake();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public class CreateBuildingViewComponentUpdateSystem : UpdateSystem<CreateBuildingViewComponent>
|
||
|
{
|
||
|
public override void Update(CreateBuildingViewComponent self)
|
||
|
{
|
||
|
self.Update();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public class CreateBuildingViewComponentDestorySystem : DestroySystem<CreateBuildingViewComponent>
|
||
|
{
|
||
|
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<SpriteRenderer>();
|
||
|
|
||
|
// 显示编辑按钮
|
||
|
self.EditUI = self.ZoneScene().GetComponent<FUIComponent>()
|
||
|
.ShowWindow<FUI_BuildingEdit, FUIBuildingEditComponent>();
|
||
|
self.EditUI.OnCreateBuildingConfirm = self.OnCreateBuildingConfirm;
|
||
|
self.EditUI.OnCreateBuildingCancle = self.OnCreateBuildingCancel;
|
||
|
|
||
|
var mapUnitOper = self.Parent.AddComponent<MapUnitOperationComponent>();
|
||
|
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<MapUnitOperationComponent>();
|
||
|
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<MapUnitOperationComponent>();
|
||
|
}
|
||
|
|
||
|
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)
|
||
|
{
|
||
|
Unit unit = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene());
|
||
|
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");
|
||
|
}
|
||
|
|
||
|
// 删除临时的建筑
|
||
|
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});
|
||
|
}
|
||
|
}
|
||
|
}
|