コード例 #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;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// 创建 格子集合(元素是固定不变的。变化的是元素里面的参数)
        /// </summary>
        /// <param name="self"></param>
        void CreateAoiGridDict(AoiGridComponent self)
        {
            for (int y = 0; y < self.rcCount; y++)
            {
                for (int x = 0; x < self.rcCount; x++)
                {
                    AoiGrid grid = new AoiGrid((x + y * self.rcCount), x, y);
                    grid.minX = x * self.gridWide;
                    grid.maxX = (x + 1) * self.gridWide;
                    grid.minY = y * self.gridWide;
                    grid.maxY = (y + 1) * self.gridWide;
                    self.Add(grid);

                    grid.Parent = self;
                }
            }
            Console.WriteLine(" AoiGridComponentAwakeSystem-40-grids: " + self.Count);
        }