| | |
| | | private float[,] m_arrCoinGenTime; |
| | | |
| | | /// <summary> |
| | | /// 每一个Tile格子的中心点对应的屏幕坐标. |
| | | /// 每一个Tile格子的中心店的世界坐标 |
| | | /// </summary> |
| | | private Vector2[,] m_arrGridCentUIPos; |
| | | private Vector2[,] arrGridCentPos; |
| | | |
| | | /// <summary> |
| | | /// 攻击塔位对应的UI位置信息. |
| | |
| | | private TowerBloodVis[,] arrTowerBloodUi; |
| | | |
| | | /// <summary> |
| | | /// 塔位对应的屏幕坐标尺寸 |
| | | /// </summary> |
| | | private float m_fGridUISize; |
| | | |
| | | /// <summary> |
| | | /// Array of <see cref="PlacementTile"/>s |
| | | /// </summary> |
| | | private PlacementTile[,] m_Tiles; |
| | |
| | | /// </summary> |
| | | /// <value></value> |
| | | public int AttackRowNumbers { get; } = 2; |
| | | |
| | | /// <summary> |
| | | /// 攻击塔位对应的子弹UI位置信息. |
| | | /// </summary> |
| | | private Vector2[,] m_arrTowerBulletUIPos; |
| | | |
| | | private BulletUICtl[,] arrTowerBulletUi; |
| | | |
| | | private EnergyUICtl[,] arrTowerEnergyUi; |
| | | |
| | | /// <summary> |
| | | /// 此位置上塔对应的子弹充能Prefab.塔放置到当前的塔位后,如果是对应的塔防类型,需要把 |
| | | /// 相应的界面指针传到塔防的数据结构内。 |
| | | /// </summary> |
| | | public GameObject towerBulletUIPrefab; |
| | | |
| | | /// <summary> |
| | | /// 充能条对应的界面 |
| | | /// </summary> |
| | | public GameObject towerEnergyUIPrefab; |
| | | |
| | | /// <summary> |
| | | /// Converts a location in world space into local grid coordinates. |
| | |
| | | /// </summary> |
| | | /// <param name="x"></param> |
| | | /// <returns></returns> |
| | | public BulletUICtl GetBulletUICtl(int x) |
| | | public BulletUICtl GetBulletUICtl(int x, int y) |
| | | { |
| | | return null; |
| | | return arrTowerBulletUi[x, 3 - y]; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="x"></param> |
| | | /// <returns></returns> |
| | | public EnergyUICtl GetEnergyUICtl(int x) |
| | | public EnergyUICtl GetEnergyUICtl(int x, int y) |
| | | { |
| | | return null; |
| | | return arrTowerEnergyUi[x, 3 - y]; |
| | | } |
| | | |
| | | |
| | |
| | | /// </summary> |
| | | void preCalculateGridUIPos() |
| | | { |
| | | m_arrGridCentUIPos = new Vector2[dimensions.x, dimensions.y]; |
| | | arrGridCentPos = new Vector2[dimensions.x, dimensions.y]; |
| | | |
| | | Vector3 targetPos = GridToWorld(new IntVector2(0, 0), new IntVector2(1, 1)); |
| | | Vector3 svec = transform.position; |
| | | |
| | | if (!ViewPortAdj.instance.bAdjViewPort) |
| | | ViewPortAdj.instance.adjViewportRect(); |
| | | |
| | | UnityEngine.Camera sceneCam = ViewPortAdj.instance.cachedCamera; |
| | | Vector3 centPos = sceneCam.WorldToScreenPoint(targetPos); |
| | | Vector3 lbPos = sceneCam.WorldToScreenPoint(svec); |
| | | float size = 10.29f; |
| | | |
| | | m_fGridUISize = (centPos.y - lbPos.y) * 2.0f; |
| | | |
| | | for (int ty = 0; ty < dimensions.y; ty++) |
| | | for (int x = 0; x < dimensions.x; ++x) |
| | | { |
| | | for (int tx = 0; tx < dimensions.x; tx++) |
| | | for (int y = 0; y < dimensions.y; ++y) |
| | | { |
| | | m_arrGridCentUIPos[tx, ty].x = centPos.x + tx * m_fGridUISize; |
| | | m_arrGridCentUIPos[tx, ty].y = centPos.y + ty * m_fGridUISize; |
| | | } |
| | | |
| | | if ((gridFreePos > 0) && (ty == (dimensions.y - 1))) |
| | | { |
| | | targetPos = GridToWorld(new IntVector2(0, ty), new IntVector2(1, 1)); |
| | | centPos = sceneCam.WorldToScreenPoint(targetPos); |
| | | |
| | | for (int tx = 0; tx < dimensions.x; tx++) |
| | | { |
| | | m_arrGridCentUIPos[tx, ty].x = centPos.x + tx * m_fGridUISize; |
| | | m_arrGridCentUIPos[tx, ty].y = centPos.y; |
| | | } |
| | | } |
| | | else if (gridFreePos2 > 0 && ty == dimensions.y - 2) |
| | | { |
| | | targetPos = GridToWorld(new IntVector2(0, ty), new IntVector2(1, 1)); |
| | | centPos = sceneCam.WorldToScreenPoint(targetPos); |
| | | |
| | | for (int tx = 0; tx < dimensions.x; tx++) |
| | | { |
| | | m_arrGridCentUIPos[tx, ty].x = centPos.x + tx * m_fGridUISize; |
| | | m_arrGridCentUIPos[tx, ty].y = centPos.y; |
| | | } |
| | | arrGridCentPos[x, y].x = targetPos.x + x * size; |
| | | arrGridCentPos[x, y].y = targetPos.y + y * size - 44.5f; |
| | | } |
| | | } |
| | | |
| | |
| | | PreCalculateTowerBloodUi(); |
| | | |
| | | m_arrTGO = new EndlessTowerGridOpen[dimensions.x, dimensions.y]; |
| | | // 设置界面相关的内容: |
| | | for (int y = dimensions.y - AttackRowNumbers; y < dimensions.y; y++) |
| | | |
| | | for (int x = 0; x < dimensions.x; ++x) |
| | | { |
| | | 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; |
| | | if (m_arrGridType[x, y] != PlacementGridType.EGridWaitBuy) continue; |
| | | |
| | | Button tbtn = Instantiate(waitBuyBtnPrefab); |
| | | GameObject go = GameObject.Find("MainUI"); |
| | | if (!go) continue; |
| | | GameObject container = GameObject.Find("BuyButtonContainer"); |
| | | Button buyButton = Instantiate(waitBuyBtnPrefab); |
| | | buyButton.transform.SetParent(container.transform); |
| | | |
| | | Transform tp = go.GetComponent<Transform>(); |
| | | tbtn.GetComponent<Transform>().SetParent(tp, true); |
| | | Vector3 tpos = tbtn.transform.position; |
| | | tpos.x = m_arrGridCentUIPos[x, y].x; |
| | | tpos.y = m_arrGridCentUIPos[x, y].y + m_fGridUISize / 10; |
| | | tbtn.transform.position = tpos; |
| | | |
| | | // 设置为界面最下层: |
| | | tbtn.transform.SetAsFirstSibling(); |
| | | 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; |
| | | |
| | | // 设置按钮对应的点击功能 |
| | | EndlessTowerGridOpen tgo = tbtn.GetComponent<EndlessTowerGridOpen>(); |
| | | EndlessTowerGridOpen tgo = buyButton.GetComponent<EndlessTowerGridOpen>(); |
| | | if (tgo) |
| | | { |
| | | tgo.SetBuyBtnInfo(x, y, this); |
| | |
| | | arrTowerBloodUi = new TowerBloodVis[dimensions.x, AttackRowNumbers]; |
| | | int dy = dimensions.y - 1; |
| | | |
| | | // 处理攻击塔位对应的血条 |
| | | m_arrTowerBulletUIPos = new Vector2[dimensions.x, AttackRowNumbers]; |
| | | arrTowerBulletUi = new BulletUICtl[dimensions.x, AttackRowNumbers]; |
| | | arrTowerEnergyUi = new EnergyUICtl[dimensions.x, AttackRowNumbers]; |
| | | |
| | | for (int x = 0; x < dimensions.x; x++) |
| | | { |
| | | for (int y = 0; y < AttackRowNumbers; ++y) |
| | | { |
| | | m_arrTowerBloodUIPos[x, y].x = m_arrGridCentUIPos[x, dy - y].x; |
| | | m_arrTowerBloodUIPos[x, y].y = m_arrGridCentUIPos[x, dy - y].y + m_fGridUISize / 10 * 3; |
| | | m_arrTowerBloodUIPos[x, y].x = arrGridCentPos[x, dy - y].x; |
| | | m_arrTowerBloodUIPos[x, y].y = arrGridCentPos[x, dy - y].y; |
| | | m_arrTowerBulletUIPos[x, y].x = arrGridCentPos[x, dy - y].x; |
| | | m_arrTowerBulletUIPos[x, y].y = arrGridCentPos[x, dy - y].y; |
| | | |
| | | GameObject img = Instantiate(towerBloodUIPrefab); |
| | | GameObject go = GameObject.Find("MainUI"); |
| | | if (!go) continue; |
| | | |
| | | Transform tp = go.GetComponent<Transform>(); |
| | | img.GetComponent<Transform>().SetParent(tp, true); |
| | | GameObject container = GameObject.Find("BuyButtonContainer"); |
| | | img.transform.SetParent(container.transform); |
| | | Vector3 tpos = img.transform.position; |
| | | tpos.x = m_arrTowerBloodUIPos[x, y].x; |
| | | tpos.y = m_arrTowerBloodUIPos[x, y].y; |
| | | tpos.z = m_arrTowerBloodUIPos[x, y].y + 4.2f - y * 1.66f; |
| | | tpos.y = 30f; |
| | | img.transform.position = tpos; |
| | | |
| | | // 设置为界面最下层: |
| | | img.transform.SetAsFirstSibling(); |
| | | img.transform.localScale = Vector3.one; |
| | | img.transform.localRotation = Quaternion.identity; |
| | | |
| | | TowerBloodVis tbv = img.GetComponent<TowerBloodVis>(); |
| | | arrTowerBloodUi[x, y] = tbv; |
| | | tbv.gameObject.SetActive(false); |
| | | |
| | | img = Instantiate(towerBulletUIPrefab); |
| | | 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.y = 30f; |
| | | img.transform.position = tpos; |
| | | img.transform.localScale = Vector3.one; |
| | | img.transform.localRotation = Quaternion.identity; |
| | | |
| | | BulletUICtl buc = img.GetComponent<BulletUICtl>(); |
| | | arrTowerBulletUi[x, y] = buc; |
| | | buc.gameObject.SetActive(false); |
| | | |
| | | // 把充能条也创建出来了. |
| | | img = Instantiate(towerEnergyUIPrefab); |
| | | 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.y = 30f; |
| | | img.transform.position = tpos; |
| | | img.transform.localScale = Vector3.one; |
| | | img.transform.localRotation = Quaternion.identity; |
| | | |
| | | EnergyUICtl euc = img.GetComponent<EnergyUICtl>(); |
| | | arrTowerEnergyUi[x, y] = euc; |
| | | euc.gameObject.SetActive(false); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | // 设置塔位默认开启,后面需要根据配置来 |
| | | m_arrGridType[2, 3] = PlacementGridType.EGridOpen; |
| | | ++GameConfig.EndlessOpenAttackTowerCount; |
| | | } |
| | | |
| | | /// <summary> |