示例#1
0
    public float getNoise(float x, float y, ref perlinNoise p_noiseGenerator)
    {
        float noiseValue = p_noiseGenerator.getNoise(x, y);

        if (noiseValue <= m_noiseSettings.cutoffMin || noiseValue >= m_noiseSettings.cutoffMax)
        {
            return(0);
        }
        return(noiseValue);
    }
示例#2
0
    public void LoadGrid(ref WorldChunk p_worldChunk, GameObject p_parent)
    {
        var grid = p_worldChunk.m_mapGrid;

        for (int i = 0; i < grid.getNumHorizontal(); i++)
        {
            for (int j = 0; j < grid.getNumVertical(); j++)
            {
                var     v           = grid.m_grid[i, j];
                float   x           = v.x + m_origin.x;
                float   y           = v.z + m_origin.z;
                float[] noiseValues = getNoise(x, y, m_origin);
                float   height      = m_elevationNoise.getNoise(x, y);
                Vector3 newTilePos  = new Vector3(v.x, (int)(height * 50), v.z);
                newTilePos.x += m_origin.x;
                newTilePos.z += m_origin.z;

                GameObject createdObject;
                GameObject toCreate = standartTile;
                if (noiseValues.Sum() > 0.001f)
                {
                    int prefabIDX = noiseValues.ToList().IndexOf(Mathf.Max(noiseValues));
                    toCreate = getPrefab(prefabIDX);
                    if (prefabIDX == 2)
                    {
                        float forestNoise = m_forestNoiseManager.getNoise(x, y, ref m_forestNoise);
                        if (forestNoise > 0.0f)
                        {
                            toCreate = m_forestNoiseManager.getPrefab();
                        }
                        else
                        {
                            float stoneNoise = m_stoneNoiseManager.getNoise(x, y, ref m_stoneNoise);
                            if (stoneNoise > 0.0f)
                            {
                                toCreate = m_stoneNoiseManager.getPrefab();
                            }
                        }
                    }
                    createdObject = Instantiate(toCreate, newTilePos, Quaternion.identity);
                }
                else
                {
                    newTilePos.y  = 0.3f * 50.0f;
                    createdObject = Instantiate(toCreate, newTilePos, Quaternion.identity);
                }
                p_worldChunk.m_tileMap[i, j] = createdObject;
                createdObject.GetComponent <Tile>().setCoordText(getChunkID(newTilePos), getTileFromChunk(newTilePos, getChunkID(newTilePos)));
                p_worldChunk.m_tileMap[i, j].transform.parent = p_parent.transform;
            }
        }
        p_parent.transform.parent = m_map.transform;
        invoked = false;
    }