예제 #1
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        AsteroidGenerator body = (AsteroidGenerator)target;

        if (GUILayout.Button("Generate"))
        {
            body.Generate();
        }
    }
예제 #2
0
        public Chunk Generate(ChunkType type, Vector3Int coords, GameObject chunkPrefab)
        {
            Vector3 center = ((Vector3)coords) * chunkSize;
            int     n      = GetRandomAsteroidsCount(type);
            var     b      = new Bounds(center, chunkSize);

            var chunkObj = GameObject.Instantiate(chunkPrefab, center, Quaternion.identity, g.ChunksRoot);
            var chunk    = chunkObj.GetComponent <Chunk>();

            chunk.Init(chunkSize, g, coords);

            for (int i = 0; i < n; i++)
            {
                float   x     = b.PercentX(i, n);
                Vector3 place = b.RandomYZ(x);

                var asteroidType = Rnd.WeightedPick(type.availableTypes);

                var asteroid = AsteroidGenerator.Generate(place, asteroidType, g.AstersRoot);
                chunk.AttachAsteroid(asteroid);
            }

            return(chunk);
        }
 public void OnGenerate()
 {
     _gen.Generate();
 }