chenxin
2020-11-28 ee2cbc86ed58ae03a092b67690d3869ebe78fd20
Assets/Scripts/TowerDefense/Towers/Placement/TowerPlacementGridEndless.cs
@@ -16,7 +16,7 @@
    [RequireComponent(typeof(BoxCollider))]
    public class TowerPlacementGridEndless : MonoBehaviour, IPlacementArea
    {
        public static float GRID_OPENCASH = 100;
        public static float GRID_OPENCASH = 200;
        /// <summary>
        /// Prefab used to visualise the grid.
@@ -589,12 +589,26 @@
            // 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);
            EventCenter.Ins.Add((int)KTGMGemClient.EventType.OpenAllTowerGrid, OpenAllTowerGrid);
        }
        /// <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>
@@ -625,11 +639,11 @@
            // 血条位置的设定
            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)
@@ -639,7 +653,7 @@
                    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];
@@ -655,15 +669,13 @@
                    // }
                    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;
                    }
                }
@@ -801,7 +813,7 @@
        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++)
            {
@@ -854,6 +866,30 @@
        }
        /// <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>
@@ -879,11 +915,11 @@
            for (int tx = 0; tx < dimensions.x; tx++)
            {
                m_arrGridType[tx, sy] = PlacementGridType.EGridWaitBuy;
                // cx test
                m_arrGridType[tx, sy - 1] = PlacementGridType.EGridWaitBuy;
                m_arrGridType[tx, sy] = PlacementGridType.EGridOpen;
            }
            // 设置塔位默认开启,后面需要根据配置来
            m_arrGridType[2, 3] = PlacementGridType.EGridOpen;
            // m_arrGridType[2, 3] = PlacementGridType.EGridOpen;
            ++GameConfig.EndlessOpenAttackTowerCount;
        }
@@ -991,7 +1027,7 @@
                        m_Tiles[x, y] = newTile;
                        newTile.SetTileType(m_arrGridType[x, y]);
                        newTile.CheckCanPlace(false);//初始化不显示
                        newTile.SetRender(false, "");//初始化不显示
                    }
                }
            }
@@ -1015,15 +1051,18 @@
                    if (m_arrGridType[ix, y] == PlacementGridType.EGridOpen)
                    {
                        canPlace = true;
                        for (int i = 0; i < allTowerP.Count; i++)
                        if (allTowerP != null)
                        {
                            if (allTowerP[i].x == ix && allTowerP[i].y == y)
                            for (int i = 0; i < allTowerP.Count; i++)
                            {
                                canPlace = false;
                                break;
                                if (allTowerP[i].x == ix && allTowerP[i].y == y)
                                {
                                    canPlace = false;
                                    break;
                                }
                            }
                        }
                        m_Tiles[ix, y].CheckCanPlace(canPlace);
                        //m_Tiles[ix, y].CheckCanPlace(canPlace);
                    }
                }
            }
@@ -1068,11 +1107,11 @@
        {
            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>
@@ -1082,7 +1121,7 @@
        {
            if (currentCanPlace != null)
            {
                currentCanPlace.SetSelect(false);
                currentCanPlace.SetRender(false, "");
                currentCanPlace = null;
            }
        }
@@ -1099,7 +1138,8 @@
                {
                    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, "");
                    }
                }
            }