Пример #1
0
    void Start()
    {
        textPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>("Assets/New Text.prefab");

        random = new Unity.Mathematics.Random((uint)UnityEngine.Random.Range(0, 10000));
        //random = new Unity.Mathematics.Random(2456235);

        worley = new WorleyNoise()
        {
            frequency = 0.075f,
            //seed = random.NextInt(),
            seed               = -878905037,
            perterbAmp         = 0,
            cellularJitter     = 0.3f,
            distanceFunction   = WorleyNoise.DistanceFunction.Euclidean,
            cellularReturnType = WorleyNoise.CellularReturnType.Distance2
        };

        Debug.Log("Seed: " + worley.seed);

        TreeGenerator generator = new TreeGenerator
        {
            worley     = this.worley,
            meshPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>("Assets/TreeMesh.prefab"),
            material   = UnityEditor.AssetDatabase.LoadAssetAtPath <Material>("Assets/Materials/DefaultMat.mat"),
            simplex    = new SimplexNoise(worley.seed, 0.1f)
        };

        bool one   = false;
        int  range = 1;

        if (!one)
        {
            for (int x = -range; x <= range; x++)
            {
                for (int z = -range; z <= range; z++)
                {
                    int2 index = new int2(x, z);
                    generator.Generate(index);
                }
            }
        }
        else
        {
            generator.Generate(new int2(0));
        }

        //DebugWorley(30);
    }
Пример #2
0
    //VARS

    //LISTS

    public IEnumerator Load()
    {
        M   = GameObject.FindWithTag("Manager").GetComponent <Manager>();
        MM  = GameObject.FindWithTag("MenuManager").GetComponent <MenuManager>();
        MUI = MM.GetComponent <ManagerUI>();

        StartCoroutine(TG.Generate());
        while (TG.isWorking)
        {
            yield return(null);
        }

        for (int i = 0; i < Roads.Count; i++)
        {
            yield return(null);

            yield return(null);

            Roads[i].SpawnCars(M);
        }

        yield return(null);

        MUI.ShowStartMenu();

        M.GameStarted = true;
    }
Пример #3
0
        public void GenTrees(IWorld world, IGrainFactory grainFactory, ChunkColumnCompactStorage chunk, Random random, BlockWorldPos pos)
        {
            int treesPerChunk = _treesPerChunk;

            if (random.NextDouble() < _extraTreeChance)
            {
                ++treesPerChunk;
            }

            for (int num = 0; num < treesPerChunk; ++num)
            {
                int x = random.Next(12) + 2;
                int z = random.Next(12) + 2;

                TreeGenerator treeGenerator = new TreeGenerator(5, false, GetRandomTree(random));

                // 获得地表面高度
                int h = 0;
                for (int y = 255; y >= 0; --y)
                {
                    if (!chunk[x, y, z].IsAir())
                    {
                        h = y + 1;
                        break;
                    }
                }

                treeGenerator.Generate(world, grainFactory, chunk, this, random, new BlockWorldPos(pos.X + x, h, pos.Z + z));
            }
        }
Пример #4
0
    private IEnumerator GenerateColumn(int cx, int cz)
    {
        yield return(StartCoroutine(terrainGenerator.Generate(cx, cz)));

        yield return(null);

        int x = cx * Chunk.SIZE_X + Chunk.SIZE_X / 2;
        int z = cz * Chunk.SIZE_Z + Chunk.SIZE_Z / 2;
        int y = map.GetMaxY(x, z) + 1;

        treeGenerator.Generate(x, y, z);
    }
Пример #5
0
        // 添加其他东西
        public override void Decorate(IWorld world, IGrainFactory grainFactory, ChunkColumnCompactStorage chunk, Random rand, BlockWorldPos pos)
        {
            float grassColor = (_grassColorNoise.Noise((pos.X + 8) / 200.0F, 0.0F, (pos.Z + 8) / 200.0F) - 0.5F) * 2;

            if (grassColor < -0.8F)
            {
                _flowersPerChunk = 15;
                _grassPerChunk   = 5 * 7;
                GenDoubleFlowers(world, grainFactory, chunk, rand, pos);
            }
            else
            {
                _flowersPerChunk = 4;
                _grassPerChunk   = 10 * 7;
            }

            GenGrass(world, grainFactory, chunk, rand, pos);
            GenFlowers(world, grainFactory, chunk, rand, pos);
            GenDoubleGrass(world, grainFactory, chunk, rand, pos);

            int treesPerChunk = _treesPerChunk;

            if (rand.NextDouble() < _extraTreeChance)
            {
                ++treesPerChunk;
            }

            for (int num = 0; num < treesPerChunk; ++num)
            {
                int x = rand.Next(12) + 2;
                int z = rand.Next(12) + 2;

                TreeGenerator treeGenerator = new TreeGenerator(5, false, GetRandomTree(rand));

                // 获得地表面高度
                int h = 0;
                for (int y = 255; y >= 0; --y)
                {
                    if (!chunk[x, y, z].IsAir())
                    {
                        h = y + 1;
                        break;
                    }
                }

                treeGenerator.Generate(world, grainFactory, chunk, this, rand, new BlockWorldPos(pos.X + x, h, pos.Z + z));
            }

            base.Decorate(world, grainFactory, chunk, rand, pos);
        }
Пример #6
0
        protected override async Task RunModule()
        {
            TreeGenerator rg = new TreeGenerator();

            rg.NodeCount     = (int)Handler[NumberOfNodes].Value;
            rg.MaxDepth      = (int)Handler[MaxDepth].Value;
            rg.MaxChildCount = (int)Handler[MaxChildCount].Value;

            rg.Generate(CurrentIGraph);
            int i = 0;

            foreach (INode node in CurrentIGraph.Nodes)
            {
                CurrentIGraph.AddLabel(node, "" + ++i);
            }
            GraphControl.Invalidate();
            await new TreeLayoutModule {
                RunInBackground = false
            }.Start(Context);
        }