chenxin
2020-11-18 90b098fe0b1219a4a2c23aef55a3e8366fd1fcdf
Assets/Scripts/TowerDefense/Towers/Placement/TowerPlacementGridEndless.cs
@@ -37,7 +37,7 @@
        /// <summary>
        /// 等待购买开启对应按钮.
        /// </summary>
        public Button waitBuyBtnPrefab;
        public GameObject waitBuyBtnPrefab;
        /// <summary>
        /// 最后一行格子与前一行格子之间的空位长度.
@@ -45,6 +45,10 @@
        public float gridFreePos;
        public float gridFreePos2;
        public float gridFreePos3;
        public float gridFreePos4;
        /// <summary>
        /// The dimensions of the grid 
@@ -443,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;
@@ -577,12 +589,25 @@
            // Precalculate inverted grid size, to save a division every time we translate coords
            m_InvGridSize = 1 / gridSize;
            SetUpGrid();
            // 初始化格子对应的屏幕坐标数据 延迟执行
            Invoke("preCalculateGridUIPos", 0.3f);
            //preCalculateGridUIPos();
            EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.EndlessCritBulletNumChange, OnCritBulletNumChange);
        }
        /// <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>
@@ -616,19 +641,31 @@
            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 + (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;
@@ -753,7 +790,7 @@
                    arrTowerEnergyEffect[x, y] = Instantiate(energyEffectPrefab);
                    arrTowerEnergyEffect[x, y].transform.position = vpos;
                    // 创建水精灵充能条
                    img = Instantiate(FreezeBreathChargePrefab);
                    img.transform.SetParent(container.transform);
@@ -1012,27 +1049,27 @@
        /// <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>
@@ -1079,7 +1116,7 @@
                    }
                }
            }
            StopPS();
            //StopPS();
        }
#if UNITY_EDITOR
@@ -1130,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);