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;
@@ -106,6 +107,33 @@
        public int AttackRowNumbers { get; } = 2;
        /// <summary>
        /// 攻击塔位对应的子弹UI位置信息.
        /// </summary>
        private Vector2[,] m_arrTowerBulletUIPos;
        private BulletUICtl[,] arrTowerBulletUi;
        private EnergyUICtl[,] arrTowerEnergyUi;
        private ParticleSystem[,] arrTowerEnergyEffect;
        /// <summary>
        /// 充能特效对应的Prefab.
        /// </summary>
        public ParticleSystem energyEffectPrefab;
        /// <summary>
        /// 此位置上塔对应的子弹充能Prefab.塔放置到当前的塔位后,如果是对应的塔防类型,需要把
        /// 相应的界面指针传到塔防的数据结构内。
        /// </summary>
        public GameObject towerBulletUIPrefab;
        /// <summary>
        /// 充能条对应的界面
        /// </summary>
        public GameObject towerEnergyUIPrefab;
        /// <summary>
        /// Converts a location in world space into local grid coordinates.
        /// </summary>
        /// <param name="worldLocation"><see cref="Vector3"/> indicating world space coordinates to convert.</param>
@@ -147,9 +175,9 @@
      /// </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>
@@ -157,9 +185,9 @@
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public EnergyUICtl GetEnergyUICtl(int x)
        public EnergyUICtl GetEnergyUICtl(int x, int y)
        {
            return null;
            return arrTowerEnergyUi[x, 3 - y];
        }
@@ -248,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>
        /// 是否是等待购买的攻击塔位.
@@ -517,8 +551,9 @@
            SetUpGrid();
            // 初始化格子对应的屏幕坐标数据
            preCalculateGridUIPos();
            // 初始化格子对应的屏幕坐标数据 延迟执行
            Invoke("preCalculateGridUIPos", 0.3f);
            //preCalculateGridUIPos();
        }
        /// <summary>
@@ -563,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;
@@ -618,20 +653,29 @@
            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];
            arrTowerEnergyEffect = new ParticleSystem[dimensions.x, AttackRowNumbers];
            for (int x = 0; x < dimensions.x; x++)
            {
                for (int y = 0; y < AttackRowNumbers; ++y)
                {
                    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 container = GameObject.Find("BuyButtonContainer");
                    img.transform.SetParent(container.transform);
                    Vector3 tpos = img.transform.position;
                    tpos.x = m_arrTowerBloodUIPos[x, y].x;
                    tpos.z = m_arrTowerBloodUIPos[x, y].y + 4.2f - y * 1.66f;
                    tpos.y = 30;
                    tpos.y = 30f;
                    img.transform.position = tpos;
                    img.transform.localScale = Vector3.one;
                    img.transform.localRotation = Quaternion.identity;
@@ -639,13 +683,51 @@
                    TowerBloodVis tbv = img.GetComponent<TowerBloodVis>();
                    arrTowerBloodUi[x, y] = tbv;
                    tbv.gameObject.SetActive(false);
                    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;
                    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.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;
                    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++)
            {
@@ -728,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>
@@ -778,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);
                    }
                }
            }