コード例 #1
0
    public void InitalSpawn(int seed)
    {
        if (!forestContainer)
        {
            forestContainer        = new GameObject("Forest Container").transform;
            forestContainer.parent = transform;
        }

        foliageObjects          = new List <FoliageObject>();
        terrainObjects          = new List <TerrainObject>();
        terrainObjectContainers = new Transform[foliageTypes.Length];

        CancelInvoke();
        Vector2 sampleOffset = new Vector2(-mapSize.x / 2f, -mapSize.z / 2f);

        for (int foliageObjectType = 0; foliageObjectType < foliageTypes.Length; foliageObjectType++)
        {
            TerrainObjectType foliageObjectSettings = foliageTypes[foliageObjectType];
            terrainObjectContainers[foliageObjectType]        = new GameObject(foliageObjectSettings.name + " Container").transform;
            terrainObjectContainers[foliageObjectType].parent = forestContainer;
            foliageObjectSettings.Initialize(terrainLayerMask, objectLayerMask, terrainObjectContainers[foliageObjectType], LevelController.Instance.yearLength);
            foreach (Vector2 sample in new PoissonDiscSampler((int)mapSize.x, (int)mapSize.z, foliageObjectSettings.initialSpawnSampleRadius, foliageObjectSettings.poissonClusterRange, seed).Samples())
            {
                Vector3 position = new Vector3(sample.x + sampleOffset.x, maxTerrainHeight + 5f, sample.y + sampleOffset.x);
                AttemptSpawn(position, foliageObjectSettings, true, foliageObjectType > 0);
            }
        }

        InvokeRepeating("UpdateScores", .1f, scoreUpdateInterval);
        if (reproduceAnnually)
        {
            InvokeRepeating("NewYear", 0.0f, LevelController.Instance.yearLength);
        }
    }