| | |
| | | /// <summary> |
| | | /// 等待购买开启对应按钮. |
| | | /// </summary> |
| | | public Button waitBuyBtnPrefab; |
| | | public GameObject waitBuyBtnPrefab; |
| | | |
| | | /// <summary> |
| | | /// 最后一行格子与前一行格子之间的空位长度. |
| | |
| | | public float gridFreePos; |
| | | |
| | | public float gridFreePos2; |
| | | |
| | | public float gridFreePos3; |
| | | |
| | | public float gridFreePos4; |
| | | |
| | | /// <summary> |
| | | /// The dimensions of the grid |
| | |
| | | |
| | | private EnergyUICtl[,] arrTowerEnergyUi; |
| | | |
| | | private ParticleSystem[,] arrTowerEnergyEffect; |
| | | private FreezeBreath[,] arrTowerFreezeBreathUi; |
| | | |
| | | private GameObject[,] arrTowerEnergyEffect; |
| | | |
| | | /// <summary> |
| | | /// 水精灵充能满特效 |
| | | /// </summary> |
| | | private GameObject[,] arrTowerFreezeBreathEffect; |
| | | |
| | | /// <summary> |
| | | /// 充能特效对应的Prefab. |
| | | /// </summary> |
| | | public ParticleSystem energyEffectPrefab; |
| | | public GameObject energyEffectPrefab; |
| | | |
| | | /// <summary> |
| | | /// 此位置上塔对应的子弹充能Prefab.塔放置到当前的塔位后,如果是对应的塔防类型,需要把 |
| | |
| | | /// 充能条对应的界面 |
| | | /// </summary> |
| | | public GameObject towerEnergyUIPrefab; |
| | | |
| | | /// <summary> |
| | | /// 水精灵塔技能(冷冻气息)充能条 |
| | | /// </summary> |
| | | public GameObject FreezeBreathChargePrefab; |
| | | |
| | | /// <summary> |
| | | /// 水精灵塔充能条特效 |
| | | /// </summary> |
| | | public GameObject FreezeBreathChargeEffect; |
| | | |
| | | /// <summary> |
| | | /// Converts a location in world space into local grid coordinates. |
| | |
| | | return arrTowerEnergyUi[x, 3 - y]; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取水精灵对应位置的充能条 |
| | | /// </summary> |
| | | /// <param name="x"></param> |
| | | /// <param name="y"></param> |
| | | /// <returns></returns> |
| | | public FreezeBreath GetFreezeBreath(int x, int y) |
| | | { |
| | | return arrTowerFreezeBreathUi[x, 3 - y]; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取一个可以放置塔防的位置. |
| | |
| | | freePos = gridFreePos; |
| | | else if (gridPosition.y == 2) |
| | | freePos = gridFreePos2; |
| | | else if (gridPosition.y == 1) |
| | | { |
| | | freePos = gridFreePos3; |
| | | } |
| | | else if (gridPosition.y == 0) |
| | | { |
| | | freePos = gridFreePos4; |
| | | } |
| | | // Calculate scaled local position |
| | | Vector3 localPos = new Vector3(gridPosition.x + (sizeOffset.x * 0.5f), 0, gridPosition.y + (sizeOffset.y * 0.5f) + freePos) * |
| | | gridSize; |
| | |
| | | // 血条位置的设定 |
| | | PreCalculateTowerBloodUi(); |
| | | |
| | | float[] gapArr = { 0.2f, 0.7f }; |
| | | m_arrTGO = new EndlessTowerGridOpen[dimensions.x, dimensions.y]; |
| | | |
| | | GameObject container = GameObject.Find("BuyButtonContainer"); |
| | | TowerPlacementGridEndless.GRID_OPENCASH = 100; |
| | | //Debug.Log("修改了数值:" + TowerPlacementGridEndless.GRID_OPENCASH); |
| | | //float[] xup = { -0.6f, -0.3f, 0, 0.3f, 0.6f }; |
| | | 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); |
| | | GameObject buyButton = Instantiate(waitBuyBtnPrefab); |
| | | buyButton.transform.SetParent(container.transform); |
| | | |
| | | Vector3 pos = buyButton.transform.position; |
| | | pos.x = arrGridCentPos[x, y].x; |
| | | pos.z = arrGridCentPos[x, y].y; |
| | | //pos.x = arrGridCentPos[x, y].x + (x - 2) * gapArr[3 - y] + xup[x]; |
| | | pos.x = arrGridCentPos[x, y].x + (x - 2) * gapArr[3 - y]; |
| | | pos.z = arrGridCentPos[x, y].y + 6f; |
| | | // if (y == 2) |
| | | // { |
| | | // pos.z = arrGridCentPos[x, y].y + 9f; |
| | | // } |
| | | // else if (y == 3) |
| | | // { |
| | | // pos.z = arrGridCentPos[x, y].y + 7f; |
| | | // } |
| | | pos.y = 30; |
| | | buyButton.transform.position = pos; |
| | | buyButton.transform.localRotation = Quaternion.identity; |
| | |
| | | m_arrTowerBulletUIPos = new Vector2[dimensions.x, AttackRowNumbers]; |
| | | arrTowerBulletUi = new BulletUICtl[dimensions.x, AttackRowNumbers]; |
| | | arrTowerEnergyUi = new EnergyUICtl[dimensions.x, AttackRowNumbers]; |
| | | arrTowerEnergyEffect = new ParticleSystem[dimensions.x, AttackRowNumbers]; |
| | | arrTowerFreezeBreathUi = new FreezeBreath[dimensions.x, AttackRowNumbers]; |
| | | arrTowerEnergyEffect = new GameObject[dimensions.x, AttackRowNumbers]; |
| | | arrTowerFreezeBreathEffect = new GameObject[dimensions.x, AttackRowNumbers]; |
| | | |
| | | float[] gapArr = { 0.4f, 0.6f }; |
| | | |
| | | for (int x = 0; x < dimensions.x; x++) |
| | | { |
| | |
| | | arrTowerBloodUi[x, y] = tbv; |
| | | tbv.gameObject.SetActive(false); |
| | | |
| | | Vector3 targetPos = GridToWorld(new IntVector2(x, dy - y), new IntVector2(2, 1)); |
| | | |
| | | // 子弹条 |
| | | 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 - 0.5f; |
| | | tpos.y = 30f; |
| | | img.transform.position = tpos; |
| | | img.transform.localScale = Vector3.one; |
| | | img.transform.localRotation = Quaternion.identity; |
| | | img.transform.SetParent(transform, false); |
| | | img.transform.position = targetPos; |
| | | Vector3 pos = img.transform.position; |
| | | pos.x -= 1f; |
| | | img.transform.position = pos; |
| | | |
| | | BulletUICtl buc = img.GetComponent<BulletUICtl>(); |
| | | arrTowerBulletUi[x, y] = buc; |
| | |
| | | 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 - 0.5f; |
| | | tpos.x = m_arrTowerBulletUIPos[x, y].x + 4.4f + (x - 2) * gapArr[y]; |
| | | tpos.z = m_arrTowerBulletUIPos[x, y].y + 5f; |
| | | tpos.y = 30f; |
| | | img.transform.position = tpos; |
| | | img.transform.localScale = Vector3.one; |
| | |
| | | |
| | | // 设置播放特效对应的3D坐标: |
| | | Vector3 vpos = GridToWorld(new IntVector2(x, dy - y), new IntVector2(2, 1)); |
| | | vpos.x -= (gridSize / 2.0f); |
| | | vpos.y += 5.0f; |
| | | vpos.x -= 1f; |
| | | |
| | | arrTowerEnergyEffect[x, y] = Instantiate(energyEffectPrefab); |
| | | arrTowerEnergyEffect[x, y].transform.position = vpos; |
| | | arrTowerEnergyEffect[x, y].Stop(); |
| | | |
| | | // 创建水精灵充能条 |
| | | img = Instantiate(FreezeBreathChargePrefab); |
| | | img.transform.SetParent(container.transform); |
| | | tpos = img.transform.position; |
| | | tpos.x = m_arrTowerBulletUIPos[x, y].x + 4.4f + (x - 2) * gapArr[y]; |
| | | tpos.z = m_arrTowerBulletUIPos[x, y].y + 5f; |
| | | tpos.y = 30f; |
| | | img.transform.position = tpos; |
| | | img.transform.localScale = Vector3.one; |
| | | img.transform.localRotation = Quaternion.identity; |
| | | |
| | | FreezeBreath freezeBreath = img.GetComponent<FreezeBreath>(); |
| | | arrTowerFreezeBreathUi[x, y] = freezeBreath; |
| | | freezeBreath.gameObject.SetActive(false); |
| | | |
| | | arrTowerFreezeBreathEffect[x, y] = Instantiate(FreezeBreathChargeEffect); |
| | | arrTowerFreezeBreathEffect[x, y].transform.position = vpos; |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | if (!arrTowerEnergyEffect[x, dy]) return; |
| | | |
| | | ParticleSystem ps = arrTowerEnergyEffect[x, dy].GetComponent<ParticleSystem>(); |
| | | |
| | | if (ps == null) |
| | | ps = arrTowerEnergyEffect[x, dy].transform.GetChild(0).GetComponent<ParticleSystem>(); |
| | | |
| | | if (play) |
| | | { |
| | | if (!arrTowerEnergyEffect[x, dy].gameObject.activeSelf) |
| | | arrTowerEnergyEffect[x, dy].gameObject.SetActive(true); |
| | | arrTowerEnergyEffect[x, dy].Play(); |
| | | ps.Play(); |
| | | } |
| | | else |
| | | { |
| | | |
| | | arrTowerEnergyEffect[x, dy].Stop(); |
| | | ps.Stop(); |
| | | arrTowerEnergyEffect[x, dy].gameObject.SetActive(false); |
| | | } |
| | | } |
| | | |
| | | public void PlayFreezeBreathEffect(int x, int y, bool play = true) |
| | | { |
| | | int dy = dimensions.y - 1 - y; |
| | | |
| | | if (!arrTowerFreezeBreathEffect[x, dy]) return; |
| | | |
| | | ParticleSystem ps = arrTowerFreezeBreathEffect[x, dy].GetComponent<ParticleSystem>(); |
| | | |
| | | if (ps == null) |
| | | ps = arrTowerFreezeBreathEffect[x, dy].transform.GetChild(0).GetComponent<ParticleSystem>(); |
| | | |
| | | if (play) |
| | | { |
| | | if (!arrTowerFreezeBreathEffect[x, dy].gameObject.activeSelf) |
| | | arrTowerFreezeBreathEffect[x, dy].gameObject.SetActive(true); |
| | | ps.Play(); |
| | | } |
| | | else |
| | | { |
| | | ps.Stop(); |
| | | arrTowerFreezeBreathEffect[x, dy].gameObject.SetActive(false); |
| | | } |
| | | } |
| | | |
| | |
| | | /// <param name="allTowerP"></param> |
| | | public void PlayPS(List<IntVector2> allTowerP) |
| | | { |
| | | for (int i = 0; i < allTowerP.Count; i++) |
| | | { |
| | | m_Tiles[allTowerP[i].x, allTowerP[i].y].SetParticleSystem(true); |
| | | } |
| | | // for (int i = 0; i < allTowerP.Count; i++) |
| | | // { |
| | | // m_Tiles[allTowerP[i].x, allTowerP[i].y].SetParticleSystem(true); |
| | | // } |
| | | } |
| | | /// <summary> |
| | | /// /// 停止所有升级动画 |
| | | /// </summary> |
| | | public void StopPS() |
| | | { |
| | | int iy = dimensions.y - 1;//3 |
| | | 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].SetParticleSystem(false); |
| | | } |
| | | } |
| | | } |
| | | // int iy = dimensions.y - 1;//3 |
| | | // 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].SetParticleSystem(false); |
| | | // } |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | } |
| | | } |
| | | StopPS(); |
| | | //StopPS(); |
| | | } |
| | | |
| | | #if UNITY_EDITOR |
| | |
| | | freePos = gridFreePos; |
| | | else if (y > 0 && y == dimensions.y - 2) |
| | | freePos = gridFreePos2; |
| | | |
| | | else if (y > 0 && y == dimensions.y - 3) |
| | | freePos = gridFreePos3; |
| | | else if (y == dimensions.y - 4) |
| | | freePos = gridFreePos4; |
| | | for (int x = 0; x < dimensions.x; x++) |
| | | { |
| | | var position = new Vector3((x + 0.5f) * gridSize, 0, (y + 0.5f) * gridSize + freePos); |