using Core.Utilities;
|
using UnityEngine;
|
|
namespace TowerDefense.Towers.Placement
|
{
|
/// <summary>
|
/// An interface for a placement area that can contain a tower
|
/// </summary>
|
public interface IPlacementArea
|
{
|
/// <summary>
|
/// Gets this object's transform
|
/// </summary>
|
Transform transform { get; }
|
|
/// <summary>
|
/// 获取当前PlaceMentArea的Size.
|
/// </summary>
|
IntVector2 getdimsize();
|
|
/// <summary>
|
/// 获取一个可以放置塔防的位置.
|
/// </summary>
|
/// <returns></returns>
|
IntVector2 getFreePos(int xdim,int ydim,bool forceGet = false );
|
|
|
/// <summary>
|
/// 获取对应位置的充能子弹界面指针.
|
/// </summary>
|
/// <param name="x"></param>
|
/// <returns></returns>
|
BulletUICtl GetBulletUICtl(int x);
|
|
/// <summary>
|
/// 获取对应位置的能量条界面指针.
|
/// </summary>
|
/// <param name="x"></param>
|
/// <returns></returns>
|
EnergyUICtl GetEnergyUICtl(int x);
|
|
/// <summary>
|
/// 是否空置的攻击位
|
/// </summary>
|
/// <param name="x"></param>
|
/// <param name="y"></param>
|
/// <returns></returns>
|
bool isFreeAtackPos(int x, int y);
|
|
/// <summary>
|
/// 是否有已开启的可放置攻击位置。
|
/// </summary>
|
/// <returns></returns>
|
bool hasFreeAttackPos();
|
|
/// <summary>
|
/// 是否是等待购买的攻击塔位.
|
/// </summary>
|
/// <param name="x"></param>
|
/// <param name="y"></param>
|
/// <returns></returns>
|
bool isWaitBuyGrid(int x, int y);
|
|
void startCoinGenMode();
|
|
/// <summary>
|
/// 购买对应的待购攻击塔位.
|
/// </summary>
|
/// <param name="x"></param>
|
/// <param name="y"></param>
|
/// <returns></returns>
|
bool buyWaitBuyGrid(int x, int y);
|
|
/// <summary>
|
/// 设置某一个格子为已破坏塔位。
|
/// </summary>
|
/// <param name="x"></param>
|
/// <param name="y"></param>
|
/// <returns></returns>
|
bool SetDestroyedGrid(int x, int y );
|
|
/// <summary>
|
/// 设置格子为合成状态。
|
/// </summary>
|
/// <param name="x"></param>
|
/// <param name="y"></param>
|
/// <returns></returns>
|
bool SetComboGrid(int x, int y);
|
|
/// <summary>
|
/// 设置塔位的血条血量数据
|
/// </summary>
|
/// <param name="ix"></param>
|
/// <param name="health"></param>
|
void setTowerPosHealth(int ix, float health);
|
|
/// <summary>
|
/// Calculates the grid position from a given world position, offset to center for a specific size object
|
/// </summary>
|
IntVector2 WorldToGrid(Vector3 worldPosition, IntVector2 sizeOffset);
|
|
/// <summary>
|
/// Calculates the snapped world position from a given grid position
|
/// </summary>
|
Vector3 GridToWorld(IntVector2 gridPosition, IntVector2 sizeOffset);
|
|
/// <summary>
|
/// 当前是否是反方的TowerPlacementGrid.
|
/// </summary>
|
bool isOpponent();
|
|
|
/// <summary>
|
/// Gets whether an object of a given size would fit on this grid at the given location
|
/// </summary>
|
/// <param name="gridPos">The grid location</param>
|
/// <param name="size">The size of the item</param>
|
/// <returns>True if the item would fit at <paramref name="gridPos"/></returns>
|
TowerFitStatus Fits(IntVector2 gridPos, IntVector2 size);
|
|
/// <summary>
|
/// Occupy the given space on this placement area
|
/// </summary>
|
/// <param name="gridPos">The grid location</param>
|
/// <param name="size">The size of the item</param>
|
void Occupy(IntVector2 gridPos, IntVector2 size);
|
|
/// <summary>
|
/// Clear the given space on this placement area
|
/// </summary>
|
/// <param name="gridPos">The grid location</param>
|
/// <param name="size">The size of the item</param>
|
void Clear(IntVector2 gridPos, IntVector2 size);
|
}
|
|
public static class PlacementAreaExtensions
|
{
|
/// <summary>
|
/// Snaps a given world positionn to this grid
|
/// </summary>
|
public static Vector3 Snap(this IPlacementArea placementArea, Vector3 worldPosition, IntVector2 sizeOffset)
|
{
|
// Calculate the nearest grid location and then change that back to world space
|
return placementArea.GridToWorld(placementArea.WorldToGrid(worldPosition, sizeOffset), sizeOffset);
|
}
|
}
|
}
|