예제 #1
0
        /// <summary>
        /// 得到本人的 九宫格内 最新的 所有单元的 unitId
        /// </summary>
        /// <param name="aoiUnit"></param>
        static void FindAoi(this AoiGridComponent self, AoiUnitComponent aoiUnit)
        {
            aoiUnit.playerIds.MovesSet.Clear();
            aoiUnit.enemyIds.MovesSet.Clear();
            aoiUnit.npcerIds.MovesSet.Clear();

            AoiGrid mygrid = self.Get(aoiUnit.gridId);

            foreach (long gid in mygrid.seeGrids)
            {
                AoiGrid nineGrid = self.Get(gid);
                if (nineGrid.players.Count > 0)
                {
                    foreach (long unitId1 in nineGrid.players)
                    {
                        aoiUnit.playerIds.MovesSet.Add(unitId1);
                    }
                }
                if (nineGrid.enemys.Count > 0)
                {
                    foreach (long unitId2 in nineGrid.enemys)
                    {
                        aoiUnit.enemyIds.MovesSet.Add(unitId2);
                    }
                }
                if (nineGrid.npcers.Count > 0)
                {
                    foreach (long unitId3 in nineGrid.npcers)
                    {
                        aoiUnit.npcerIds.MovesSet.Add(unitId3);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 根据坐标 即时 向地图固定格子 里删除 unitId
        /// </summary>
        /// <param name="aoiUnit"></param>
        public static void RemoveUnitId(this AoiGridComponent self, AoiUnitComponent aoiUnit)
        {
            AoiGrid aoiGrid = self.Get(aoiUnit.gridId);

            if (aoiGrid != null)
            {
                UnitType unitType = aoiUnit.GetParent <Unit>().UnitType;
                switch (unitType)
                {
                case UnitType.Player:
                    if (aoiGrid.players.Contains(aoiUnit.GetParent <Unit>().Id))
                    {
                        aoiGrid.players.Remove(aoiUnit.GetParent <Unit>().Id);
                    }
                    break;

                case UnitType.Monster:
                    if (aoiGrid.enemys.Contains(aoiUnit.GetParent <Unit>().Id))
                    {
                        aoiGrid.enemys.Remove(aoiUnit.GetParent <Unit>().Id);
                    }
                    break;

                case UnitType.Npcer:
                    if (aoiGrid.npcers.Contains(aoiUnit.GetParent <Unit>().Id))
                    {
                        aoiGrid.npcers.Remove(aoiUnit.GetParent <Unit>().Id);
                    }
                    break;
                }
            }
        }