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;
@@ -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>
        /// 是否是等待购买的攻击塔位.
@@ -544,8 +551,9 @@
            SetUpGrid();
            // 初始化格子对应的屏幕坐标数据
            preCalculateGridUIPos();
            // 初始化格子对应的屏幕坐标数据 延迟执行
            Invoke("preCalculateGridUIPos", 0.3f);
            //preCalculateGridUIPos();
        }
        /// <summary>
@@ -590,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;
@@ -660,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);
@@ -679,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;
@@ -694,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;
@@ -870,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);
                    }
                }
            }