From 90b098fe0b1219a4a2c23aef55a3e8366fd1fcdf Mon Sep 17 00:00:00 2001 From: chenxin <chenxin6991@163.com> Date: Wed, 18 Nov 2020 12:29:52 +0800 Subject: [PATCH] 新增buff验证测试 --- Assets/Scripts/TowerDefense/Towers/Placement/TowerPlacementGridEndless.cs | 471 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 391 insertions(+), 80 deletions(-) diff --git a/Assets/Scripts/TowerDefense/Towers/Placement/TowerPlacementGridEndless.cs b/Assets/Scripts/TowerDefense/Towers/Placement/TowerPlacementGridEndless.cs index 214c076..6ca6cb3 100644 --- a/Assets/Scripts/TowerDefense/Towers/Placement/TowerPlacementGridEndless.cs +++ b/Assets/Scripts/TowerDefense/Towers/Placement/TowerPlacementGridEndless.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Core.Utilities; using KTGMGemClient; using TowerDefense.Level; @@ -36,7 +37,7 @@ /// <summary> /// 等待购买开启对应按钮. /// </summary> - public Button waitBuyBtnPrefab; + public GameObject waitBuyBtnPrefab; /// <summary> /// 最后一行格子与前一行格子之间的空位长度. @@ -44,6 +45,10 @@ public float gridFreePos; public float gridFreePos2; + + public float gridFreePos3; + + public float gridFreePos4; /// <summary> /// The dimensions of the grid @@ -77,12 +82,14 @@ /// </summary> private EndlessTowerGridOpen[,] m_arrTGO; + public GameObject[] TowerGridOpenObjArr; + private float[,] m_arrCoinGenTime; /// <summary> - /// 每一个Tile格子的中心点对应的屏幕坐标. + /// 每一个Tile格子的中心店的世界坐标 /// </summary> - private Vector2[,] m_arrGridCentUIPos; + private Vector2[,] arrGridCentPos; /// <summary> /// 攻击塔位对应的UI位置信息. @@ -95,11 +102,6 @@ private TowerBloodVis[,] arrTowerBloodUi; /// <summary> - /// 塔位对应的屏幕坐标尺寸 - /// </summary> - private float m_fGridUISize; - - /// <summary> /// Array of <see cref="PlacementTile"/>s /// </summary> private PlacementTile[,] m_Tiles; @@ -109,6 +111,50 @@ /// </summary> /// <value></value> public int AttackRowNumbers { get; } = 2; + + /// <summary> + /// 攻击塔位对应的子弹UI位置信息. + /// </summary> + private Vector2[,] m_arrTowerBulletUIPos; + + private BulletUICtl[,] arrTowerBulletUi; + + private EnergyUICtl[,] arrTowerEnergyUi; + + private FreezeBreath[,] arrTowerFreezeBreathUi; + + private GameObject[,] arrTowerEnergyEffect; + + /// <summary> + /// 水精灵充能满特效 + /// </summary> + private GameObject[,] arrTowerFreezeBreathEffect; + + /// <summary> + /// 充能特效对应的Prefab. + /// </summary> + public GameObject energyEffectPrefab; + + /// <summary> + /// 此位置上塔对应的子弹充能Prefab.塔放置到当前的塔位后,如果是对应的塔防类型,需要把 + /// 相应的界面指针传到塔防的数据结构内。 + /// </summary> + public GameObject towerBulletUIPrefab; + + /// <summary> + /// 充能条对应的界面 + /// </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. @@ -152,9 +198,30 @@ /// </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, int y) + { + 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> @@ -242,13 +309,19 @@ 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> /// 是否是等待购买的攻击塔位. @@ -289,7 +362,7 @@ void Update() { - if (m_arrCoinGenTime == null) return; + if (m_arrCoinGenTime == null || !EndlessUIStart.instance.IsGameRunning) return; float delta = Time.deltaTime; float timePe = JsonDataCenter.GOLD_TIME / 1000.0f; @@ -374,6 +447,14 @@ 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; @@ -508,11 +589,25 @@ // Precalculate inverted grid size, to save a division every time we translate coords m_InvGridSize = 1 / gridSize; - SetUpGrid(); + // 初始化格子对应的屏幕坐标数据 延迟执行 + Invoke("preCalculateGridUIPos", 0.3f); + EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.EndlessCritBulletNumChange, OnCritBulletNumChange); + } - // 初始化格子对应的屏幕坐标数据 - preCalculateGridUIPos(); + /// <summary> + /// 木属性暴击子弹数量改变 + /// </summary> + /// <param name="count"></param> + private void OnCritBulletNumChange(int count) + { + for (int i = 0; i < dimensions.x; ++i) + { + for (int j = 0; j < AttackRowNumbers; ++j) + { + arrTowerBulletUi[i, j].CritBulletNum = count; + } + } } /// <summary> @@ -522,80 +617,62 @@ /// </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(); + float[] gapArr = { 0.2f, 0.7f }; m_arrTGO = new EndlessTowerGridOpen[dimensions.x, dimensions.y]; - // 设置界面相关的内容: - for (int y = dimensions.y - AttackRowNumbers; y < dimensions.y; 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 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 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 + (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; + buyButton.transform.localScale = Vector3.one; // 设置按钮对应的点击功能 - EndlessTowerGridOpen tgo = tbtn.GetComponent<EndlessTowerGridOpen>(); + EndlessTowerGridOpen tgo = buyButton.GetComponent<EndlessTowerGridOpen>(); if (tgo) { tgo.SetBuyBtnInfo(x, y, this); @@ -643,37 +720,101 @@ 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]; + 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++) { 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; + // 现在PVE基地不需要血条 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); + + Vector3 targetPos = GridToWorld(new IntVector2(x, dy - y), new IntVector2(2, 1)); + + // 子弹条 + img = Instantiate(towerBulletUIPrefab); + 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; + buc.gameObject.SetActive(false); + + // 把充能条也创建出来了. + img = Instantiate(towerEnergyUIPrefab); + 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; + + EnergyUICtl euc = img.GetComponent<EnergyUICtl>(); + arrTowerEnergyUi[x, y] = euc; + euc.gameObject.SetActive(false); + + // 设置播放特效对应的3D坐标: + Vector3 vpos = GridToWorld(new IntVector2(x, dy - y), new IntVector2(2, 1)); + vpos.x -= 1f; + + arrTowerEnergyEffect[x, y] = Instantiate(energyEffectPrefab); + arrTowerEnergyEffect[x, y].transform.position = vpos; + + // 创建水精灵充能条 + 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; } } } public void updateGridOpenCoin(int ix, int iy) { - GRID_OPENCASH += GRID_OPENCASH; + GRID_OPENCASH = Mathf.Floor(GRID_OPENCASH * 1.2f); for (int x = 0; x < dimensions.x; x++) { @@ -756,6 +897,62 @@ } // 设置塔位默认开启,后面需要根据配置来 m_arrGridType[2, 3] = PlacementGridType.EGridOpen; + ++GameConfig.EndlessOpenAttackTowerCount; + } + + /// <summary> + /// 在指定的位置播放充能成功的特效. + /// </summary> + /// <param name="x"></param> + /// <param name="y"></param> + /// <param name="play">是播放还是停止播放</param> + public void PlayEnergyEffect(int x, int y, bool play = true) + { + int dy = dimensions.y - 1 - y; + + 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); + ps.Play(); + } + else + { + + 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); + } } /// <summary> @@ -778,7 +975,8 @@ { PlacementTile tileToUse; #if UNITY_STANDALONE - tileToUse = placementTilePrefab; + //tileToUse = placementTilePrefab; + tileToUse = placementTilePrefabMobile; #else tileToUse = placementTilePrefabMobile; #endif @@ -806,9 +1004,119 @@ m_Tiles[x, y] = newTile; newTile.SetTileType(m_arrGridType[x, y]); + newTile.CheckCanPlace(false);//初始化不显示 } } } + } + + PlacementTile currentCanPlace;//记录当前标记 + + /// <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); + } + } + } + } + + + /// <summary> + /// 播放升级动画 + /// </summary> + /// <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); + // } + } + /// <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); + // } + // } + // } + } + + /// <summary> + /// 拖动时候实时检查距离哪个格子近 + /// </summary> + /// <param name="x"></param> + /// <param name="y"></param> + public void CheckCanPlaceUpdate(int x, int y, bool isEmpty, string towerName) + { + CloseCanPlace(); + currentCanPlace = m_Tiles[x, y]; + currentCanPlace.SetSelect(true); + if (isEmpty) + { + currentCanPlace.SetTowerVirtualshadow(towerName); + } + } + + /// <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); + } + } + } + //StopPS(); } #if UNITY_EDITOR @@ -859,7 +1167,10 @@ 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); -- Gitblit v1.9.1