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.
107 lines
4.3 KiB
107 lines
4.3 KiB
using ET.EventType; |
|
using ET.FUIBuilding; |
|
using ET.FUIMain; |
|
using UnityEngine; |
|
|
|
namespace ET |
|
{ |
|
public class UseSaplingItemComponentAwakeSystem: AwakeSystem<UseSaplingItemComponent> |
|
{ |
|
public override void Awake(UseSaplingItemComponent self) |
|
{ |
|
self.Awake(); |
|
} |
|
} |
|
|
|
public class UseSaplingItemComponentDestroySystem: DestroySystem<UseSaplingItemComponent> |
|
{ |
|
public override void Destroy(UseSaplingItemComponent self) |
|
{ |
|
self.Destroy(); |
|
} |
|
} |
|
|
|
[FriendClass(typeof(UseSaplingItemComponent))] |
|
[FriendClass(typeof(MapComponent))] |
|
[FriendClass(typeof(FUIBuildingEditComponent))] |
|
[FriendClass(typeof(MapUnitOperationComponent))] |
|
public static class UseSaplingItemComponentSystem |
|
{ |
|
public static void Awake(this UseSaplingItemComponent self) |
|
{ |
|
|
|
} |
|
|
|
public static void Edit(this UseSaplingItemComponent self, int saplingConfigId, int itemId) |
|
{ |
|
Unit unit = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()); |
|
Game.EventSystem.Publish(new EnterCreateResourceEdit(){ Unit = unit}); |
|
self.CurEditSaplingId = saplingConfigId; |
|
var saplingConfig = SaplingConfigCategory.Instance.Get(self.CurEditSaplingId); |
|
var resourceConfig = ResourcesPointConfigCategory.Instance.Get(saplingConfig.RelatedResourcesPoint); |
|
var mapComp = self.ZoneScene().CurrentScene().GetComponent<MapComponent>(); |
|
var prefabName = resourceConfig.Prefab[0].ToPrefabAddress(); |
|
GameObject resGO = self.InstantiateSync(prefabName, mapComp.BuildingRoot); |
|
self.CurEditResourceRoot = resGO.transform; |
|
self.CurEditResourceId = saplingConfig.RelatedResourcesPoint; |
|
self.ItemId = itemId; |
|
var resourceSR = self.CurEditResourceRoot.GetComponentInChildren<SpriteRenderer>(); |
|
|
|
// 显示编辑按钮 |
|
self.EditUI = self.ZoneScene().GetComponent<FUIComponent>() |
|
.ShowWindow<FUI_BuildingEdit, FUIBuildingEditComponent>(); |
|
self.EditUI.OnCreateBuildingConfirm = self.OnCreateResourceConfirm; |
|
self.EditUI.OnCreateBuildingCancle = self.OnCreateResourceCancel; |
|
|
|
var mapUnitOper = self.Parent.AddComponent<MapUnitOperationComponent>(); |
|
mapUnitOper.Edit(self.CurEditResourceRoot, resourceSR); |
|
// 默认设置到屏幕中间 |
|
mapUnitOper.UpdateUnitPos(new Vector2(Screen.width / 2 , Screen.height / 2)); |
|
mapUnitOper.UnitPosUpdate += self.UpdateEditUIPos; |
|
// 设置编辑按钮位置 |
|
self.UpdateEditUIPos(); |
|
} |
|
|
|
public static void Destroy(this UseSaplingItemComponent self) |
|
{ |
|
self.Parent.RemoveComponent<MapUnitOperationComponent>(); |
|
} |
|
|
|
public static void UpdateEditUIPos(this UseSaplingItemComponent self) |
|
{ |
|
var mapUnitOper = self.Parent.GetComponent<MapUnitOperationComponent>(); |
|
self.EditUI.SetConfirmButtonPos(mapUnitOper.GetMidLeftPos()); |
|
self.EditUI.SetCancelButtonPos(mapUnitOper.GetMidRightPos()); |
|
} |
|
|
|
public static void OnCreateResourceConfirm(this UseSaplingItemComponent self) |
|
{ |
|
self.CreateResource().Coroutine(); |
|
} |
|
|
|
public static async ETTask CreateResource(this UseSaplingItemComponent self) |
|
{ |
|
Unit unit = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()); |
|
var pos = self.CurEditResourceRoot.position; |
|
int errorCode = await StoreHelper.UseSaplingItem(unit, self.ItemId, pos.x, pos.y); |
|
if (errorCode != ErrorCode.ERR_Success) |
|
{ |
|
Debug.LogWarning("Create Resource Failed"); |
|
} |
|
|
|
// 删除临时的建筑 |
|
GameObject.Destroy(self.CurEditResourceRoot.gameObject); |
|
|
|
Game.EventSystem.Publish(new QuitCreateResourceEdit() { Unit = unit}); |
|
} |
|
|
|
public static void OnCreateResourceCancel(this UseSaplingItemComponent self) |
|
{ |
|
GameObject.Destroy(self.CurEditResourceRoot.gameObject); |
|
|
|
Unit unit = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()); |
|
Game.EventSystem.Publish(new QuitCreateResourceEdit(){ Unit = unit}); |
|
} |
|
|
|
} |
|
}
|
|
|