Ejemplo n.º 1
0
    public void TestDropSphere(int x, int y)
    {
        GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        _currentIsland.AddObjectToTile(obj, x, y);
    }
Ejemplo n.º 2
0
    private void PlaceDetails(float[,] heights, int size, ref IslandData data, int seed)
    {
        System.Random prng            = new System.Random(seed);
        int           noiseSeed       = prng.Next();
        GameObject    detailContainer = new GameObject();

        detailContainer.name = "Details Container";
        detailContainer.transform.SetParent(_currentTerrain.transform);
        eBiome currentBiome = eBiome.Forest;

        PerlinGenerator detailNoiseGen = new PerlinGenerator();

        float[][] noise = detailNoiseGen.Generate(noiseSeed, 3, size);

        int detailID = -1;

        for (int i = 0; i < size; ++i)
        {
            for (int j = 0; j < size; ++j)
            {
                detailID = -1;
                bool  changeScale = false;
                float height      = heights[j, i];
                if (height > 0f)
                {
                    float value = noise[i][j];
                    //currentBiome = data.GetTile(i, j).Biome;

                    // slope
                    // need to map x/z to terrain space
                    float y_01 = (float)i / (float)size;
                    float x_01 = (float)j / (float)size;

                    // Calculate the steepness of the terrain
                    float steepness = data.Data.GetSteepness(y_01, x_01);

                    if (steepness < _maxVegetationSlope)
                    {
                        if (value > 0.85f)
                        {
                            detailID    = (int)eDetailType.Tree;
                            changeScale = true;

                            if (value > 0.95f)
                            {
                                // TODO set scale modifier here or something
                                //detail = _detailObjects[(int)DetailType.Tree_Pine_0];
                            }
                            else if (value > 0.9f)
                            {
                                //detail = _detailObjects[(int)DetailType.Tree_Pine_1];
                            }
                            else
                            {
                                //detail = _detailObjects[(int)DetailType.Tree_Pine_2];
                            }
                        }
                        else if (value > 0.75f)
                        {
                            detailID = (int)eDetailType.Flower;
                            //detail = _detailObjects[(int)DetailType.Flower_Bud];
                        }
                        else if (value > 0.68f)
                        {
                            detailID = (int)eDetailType.Grass;
                            //detail = _detailObjects[(int)DetailType.Grass];
                        }
                        else if (value > 0.65f)
                        {
                            detailID = (int)eDetailType.Fern;
                            //detail = _detailObjects[(int)DetailType.Fern];
                        }
                        else if (value < 0.025f)
                        {
                            detailID = (int)eDetailType.Rock;
                            //detail = _detailObjects[(int)DetailType.Rock_Medium];
                        }

                        //if (detail != null)
                        if (detailID > -1)
                        {
                            //GameObject detail = null;
                            GameObject detail    = GetDetailsForBiome(currentBiome)[detailID];
                            GameObject detailObj = (GameObject)Instantiate(detail, Vector3.zero, Quaternion.identity);

                            float angle = prng.Next(359) + 1;
                            detailObj.transform.Rotate(Vector3.up, angle);

                            if (changeScale)
                            {
                                float scaleFactor = (float)prng.NextDouble() + 0.25f;
                                detailObj.transform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);
                            }

                            detailObj.transform.SetParent(detailContainer.transform);

                            // need to place a tile here
                            PlaceTile(i, j, ref data, _currentTerrain.transform.position);

                            data.AddObjectToTile(detailObj, i, j);
                        }
                    }
                }
            }
        }
    }