| | |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | |
| | | namespace TowerDefense.Towers.Placement { |
| | | |
| | | |
| | | |
| | | public class BuyButtonGroup |
| | | { |
| | | public BuyButtonGroup(Transform t,int x,int y) |
| | | { |
| | | this.button = t; |
| | | this.x = x; |
| | | this.y = y; |
| | | } |
| | | |
| | | |
| | | public Transform button; |
| | | public int x; |
| | | public int y; |
| | | }; |
| | | |
| | | namespace TowerDefense.Towers.Placement |
| | | { |
| | | /// <summary> |
| | | /// A tower placement location made from a grid. |
| | | /// Its origin is centered in the middle of the lower-right cell. It can be oriented in any direction |
| | |
| | | [RequireComponent(typeof(BoxCollider))] |
| | | public class TowerPlacementGridEndless : MonoBehaviour, IPlacementArea |
| | | { |
| | | [Range(0,100)] |
| | | public float buyButtonScaler=1.9f; |
| | | |
| | | private List<BuyButtonGroup> mBuyButtons = new List<BuyButtonGroup>(); |
| | | public static float GRID_OPENCASH = 100; |
| | | |
| | | /// <summary> |
| | |
| | | public bool isFreeAtackPos(int x, int y) |
| | | { |
| | | if (m_AvailableCells[x, y]) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if (m_arrGridType[x, y] == PlacementGridType.EGridOpen) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 是否是等待购买的攻击塔位. |
| | |
| | | } |
| | | } |
| | | } |
| | | void FixedUpdate() |
| | | { |
| | | this.resizeBuyButtonSize(this.buyButtonScaler); |
| | | } |
| | | |
| | | void Update() |
| | | { |
| | | |
| | | |
| | | if (m_arrCoinGenTime == null || !EndlessUIStart.instance.IsGameRunning) return; |
| | | |
| | | float delta = Time.deltaTime; |
| | |
| | | m_AvailableCells = new bool[dimensions.x, dimensions.y]; |
| | | |
| | | opponent = false; |
| | | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | |
| | | SetUpGrid(); |
| | | |
| | | // 初始化格子对应的屏幕坐标数据 |
| | | preCalculateGridUIPos(); |
| | | // 初始化格子对应的屏幕坐标数据 延迟执行 |
| | | Invoke("preCalculateGridUIPos", 0.3f); |
| | | //preCalculateGridUIPos(); |
| | | } |
| | | |
| | | void resizeBuyButtonSize(float defaultVal=1.9f) |
| | | { |
| | | |
| | | |
| | | |
| | | foreach(BuyButtonGroup bbg in this.mBuyButtons) |
| | | { |
| | | Vector3 pos = bbg.button.position; |
| | | pos.x = arrGridCentPos[bbg.x, bbg.y].x; |
| | | pos.z = arrGridCentPos[bbg.x, bbg.y].y + (bbg.y - AttackRowNumbers) * defaultVal; |
| | | pos.y = 30; |
| | | bbg.button.position = pos; |
| | | bbg.button.localRotation = Quaternion.identity; |
| | | bbg.button.localScale = Vector3.one; |
| | | } |
| | | //for (int x = 0; x < dimensions.x; ++x) |
| | | //{ |
| | | // for (int y = dimensions.y - AttackRowNumbers; y < dimensions.y; ++y) |
| | | // { |
| | | // if (m_arrGridType[x, y] != PlacementGridType.EGridWaitBuy) continue; |
| | | |
| | | // GameObject container = GameObject.Find("BuyButtonContainer"); |
| | | // Button buyButton = Instantiate(waitBuyBtnPrefab); |
| | | // buyButton.transform.SetParent(container.transform); |
| | | |
| | | |
| | | // mBuyButtons.Add(new BuyButtonGroup(buyButton.transform, x, y)); |
| | | // //Camera.main.WorldToViewportPoint() |
| | | |
| | | // Vector3 pos = buyButton.transform.position; |
| | | // pos.x = arrGridCentPos[x, y].x; |
| | | // pos.z = arrGridCentPos[x, y].y + (y - AttackRowNumbers) * 1.9f; |
| | | // pos.y = 30; |
| | | // buyButton.transform.position = pos; |
| | | // buyButton.transform.localRotation = Quaternion.identity; |
| | | // buyButton.transform.localScale = Vector3.one; |
| | | |
| | | |
| | | // } |
| | | //} |
| | | |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 预计算塔位格子对应的屏幕坐标以及塔位格子的屏幕尺寸 |
| | | /// WORK START: 计算屏幕坐标,然后开搞屏幕相关的内容。下午要把塔位上显示界面搞出来。 |
| | |
| | | /// </summary> |
| | | void preCalculateGridUIPos() |
| | | { |
| | | |
| | | arrGridCentPos = new Vector2[dimensions.x, dimensions.y]; |
| | | |
| | | Vector3 targetPos = GridToWorld(new IntVector2(0, 0), new IntVector2(1, 1)); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // 血条位置的设定 |
| | | PreCalculateTowerBloodUi(); |
| | | |
| | |
| | | Button buyButton = Instantiate(waitBuyBtnPrefab); |
| | | buyButton.transform.SetParent(container.transform); |
| | | |
| | | |
| | | mBuyButtons.Add(new BuyButtonGroup(buyButton.transform, x, y)); |
| | | //Camera.main.WorldToViewportPoint() |
| | | |
| | | //Vector3 pos = buyButton.transform.position; |
| | | //pos.x = arrGridCentPos[x, y].x; |
| | | //pos.z = arrGridCentPos[x, y].y + (y - AttackRowNumbers) * 1.9f; |
| | | //pos.y = 30; |
| | | //buyButton.transform.position = pos; |
| | | //buyButton.transform.localRotation = Quaternion.identity; |
| | | //buyButton.transform.localScale = Vector3.one; |
| | | Vector3 pos = buyButton.transform.position; |
| | | pos.x = arrGridCentPos[x, y].x; |
| | | pos.z = arrGridCentPos[x, y].y; |
| | | pos.y = 30; |
| | | buyButton.transform.position = pos; |
| | | buyButton.transform.localRotation = Quaternion.identity; |
| | | buyButton.transform.localScale = Vector3.one; |
| | | |
| | | // 设置按钮对应的点击功能 |
| | | EndlessTowerGridOpen tgo = buyButton.GetComponent<EndlessTowerGridOpen>(); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | this.resizeBuyButtonSize(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | m_arrTowerBulletUIPos[x, y].x = arrGridCentPos[x, dy - y].x; |
| | | m_arrTowerBulletUIPos[x, y].y = arrGridCentPos[x, dy - y].y; |
| | | |
| | | // 现在PVE基地不需要血条 |
| | | GameObject img = Instantiate(towerBloodUIPrefab); |
| | | GameObject container = GameObject.Find("BuyButtonContainer"); |
| | | img.transform.SetParent(container.transform); |
| | |
| | | img.transform.SetParent(container.transform, true); |
| | | tpos = img.transform.position; |
| | | tpos.x = m_arrTowerBulletUIPos[x, y].x + 4.2f; |
| | | tpos.z = m_arrTowerBulletUIPos[x, y].y + 1.1f - y * 1.66f; |
| | | tpos.z = m_arrTowerBulletUIPos[x, y].y - 0.5f; |
| | | tpos.y = 30f; |
| | | img.transform.position = tpos; |
| | | img.transform.localScale = Vector3.one; |
| | |
| | | img.transform.SetParent(container.transform); |
| | | tpos = img.transform.position; |
| | | tpos.x = m_arrTowerBulletUIPos[x, y].x + 4.2f; |
| | | tpos.z = m_arrTowerBulletUIPos[x, y].y + 1.1f - y * 1.66f; |
| | | tpos.z = m_arrTowerBulletUIPos[x, y].y - 0.5f; |
| | | tpos.y = 30f; |
| | | img.transform.position = tpos; |
| | | img.transform.localScale = Vector3.one; |
| | |
| | | |
| | | m_Tiles[x, y] = newTile; |
| | | newTile.SetTileType(m_arrGridType[x, y]); |
| | | newTile.CheckCanPlace(false);//初始化不显示 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 开始拖拽的时候判断哪些可以放置 |
| | | /// </summary> |
| | | /// <param name="allTowerP">不符合条件的数组</param> |
| | | public void CheckAllCanPlace(List<IntVector2> allTowerP) |
| | | { |
| | | int iy = dimensions.y - 1;//3 |
| | | bool canPlace; |
| | | currentCanPlace = null; |
| | | for (int ix = 0; ix < dimensions.x; ix++) |
| | | { |
| | | for (int y = iy; y >= dimensions.y - AttackRowNumbers; --y) |
| | | { |
| | | if (m_arrGridType[ix, y] == PlacementGridType.EGridOpen) |
| | | { |
| | | canPlace = true; |
| | | for (int i = 0; i < allTowerP.Count; i++) |
| | | { |
| | | if (allTowerP[i].x == ix && allTowerP[i].y == y) |
| | | { |
| | | canPlace = false; |
| | | break; |
| | | } |
| | | } |
| | | m_Tiles[ix, y].CheckCanPlace(canPlace); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | PlacementTile currentCanPlace;//记录当前标记 |
| | | /// <summary> |
| | | /// 拖动时候实时检查距离哪个格子近 |
| | | /// </summary> |
| | | /// <param name="x"></param> |
| | | /// <param name="y"></param> |
| | | public void CheckCanPlaceUpdate(int x, int y) |
| | | { |
| | | CloseCanPlace(); |
| | | currentCanPlace = m_Tiles[x, y]; |
| | | currentCanPlace.SetSelect(true); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 关闭上一个 |
| | | /// </summary> |
| | | public void CloseCanPlace() |
| | | { |
| | | if (currentCanPlace != null) |
| | | { |
| | | currentCanPlace.SetSelect(false); |
| | | currentCanPlace = null; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 关闭所有 |
| | | /// </summary> |
| | | public void CloseCanPlaceRenderer() |
| | | { |
| | | int iy = dimensions.y - 1; |
| | | for (int ix = 0; ix < dimensions.x; ix++) |
| | | { |
| | | for (int y = iy; y >= dimensions.y - AttackRowNumbers; --y) |
| | | { |
| | | if (m_arrGridType[ix, y] == PlacementGridType.EGridOpen) |
| | | { |
| | | m_Tiles[ix, y].CheckCanPlace(false); |
| | | } |
| | | } |
| | | } |