コード例 #1
0
        private FloraType[,] CreateFlora()
        {
            var gridSize      = terrain.GridSize;
            var grassBlocks   = terrain.GrassBlocks.ToList();
            var nbGrassBlocks = grassBlocks.Count;

            var floraTypes = new Dictionary <FloraType, int>
            {
                [FloraType.Grass] = (int)(nbGrassBlocks * grassDensity),
                [FloraType.Tree]  = (int)(nbGrassBlocks * treesDensity),
                [FloraType.Rock]  = (int)(nbGrassBlocks * rocksDensity)
            };

            var random = randomSeed.CreateRandom();

            var floraObjects = new FloraType[gridSize.x, gridSize.y].Fill(FloraType.None);

            while (floraTypes.Count > 0 && grassBlocks.Count > 0)
            {
                var position  = grassBlocks.RemoveRandom(random).GridPosition;
                var floraType = floraTypes.SubtractRandom(random);

                floraObjects[position.x, position.y] = floraType;
            }

            return(floraObjects);
        }
コード例 #2
0
ファイル: FaunaGenerator.cs プロジェクト: Therlys/tp1
        private void CreateFauna()
        {
            var nodes         = navigationMesh.Nodes.ToList();
            var nbGrassBlocks = nodes.Count;

            var faunaPrefabs = new Dictionary <int, int>
            {
                [0] = (int)(nbGrassBlocks * bunniesDensity),
                [1] = (int)(nbGrassBlocks * foxDensity),
            };

            var bunnyId = 0ul;
            var foxId   = 0ul;
            var random  = randomSeed.CreateRandom();

            while (faunaPrefabs.Count > 0 && nodes.Count > 0)
            {
                var position = nodes.RemoveRandom(random).Position3D;
                var prefab   = faunaPrefabs.SubtractRandom(random);

                if (prefab == 0)
                {
                    prefabFactory.CreateBunny(bunnyId++.ToString(), position, faunaRoot);
                }
                else
                {
                    prefabFactory.CreateFox(foxId++.ToString(), position, faunaRoot);
                }
            }
        }
コード例 #3
0
 private void UpdateRandom()
 {
     random = randomSeed.CreateRandom();
 }
コード例 #4
0
 protected void Awake()
 {
     randomSeed     = Finder.RandomSeed;
     navigationMesh = Finder.NavigationMesh;
     random         = randomSeed.CreateRandom();
 }