コード例 #1
0
ファイル: ObstacleBuilder.cs プロジェクト: frozen4/UnityPlus
        public FileMapRegion CreateFileMapRegion(float fGridSize, out string errMsg)
        {
            FileMapRegion fileMapRegion = new FileMapRegion();

            var obstacles = _map.EntityGeneratorRoot.EntityGenerators;

            //build header
            fileMapRegion.Header.magic     = new byte[] { (byte)'M', (byte)'R', (byte)'G', (byte)'N' };
            fileMapRegion.Header.version   = FileMapRegion.VERSION;
            fileMapRegion.Header.fWorldWid = _map.Width;
            fileMapRegion.Header.fWorldLen = _map.Length;
            fileMapRegion.Header.fGridSize = fGridSize;

            errMsg = "";
            foreach (var obstacle in obstacles)
            {
                if (obstacle.EntityType != (int)EntityType.Obstacle)
                {
                    continue;
                }

                string          err;
                ObstacleBuilder builder = new ObstacleBuilder(_map, obstacle, fGridSize);
                HashSet <uint>  gridSet = builder.BuildRegionHashSet(out err);
                if (gridSet == null || gridSet.Count == 0)
                {
                    errMsg += err;
                    errMsg += "\n";
                    continue;
                }

                FileRegion fileRegion = new FileRegion();
                fileRegion.Id            = obstacle.Id;
                fileRegion.GridNum       = gridSet.Count;
                fileRegion.RegionGridSet = gridSet;

                //add file region
                fileMapRegion.AddFileRegion(fileRegion);
            }
            fileMapRegion.Header.iNumRegion = fileMapRegion.RegionMap.Count;

            return(fileMapRegion);
        }
コード例 #2
0
        public FileMapRegion CreateFileMapRegion(float fGridSize, out string errMsg)
        {
            FileMapRegion fileMapRegion = new FileMapRegion();

            var regions = _map.RegionRoot.Regions;

            //build header
            fileMapRegion.Header.magic      = new byte[] { (byte)'M', (byte)'R', (byte)'G', (byte)'N' };
            fileMapRegion.Header.version    = 1;
            fileMapRegion.Header.fWorldWid  = _map.Width;
            fileMapRegion.Header.fWorldLen  = _map.Length;
            fileMapRegion.Header.fGridSize  = fGridSize;
            fileMapRegion.Header.iNumRegion = regions.Count;

            errMsg = "";
            foreach (var region in regions)
            {
                string         err;
                RegionBuilder  builder = new RegionBuilder(_map, region, fGridSize);
                HashSet <uint> gridSet = builder.BuildRegionHashSet(out err);
                if (gridSet == null)
                {
                    errMsg += err;
                    errMsg += "\n";
                    continue;
                }

                FileRegion fileRegion = new FileRegion();
                fileRegion.Id            = region.Id;
                fileRegion.GridNum       = gridSet.Count;
                fileRegion.RegionGridSet = gridSet;

                //add file region
                fileMapRegion.AddFileRegion(fileRegion);
            }

            return(fileMapRegion);
        }