wangguan
2020-11-11 fd1ac06475bf155996ac4aed6307eb43f9e04f53
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;
@@ -275,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>
        /// 是否是等待购买的攻击塔位.
@@ -844,7 +851,8 @@
        {
            PlacementTile tileToUse;
#if UNITY_STANDALONE
         tileToUse = placementTilePrefab;
         //tileToUse = placementTilePrefab;
         tileToUse = placementTilePrefabMobile;
#else
            tileToUse = placementTilePrefabMobile;
#endif
@@ -872,11 +880,117 @@
                        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)
        {
            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);
                    }
                }
            }
            StopPS();
        }
#if UNITY_EDITOR
        /// <summary>
        /// On editor/inspector validation, make sure we size our collider correctly.