public override void Create(List <MapFloorConfig> config, int[,] map)
        {
            bool[,] tmpMap = new bool[map.GetLength(0), map.GetLength(1)];

            for (int x = 0; x < map.GetLength(0); x++)
            {
                for (int y = 0; y < map.GetLength(1); y++)
                {
                    if (map[x, y] > 0)
                    {
                        tmpMap[x, y] = true;
                    }
                }
            }

            foreach (var item in config)
            {
                for (int x = 0; x < map.GetLength(0); x++)
                {
                    for (int y = 0; y < map.GetLength(1); y++)
                    {
                        foreach (var e in item.depthInfos)
                        {
                            if (map[x, y] == e.depth && tmpMap[x, y] && this.AnalyzeFloor(x, y, map, e.depth) == e.mapAssetAllowRefreshPosition)
                            {
                                var tmp = Random.Range(1, 101);
                                if (tmp < e.refreshRate)
                                {
                                    RandomMapHelper.CreateMapQuickly(item.mapAsset, new Vector3(x, 0, y));
                                    tmpMap[x, y] = false;
                                }
                            }
                        }
                    }
                }
            }


            foreach (var item in config)
            {
                if (item.isPrimary)
                {
                    for (int x = 0; x < map.GetLength(0); x++)
                    {
                        for (int y = 0; y < map.GetLength(1); y++)
                        {
                            if (tmpMap[x, y])
                            {
                                RandomMapHelper.CreateMapQuickly(item.mapAsset, new Vector3(x, 0, y));
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 创建水
 /// </summary>
 private void CreateWater(MapBarrierConfig config, int[,] map)
 {
     for (int x = 0; x < map.GetLength(0); x++)
     {
         for (int y = 0; y < map.GetLength(1); y++)
         {
             var tmp = map[x, y];
             if (tmp < 0 && tmp > -1000)
             {
                 RandomMapHelper.CreateMapQuickly(config.mapAsset, new UnityEngine.Vector3(x, 0, y));
             }
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 创建山
 /// </summary>
 private void CreateMountain(MapBarrierConfig config, int[,] map)
 {
     for (int x = 0; x < map.GetLength(0); x++)
     {
         for (int y = 0; y < map.GetLength(1); y++)
         {
             var tmp = map[x, y];
             if (tmp <= -1000)
             {
                 var h = Mathf.Abs(tmp) / 1000;
                 RandomMapHelper.CreateMapQuickly(config.mapAsset, new UnityEngine.Vector3(x, h, y));
             }
         }
     }
 }
        private void RandomAsset(MapAssetConfig config, List <Vector2Int> map)
        {
            int  loopNumber = 0;
            bool isOK       = true;

            if (!dicTmpData.TryGetValue(config, out List <GameObject> objs))
            {
                objs = new List <GameObject>();
                dicTmpData.Add(config, objs);
            }
            int quantity = config.generateNumber;

            while (isOK)
            {
                if (map.Count == 0 || quantity == 0)
                {
                    return;
                }
                var randomPoint = Random.Range(0, map.Count);
                var mapPoint    = map[randomPoint];
                if (!this.tmpMap[mapPoint.x, mapPoint.y])
                {
                    bool isCreate = true;
                    foreach (var item in objs)
                    {
                        if (Vector3.Distance(item.transform.position, new Vector3(mapPoint.x, 1, mapPoint.y)) < config.minDistance)
                        {
                            isCreate = false;
                            continue;
                        }
                    }
                    if (isCreate)
                    {
                        var obj = RandomMapHelper.CreateMapQuickly(config.mapAsset, new Vector3(mapPoint.x, 1, mapPoint.y));
                        objs.Add(obj);
                        this.tmpMap[mapPoint.x, mapPoint.y] = true;
                        quantity--;
                    }
                }
                loopNumber++;
                if (quantity <= 0 || map.Count < objs.Count * config.minDistance || loopNumber > 1000)
                {
                    isOK = false;
                }
            }
        }