using Core.Utilities; using TowerDefense.UI.HUD; using UnityEngine; namespace TowerDefense.Towers.Placement { /// /// An area suitable for placing a single tower /// [RequireComponent(typeof(Collider))] public class SingleTowerPlacementArea : MonoBehaviour, IPlacementArea { /// /// Visualisation prefab to instantiate /// public PlacementTile placementTilePrefab; /// /// Visualisation prefab to instantiate on mobile platforms /// public PlacementTile placementTilePrefabMobile; /// /// we've spawned on our spot /// PlacementTile m_SpawnedTile; /// /// If the area is occupied /// bool m_IsOccupied; /// /// Set up visualisation tile /// protected void Awake() { PlacementTile tileToUse; #if UNITY_STANDALONE tileToUse = placementTilePrefab; #else tileToUse = placementTilePrefabMobile; #endif if (tileToUse != null) { m_SpawnedTile = Instantiate(tileToUse); m_SpawnedTile.transform.SetParent(transform); m_SpawnedTile.transform.localPosition = new Vector3(0f, 0.05f, 0f); } } public void startCoinGenMode() { return; } /// /// Returns (0, 0), as there is only one available spot /// /// indicating world space coordinates to convert. /// indicating size of object to center. public IntVector2 WorldToGrid(Vector3 worldPosition, IntVector2 sizeOffset) { return new IntVector2(0, 0); } public IntVector2 getdimsize() { return new IntVector2(1, 1); } /// /// 获取对应位置的充能子弹界面指针. /// /// /// public BulletUICtl GetBulletUICtl(int x, int y) { return null; } /// /// 获取对应位置的能量条界面指针. /// /// /// public EnergyUICtl GetEnergyUICtl(int x, int y) { return null; } /// /// 获取一个可以放置塔防的位置. /// /// public IntVector2 getFreePos(int xdim, int ydim, bool forceGet = false) { return new IntVector2(0, 0); } public bool isFreeAtackPos(int x,int y ) { return false; } /// /// 当前是否是反方的TowerPlacementGrid. /// public bool isOpponent() { return false; } /// /// 是否有已开启的可放置攻击位置。 /// /// public bool hasFreeAttackPos() { return false; } /// /// 设置格子为合成状态。 /// /// /// /// public bool SetComboGrid(int x, int y) { return false; } /// /// 设置塔位的血条血量数据 /// /// /// public void setTowerPosHealth(int ix, float health) { return; } /// /// 是否是等待购买的攻击塔位. /// /// /// /// public bool isWaitBuyGrid(int x, int y) { return false; } /// /// 购买对应的待购攻击塔位. /// /// /// /// public bool buyWaitBuyGrid(int x, int y) { return false; } /// /// 设置某一个格子为已破坏塔位。 /// /// /// /// public bool SetDestroyedGrid(int x, int y) { return false; } /// /// Returns transform.position, as there is only one available spot /// /// The coordinate in grid space /// indicating size of object to center. public Vector3 GridToWorld(IntVector2 gridPosition, IntVector2 sizeOffset) { return transform.position; } /// /// Tests whether the placement area is valid. /// /// The grid location /// The size of the item public TowerFitStatus Fits(IntVector2 gridPos, IntVector2 size) { return m_IsOccupied ? TowerFitStatus.Overlaps : TowerFitStatus.Fits; } /// /// Occupies the area /// /// /// public void Occupy(IntVector2 gridPos, IntVector2 size) { m_IsOccupied = true; if (m_SpawnedTile != null) { //m_SpawnedTile.SetState(PlacementTileState.Filled); } } /// /// Clears the area /// /// /// public void Clear(IntVector2 gridPos, IntVector2 size) { m_IsOccupied = false; if (m_SpawnedTile != null) { //m_SpawnedTile.SetState(PlacementTileState.Empty); } } #if UNITY_EDITOR /// /// Draw the spot as a smalls phere in the scene view. /// void OnDrawGizmos() { Color prevCol = Gizmos.color; Gizmos.color = Color.cyan; Matrix4x4 originalMatrix = Gizmos.matrix; Gizmos.matrix = transform.localToWorldMatrix; Gizmos.DrawWireSphere(Vector3.zero, 1); Gizmos.matrix = originalMatrix; Gizmos.color = prevCol; // Draw icon too Gizmos.DrawIcon(transform.position + Vector3.up, "build_zone.png", true); } #endif } }