|
|
|
using FairyGUI;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
{
|
|
|
|
using FUIResource;
|
|
|
|
using FUIUnitName;
|
|
|
|
public class ResourceViewComponentAwakeSystem : AwakeSystem<ResourceViewComponent>
|
|
|
|
{
|
|
|
|
public override void Awake(ResourceViewComponent self)
|
|
|
|
{
|
|
|
|
self.Awake();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ResourceViewComponentDestroySystem : DestroySystem<ResourceViewComponent>
|
|
|
|
{
|
|
|
|
public override void Destroy(ResourceViewComponent self)
|
|
|
|
{
|
|
|
|
self.Destory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[FriendClass(typeof(ResourceViewComponent))]
|
|
|
|
[FriendClass(typeof(ResourcePoint))]
|
|
|
|
[FriendClass(typeof(MapComponent))]
|
|
|
|
[FriendClass(typeof(FUI_ResourceName))]
|
|
|
|
[FriendClass(typeof(FUIUnitNamePanelComponent))]
|
|
|
|
[FriendClass(typeof(FUI_UnitNamePanel))]
|
|
|
|
[FriendClass(typeof(GlobalComponent))]
|
|
|
|
[FriendClass(typeof(OperationComponent))]
|
|
|
|
public static class ResourceViewComponentSystem
|
|
|
|
{
|
|
|
|
public static void Awake(this ResourceViewComponent self)
|
|
|
|
{
|
|
|
|
var res = self.GetParent<ResourcePoint>();
|
|
|
|
self.CreateResource(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void CreateResource(this ResourceViewComponent self, ResourcePoint resource)
|
|
|
|
{
|
|
|
|
self.Resource = resource;
|
|
|
|
var resourcePointConfig = resource.Config;
|
|
|
|
|
|
|
|
var mapComp = self.ZoneScene().CurrentScene().GetComponent<MapComponent>();
|
|
|
|
if (string.IsNullOrEmpty(resourcePointConfig.Prefab[0]))
|
|
|
|
{
|
|
|
|
Log.Warning($"[{resourcePointConfig.Id}]: {resourcePointConfig.ResourcesPointName} has no prefab");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var prefabName = resourcePointConfig.Prefab[0].ToPrefabAddress();
|
|
|
|
GameObject resGO = self.InstantiateSync(prefabName, mapComp.ResourceRoot);
|
|
|
|
|
|
|
|
resGO.transform.position = new Vector3(resource.Position.x, resource.Position.y, 0);
|
|
|
|
self.ResourceRoot = resGO;
|
|
|
|
|
|
|
|
var sprRender = self.ResourceRoot.GetComponentInChildren<SpriteRenderer>();
|
|
|
|
Vector2Int size = mapComp.GetSizeBySpriteCollider(sprRender);
|
|
|
|
|
|
|
|
#if CLIENTTEST
|
|
|
|
var indicator = BuildingViewHelper.CreateOcupyPlaceInicator("OccupyPlaceInidcator", new Color(1, 0, 0, 0.3f));
|
|
|
|
indicator.transform.parent = self.ResourceRoot.transform;
|
|
|
|
indicator.transform.localPosition = Vector3.zero;
|
|
|
|
BuildingViewHelper.UpdateIndicatorLocal(indicator, mapComp, resGO.transform.position, size);
|
|
|
|
#endif
|
|
|
|
// 创建怪物图标
|
|
|
|
if (resource.MonsterGroupId > 0)
|
|
|
|
{
|
|
|
|
self.Parent.AddComponent<ResourceMonsterGroupViewComponent, long>(resource.MonsterGroupId);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新占位
|
|
|
|
mapComp.MarkPlaceOnGrid(self.ResourceRoot.transform.position, size);
|
|
|
|
Physics2D.SyncTransforms();
|
|
|
|
mapComp.UpdateNavMesh2d();
|
|
|
|
|
|
|
|
EventTrigger trigger = self.ResourceRoot.transform.Find("Resource_Base/SpriteClick").GetComponent<EventTrigger>();
|
|
|
|
EventTrigger.Entry entry = new EventTrigger.Entry();
|
|
|
|
entry.eventID = EventTriggerType.PointerClick;
|
|
|
|
entry.callback.AddListener((data) =>
|
|
|
|
{
|
|
|
|
self.OnSpriteClicked(self);
|
|
|
|
});
|
|
|
|
trigger.triggers.Add(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Vector2 GetNamePos(this ResourceViewComponent self)
|
|
|
|
{
|
|
|
|
var sprRender = self.ResourceRoot.GetComponentInChildren<SpriteRenderer>();
|
|
|
|
Vector3 max = sprRender.bounds.max;
|
|
|
|
Vector3 min = sprRender.bounds.min;
|
|
|
|
|
|
|
|
return new Vector2((min.x + max.x) / 2, max.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async ETTask CreateName(this ResourceViewComponent self)
|
|
|
|
{
|
|
|
|
if (self.ResourceRoot == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FUI_ResourceName nameEntity =
|
|
|
|
await FUIHelper.CreateInstanceAsync<FUI_ResourceName>(self.Resource, FUI_ResourceName.UIPackageName, FUI_ResourceName.UIResName);
|
|
|
|
FUIUnitNamePanelComponent unitNamePanelComponent = FUIComponent.Instance.GetUI(FUI_UnitNamePanel.UIResName) as FUIUnitNamePanelComponent;
|
|
|
|
unitNamePanelComponent.FUIUnitNamePanel.FGComp.AddChild(nameEntity.FGComp);
|
|
|
|
|
|
|
|
nameEntity.m_Name.text = self.Resource.Config.ResourcesPointName;
|
|
|
|
self.UnitName = nameEntity;
|
|
|
|
|
|
|
|
self.UpdateNamePos();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void UpdateNamePos(this ResourceViewComponent self)
|
|
|
|
{
|
|
|
|
if (self.ResourceRoot == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.UnitName == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var topPos = self.GetNamePos();
|
|
|
|
var mainCamera = GlobalComponent.Instance.MainCamera.GetComponent<Camera>();
|
|
|
|
self.UnitName.FGComp.xy = FUIHelper.ConvertToUIPos(topPos);
|
|
|
|
self.UnitName.FGComp.scale = Vector2.one * 10 /mainCamera.orthographicSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsOnUI(this ResourceViewComponent self)
|
|
|
|
{
|
|
|
|
if (Stage.isTouchOnUI)
|
|
|
|
{
|
|
|
|
var unitNamePanel = FUIComponent.Instance.GetUI(FUI_UnitNamePanel.UIResName) as FUIUnitNamePanelComponent;
|
|
|
|
if (unitNamePanel != null && unitNamePanel.FUIUnitNamePanel.Visible)
|
|
|
|
{
|
|
|
|
if (unitNamePanel.FUIUnitNamePanel.FGComp.IsAncestorOf(GRoot.inst.touchTarget))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void OnSpriteClicked(this ResourceViewComponent self, ResourceViewComponent resourceViewComponent)
|
|
|
|
{
|
|
|
|
if (Stage.isTouchOnUI)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var operationComponent = self.ZoneScene().CurrentScene().GetComponent<OperationComponent>();
|
|
|
|
if (operationComponent.IsDragging)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var resource = resourceViewComponent.Resource;
|
|
|
|
|
|
|
|
// 如果有怪,则先进行打怪
|
|
|
|
// if (resource.MonsterGroupId > 0)
|
|
|
|
// {
|
|
|
|
// Unit unit = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene());
|
|
|
|
// BattleHelper.EnterBattle(unit, resource.MonsterGroupId, ConstBattleType.BATTLE_PVE).Coroutine();
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
var resourceWindowComp = self.ZoneScene().GetComponent<FUIComponent>().ShowWindow<FUI_ResourceWindow,FUIResourceWindowComponent>();
|
|
|
|
resourceWindowComp.ShowInfo(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Vector3 GetWorkerPos(this ResourceViewComponent self)
|
|
|
|
{
|
|
|
|
return self.ResourceRoot.transform.position;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void UpdateMonsterGroupInfo(this ResourceViewComponent self)
|
|
|
|
{
|
|
|
|
if (self.Resource.MonsterGroupId <= 0)
|
|
|
|
{
|
|
|
|
self.Parent.RemoveComponent<ResourceMonsterGroupViewComponent>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Destory(this ResourceViewComponent self)
|
|
|
|
{
|
|
|
|
if (self.Parent == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var mapComp = self.ZoneScene()?.CurrentScene()?.GetComponent<MapComponent>();
|
|
|
|
|
|
|
|
// 退出程序时,zoneScene会先被清理掉,这里会为空
|
|
|
|
if (mapComp == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FUIUnitNamePanelComponent unitNamePanelComponent = FUIComponent.Instance.GetUI(FUI_UnitNamePanel.UIResName) as FUIUnitNamePanelComponent;
|
|
|
|
unitNamePanelComponent.FUIUnitNamePanel.FGComp.RemoveChild(self.UnitName.FGComp);
|
|
|
|
self.UnitName.Dispose();
|
|
|
|
|
|
|
|
var sprRender = self.ResourceRoot.GetComponentInChildren<SpriteRenderer>();
|
|
|
|
mapComp.MarkPlaceOnGrid(self.ResourceRoot.transform.position, mapComp.GetSizeBySpriteCollider(sprRender), false);
|
|
|
|
GameObject.Destroy(self.ResourceRoot);
|
|
|
|
Physics2D.SyncTransforms();
|
|
|
|
mapComp.UpdateNavMesh2d();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|