| | |
| | | using TowerDefense.Level; |
| | | using TowerDefense.UI.HUD; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | |
| | | namespace TowerDefense.Towers.Placement |
| | | { |
| | |
| | | /// Its origin is centered in the middle of the lower-right cell. It can be oriented in any direction |
| | | /// </summary> |
| | | [RequireComponent(typeof(BoxCollider))] |
| | | public class TowerPlacementGridEndless : MonoBehaviour, IPlacementArea |
| | | public class TowerPlacementGridEndless : Singleton<TowerPlacementGridEndless>, IPlacementArea |
| | | { |
| | | public static float GRID_OPENCASH = 100; |
| | | public static float GRID_OPENCASH = 200; |
| | | |
| | | /// <summary> |
| | | /// Prefab used to visualise the grid. |
| | |
| | | /// Size of the edge of a cell |
| | | /// </summary> |
| | | [Tooltip("The size of the edge of one grid cell for area. Should match the physical grid size of towers")] |
| | | public float gridSize = 1; |
| | | public float gridSize = 1;//1.109 |
| | | |
| | | /// <summary> |
| | | /// Inverted grid size, to multiply with |
| | |
| | | |
| | | private float[,] m_arrCoinGenTime; |
| | | |
| | | public GameObject GridContainer; |
| | | |
| | | /// <summary> |
| | | /// 每一个Tile格子的中心店的世界坐标 |
| | | /// 所有格子对应的世界坐标 |
| | | /// </summary> |
| | | private Vector3[,] GridWorldPosArr; |
| | | |
| | | /// <summary> |
| | | /// 每一个Tile格子的中心店的屏幕坐标 |
| | | /// </summary> |
| | | private Vector2[,] arrGridCentPos; |
| | | |
| | |
| | | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 是否是等待购买的攻击塔位. |
| | |
| | | /// <summary> |
| | | /// Initialize values |
| | | /// </summary> |
| | | protected virtual void Awake() |
| | | protected override void Awake() |
| | | { |
| | | base.Awake(); |
| | | ResizeCollider(); |
| | | |
| | | // Initialize empty bool array (defaults are false, which is what we want) |
| | |
| | | { |
| | | // 初始化塔位类型. |
| | | initTileGridType(); |
| | | InitGridWorldPos(); |
| | | |
| | | // Precalculate inverted grid size, to save a division every time we translate coords |
| | | m_InvGridSize = 1 / gridSize; |
| | |
| | | // 初始化格子对应的屏幕坐标数据 延迟执行 |
| | | Invoke("preCalculateGridUIPos", 0.3f); |
| | | EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.EndlessCritBulletNumChange, OnCritBulletNumChange); |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.OpenAllTowerGrid, OpenAllTowerGrid); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化所有格子的世界坐标(中心) |
| | | /// </summary> |
| | | private void InitGridWorldPos() |
| | | { |
| | | GridWorldPosArr = new Vector3[dimensions.x, dimensions.y]; |
| | | |
| | | for (int i = 0; i < dimensions.x; ++i) |
| | | { |
| | | for (int j = 0; j < dimensions.y; ++j) |
| | | { |
| | | GridWorldPosArr[i, j] = GridToWorld(new IntVector2(i, j), new IntVector2(1, 1)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据坐标获取格子世界坐标(中心) |
| | | /// </summary> |
| | | /// <param name="x"></param> |
| | | /// <param name="y"></param> |
| | | /// <returns></returns> |
| | | public Vector3 GetGridWorldPos(int x, int y) |
| | | { |
| | | if (x < 0 || x >= dimensions.x || y < 0 || y >= dimensions.y) return new Vector3(); |
| | | |
| | | return GridWorldPosArr[x, y]; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | arrGridCentPos = new Vector2[dimensions.x, dimensions.y]; |
| | | |
| | | Vector3 targetPos = GridToWorld(new IntVector2(0, 0), new IntVector2(1, 1)); |
| | | Vector3 targetPos = GetGridWorldPos(0, 0); |
| | | |
| | | if (!ViewPortAdj.instance.bAdjViewPort) |
| | | ViewPortAdj.instance.adjViewportRect(); |
| | |
| | | // 血条位置的设定 |
| | | PreCalculateTowerBloodUi(); |
| | | |
| | | float[] gapArr = { 0.2f, 0.7f }; |
| | | float[] gapArr = { 0.5f, 1f }; |
| | | m_arrTGO = new EndlessTowerGridOpen[dimensions.x, dimensions.y]; |
| | | |
| | | GameObject container = GameObject.Find("BuyButtonContainer"); |
| | | TowerPlacementGridEndless.GRID_OPENCASH = 100; |
| | | TowerPlacementGridEndless.GRID_OPENCASH = 200; |
| | | //Debug.Log("修改了数值:" + TowerPlacementGridEndless.GRID_OPENCASH); |
| | | //float[] xup = { -0.6f, -0.3f, 0, 0.3f, 0.6f }; |
| | | for (int x = 0; x < dimensions.x; ++x) |
| | |
| | | if (m_arrGridType[x, y] != PlacementGridType.EGridWaitBuy) continue; |
| | | |
| | | GameObject buyButton = Instantiate(waitBuyBtnPrefab); |
| | | buyButton.transform.SetParent(container.transform); |
| | | buyButton.transform.SetParent(container.transform, false); |
| | | |
| | | Vector3 pos = buyButton.transform.position; |
| | | //pos.x = arrGridCentPos[x, y].x + (x - 2) * gapArr[3 - y] + xup[x]; |
| | |
| | | // } |
| | | pos.y = 30; |
| | | buyButton.transform.position = pos; |
| | | buyButton.transform.localRotation = Quaternion.identity; |
| | | buyButton.transform.localScale = Vector3.one; |
| | | |
| | | // 设置按钮对应的点击功能 |
| | | EndlessTowerGridOpen tgo = buyButton.GetComponent<EndlessTowerGridOpen>(); |
| | | if (tgo) |
| | | { |
| | | tgo.SetBuyBtnInfo(x, y, this); |
| | | tgo.cashText.SetText(TowerPlacementGrid.GRID_OPENCASH_SELF.ToString()); |
| | | tgo.cashText.SetText(TowerPlacementGridEndless.GRID_OPENCASH.ToString()); |
| | | m_arrTGO[x, y] = tgo; |
| | | } |
| | | } |
| | |
| | | |
| | | public void updateGridOpenCoin(int ix, int iy) |
| | | { |
| | | GRID_OPENCASH = Mathf.Floor(GRID_OPENCASH * 1.2f); |
| | | GRID_OPENCASH = Mathf.Floor(GRID_OPENCASH * 1.25f); |
| | | |
| | | for (int x = 0; x < dimensions.x; x++) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 免费开启所有塔位 |
| | | /// </summary> |
| | | public void OpenAllTowerGrid() |
| | | { |
| | | int sy = dimensions.y - 1; |
| | | |
| | | for (int tx = 0; tx < dimensions.x; tx++) |
| | | { |
| | | if (m_arrGridType[tx, sy - 1] == PlacementGridType.EGridWaitBuy) |
| | | { |
| | | BuyTowerGrid(tx, sy - 1); |
| | | Destroy(m_arrTGO[tx, sy - 1].gameObject); |
| | | ++GameConfig.EndlessOpenAttackTowerCount; |
| | | } |
| | | if (m_arrGridType[tx, sy] == PlacementGridType.EGridWaitBuy) |
| | | { |
| | | BuyTowerGrid(tx, sy); |
| | | Destroy(m_arrTGO[tx, sy].gameObject); |
| | | ++GameConfig.EndlessOpenAttackTowerCount; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 购买对应的待购攻击塔位. |
| | | /// </summary> |
| | | /// <param name="x"></param> |
| | |
| | | |
| | | for (int tx = 0; tx < dimensions.x; tx++) |
| | | { |
| | | m_arrGridType[tx, sy] = PlacementGridType.EGridWaitBuy; |
| | | m_arrGridType[tx, sy - 1] = PlacementGridType.EGridWaitBuy; |
| | | m_arrGridType[tx, sy] = PlacementGridType.EGridOpen; |
| | | } |
| | | // 设置塔位默认开启,后面需要根据配置来 |
| | | m_arrGridType[2, 3] = PlacementGridType.EGridOpen; |
| | | ++GameConfig.EndlessOpenAttackTowerCount; |
| | | } |
| | | |
| | |
| | | { |
| | | for (int x = 0; x < dimensions.x; x++) |
| | | { |
| | | Vector3 targetPos = GridToWorld(new IntVector2(x, y), new IntVector2(1, 1)); |
| | | Vector3 targetPos = GetGridWorldPos(x, y); |
| | | targetPos.z -= 1.0f; |
| | | PlacementTile newTile = Instantiate(tileToUse); |
| | | newTile.transform.parent = tilesParent.transform; |
| | |
| | | |
| | | m_Tiles[x, y] = newTile; |
| | | newTile.SetTileType(m_arrGridType[x, y]); |
| | | newTile.CheckCanPlace(false);//初始化不显示 |
| | | newTile.SetRender(false, "");//初始化不显示 |
| | | } |
| | | } |
| | | } |
| | |
| | | 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); |
| | | if (allTowerP != null) |
| | | { |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | CloseCanPlace(); |
| | | currentCanPlace = m_Tiles[x, y]; |
| | | currentCanPlace.SetSelect(true); |
| | | if (isEmpty) |
| | | { |
| | | currentCanPlace.SetTowerVirtualshadow(towerName); |
| | | } |
| | | currentCanPlace?.SetRender(true, isEmpty ? towerName : ""); |
| | | // if (isEmpty) |
| | | // { |
| | | // currentCanPlace.SetTowerVirtualshadow(towerName); |
| | | // } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | if (currentCanPlace != null) |
| | | { |
| | | currentCanPlace.SetSelect(false); |
| | | currentCanPlace.SetRender(false, ""); |
| | | currentCanPlace = null; |
| | | } |
| | | } |
| | |
| | | { |
| | | if (m_arrGridType[ix, y] == PlacementGridType.EGridOpen) |
| | | { |
| | | m_Tiles[ix, y].CheckCanPlace(false); |
| | | //m_Tiles[ix, y].CheckCanPlace(false); |
| | | m_Tiles[ix, y].SetRender(false, ""); |
| | | } |
| | | } |
| | | } |