wangguan
2020-11-10 921ba9372bc0b8be17b00fd0e1240c10ac61403e
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;
@@ -113,6 +114,13 @@
        private BulletUICtl[,] arrTowerBulletUi;
        private EnergyUICtl[,] arrTowerEnergyUi;
        private ParticleSystem[,] arrTowerEnergyEffect;
        /// <summary>
        /// 充能特效对应的Prefab.
        /// </summary>
        public ParticleSystem energyEffectPrefab;
        /// <summary>
        /// 此位置上塔对应的子弹充能Prefab.塔放置到当前的塔位后,如果是对应的塔防类型,需要把
@@ -268,13 +276,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>
        /// 是否是等待购买的攻击塔位.
@@ -537,8 +551,9 @@
            SetUpGrid();
            // 初始化格子对应的屏幕坐标数据
            preCalculateGridUIPos();
            // 初始化格子对应的屏幕坐标数据 延迟执行
            Invoke("preCalculateGridUIPos", 0.3f);
            //preCalculateGridUIPos();
        }
        /// <summary>
@@ -583,7 +598,7 @@
                    Vector3 pos = buyButton.transform.position;
                    pos.x = arrGridCentPos[x, y].x;
                    pos.z = arrGridCentPos[x, y].y + (y - AttackRowNumbers) * 1.9f;
                    pos.z = arrGridCentPos[x, y].y;
                    pos.y = 30;
                    buyButton.transform.position = pos;
                    buyButton.transform.localRotation = Quaternion.identity;
@@ -642,6 +657,7 @@
            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];
            for (int x = 0; x < dimensions.x; x++)
            {
@@ -652,6 +668,7 @@
                    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 container = GameObject.Find("BuyButtonContainer");
                    img.transform.SetParent(container.transform);
@@ -671,7 +688,7 @@
                    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.z = m_arrTowerBulletUIPos[x, y].y - 0.5f;
                    tpos.y = 30f;
                    img.transform.position = tpos;
                    img.transform.localScale = Vector3.one;
@@ -686,7 +703,7 @@
                    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.z = m_arrTowerBulletUIPos[x, y].y - 0.5f;
                    tpos.y = 30f;
                    img.transform.position = tpos;
                    img.transform.localScale = Vector3.one;
@@ -695,13 +712,22 @@
                    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 -= (gridSize / 2.0f);
                    vpos.y += 5.0f;
                    arrTowerEnergyEffect[x, y] = Instantiate(energyEffectPrefab);
                    arrTowerEnergyEffect[x, y].transform.position = vpos;
                    arrTowerEnergyEffect[x, y].Stop();
                }
            }
        }
        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++)
            {
@@ -784,6 +810,25 @@
            }
            // 设置塔位默认开启,后面需要根据配置来
            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;
            if (play)
                arrTowerEnergyEffect[x, dy].Play();
            else
                arrTowerEnergyEffect[x, dy].Stop();
        }
        /// <summary>
@@ -834,6 +879,80 @@
                        m_Tiles[x, y] = newTile;
                        newTile.SetTileType(m_arrGridType[x, y]);
                        newTile.CheckCanPlace(false);//初始化不显示
                    }
                }
            }
        }
        /// <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);
                    }
                }
            }
        }
        PlacementTile currentCanPlace;//记录当前标记
        /// <summary>
        /// 拖动时候实时检查距离哪个格子近
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public void CheckCanPlaceUpdate(int x, int y)
        {
            CloseCanPlace();
            currentCanPlace = m_Tiles[x, y];
            currentCanPlace.SetSelect(true);
        }
        /// <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);
                    }
                }
            }