コード例 #1
0
        public void RebuildNodesOnHighSectorEdges(IntVector3 areaWithSectors, int side)
        {
            WorldArea        area         = Manager.WorldData.WorldAreas[areaWithSectors.X];
            MultiLevelSector sector       = area.SectorGrid[0][areaWithSectors.Y];
            MultiLevelSector higherSector = Manager.GetHigherSectorFromLower(1, sector, area);

            Debug.Log("Lower level  start " + areaWithSectors.Y + "  end " + areaWithSectors.Z);

            // clear out both sides  //area.sectorGrid[1][areaWithSectors.z]
            Manager.RemoveAllAbstractNodesOnSectorEdge(higherSector, side);
            Manager.RemoveAllAbstractNodesOnSectorEdge(
                Manager.GetHigherSectorFromLower(1, area.SectorGrid[0][areaWithSectors.Z], area),
                MultiLevelSectorManager.FlipDirection(side));

            // rebuild side
            RebuildNodesOnHighSectorEdge(1, higherSector, side, MultiLevelSectorManager.EdgeIndexToVector(side), area);
        }
コード例 #2
0
        public void RebuildNodesOnSectorEdges(List <int> sides, int sectorIndex, WorldArea area)
        {
            Vector2          startInSector          = Vector2.zero;
            Vector2          startInNeighbourSector = Vector2.zero;
            Vector2          direction = Vector2.zero;
            MultiLevelSector sector    = area.SectorGrid[0][sectorIndex];

            foreach (int side in sides)
            {
                if (side == 0)
                {
                    startInSector          = new Vector2(sector.Left, sector.Top);
                    startInNeighbourSector = new Vector2(sector.Left, sector.Top - 1);
                    direction = Vector2.right;
                }
                else if (side == 1)
                {
                    startInSector          = new Vector2(sector.Left, sector.Bottom);
                    startInNeighbourSector = new Vector2(sector.Left, sector.Bottom + 1);
                    direction = Vector2.right;
                }
                else if (side == 2)
                {
                    startInSector          = new Vector2(sector.Left, sector.Top);
                    startInNeighbourSector = new Vector2(sector.Left - 1, sector.Top);
                    direction = Vector2.up;
                }
                else if (side == 3)
                {
                    startInSector          = new Vector2(sector.Right, sector.Top);
                    startInNeighbourSector = new Vector2(sector.Right + 1, sector.Top);
                    direction = Vector2.up;
                }

                RebuildNodesOnSectorEdge(sector, side, MultiLevelSectorManager.FlipDirection(side), startInSector,
                                         startInNeighbourSector, direction, area);
            }
        }
コード例 #3
0
ファイル: WorldManager.cs プロジェクト: SachsA/MiningBattle
        private void AddChange(IntVector2 key, Tile tile, WorldArea area, int side)
        {
            IntVector2 otherSectorKey = new IntVector2();
            int        otherSector    = -1;

            // if other side of the sector has already been added, we dont need to add this
            if (side == 0)
            {
                otherSector = tile.SectorIndex - WorldData.MultiLevelSectorManager.GetSectorGridWidthAtLevel(area, 0);
            }
            else if (side == 1)
            {
                otherSector = tile.SectorIndex + WorldData.MultiLevelSectorManager.GetSectorGridWidthAtLevel(area, 0);
            }
            else if (side == 2 && area.SectorGrid[0][tile.SectorIndex].GridX > 0)
            {
                otherSector = tile.SectorIndex - 1;
            }
            else if (side == 3 && area.SectorGrid[0][tile.SectorIndex].GridX <
                     WorldData.MultiLevelSectorManager.GetSectorGridWidthAtLevel(area, 0) - 1)
            {
                otherSector = tile.SectorIndex + 1;
            }

            if (WorldData.Pathfinder.maxLevelAmount > 1)
            {
                // add high level sector changes
                if (WorldData.MultiLevelSectorManager.GetHigherSectorFromLower(1, area.SectorGrid[0][tile.SectorIndex],
                                                                               area) != WorldData.MultiLevelSectorManager.GetHigherSectorFromLower(1,
                                                                                                                                                   area.SectorGrid[0][otherSector], area))
                {
                    IntVector3 highLevelEdgeKey = new IntVector3(area.Index, 0, 0);
                    int        sideValue;
                    if (tile.SectorIndex < otherSector)
                    {
                        sideValue          = side;
                        highLevelEdgeKey.Y = tile.SectorIndex;
                        highLevelEdgeKey.Z = otherSector;
                    }
                    else
                    {
                        sideValue          = MultiLevelSectorManager.FlipDirection(side);
                        highLevelEdgeKey.Y = otherSector;
                        highLevelEdgeKey.Z = tile.SectorIndex;
                    }

                    if (!_sectorEdgeChangesHighLevel.ContainsKey(highLevelEdgeKey))
                    {
                        _sectorEdgeChangesHighLevel.Add(highLevelEdgeKey, sideValue);
                    }
                }
            }

            if (otherSector > 0 && otherSector < area.SectorGrid[0].Length)
            {
                otherSectorKey.X = tile.WorldAreaIndex;
                otherSectorKey.Y = otherSector;

                if (_sectorEdgeChangesLowLevel.ContainsKey(otherSectorKey))
                {
                    if (_sectorEdgeChangesLowLevel[otherSectorKey].Contains(MultiLevelSectorManager.FlipDirection(side))
                        ) // other side already filled in
                    {
                        if (!_sectorChanges.Contains(key)
                            ) // other sector exist and the side. add our sector for general change
                        {
                            _sectorChanges.Add(key);
                        }
                    }
                    else if (!_sectorEdgeChangesLowLevel[key].Contains(side)
                             ) //  other sector exist but not the side. add our sector for Edge change
                    {
                        _sectorEdgeChangesLowLevel[key].Add(side);
                    }
                }
                else // other sector not (yet? )added.   add ourselves and other sector for general change
                {
                    if (!_sectorChanges.Contains(otherSectorKey))
                    {
                        _sectorChanges.Add(otherSectorKey);
                    }

                    if (!_sectorEdgeChangesLowLevel[key].Contains(side))
                    {
                        _sectorEdgeChangesLowLevel[key].Add(side);
                    }
                }
            }
            else if (!_sectorEdgeChangesLowLevel[key].Contains(side)) // other sector does not exist, add ourselves
            {
                _sectorEdgeChangesLowLevel[key].Add(side);
            }
        }