Пример #1
0
    /**
     * Public Methods
     */
    public void init(int mapSize, float baseSeedProbability, float stepSpeed, int stabilizationPeriod)
    {
        m_worldMapPopulationMesh = gameObject.AddComponent <WorldMapPopulationMesh>();
        m_worldMapGraph          = gameObject.AddComponent <WorldMapGraph>();
        m_worldMapPopulationMesh.init(mapSize);
        m_worldMapGraph.init(mapSize, baseSeedProbability, stabilizationPeriod);
        InvokeRepeating("step", stepSpeed, stepSpeed);

        GameObject ocean = new GameObject();

        ocean.name             = "Ocean";
        ocean.transform.parent = transform.parent;
        ocean.AddComponent <MeshRenderer>();
        ocean.AddComponent <MeshFilter>();
        m_oceanMesh = ocean.AddComponent <OceanMesh>();
        m_oceanMesh.init(mapSize);
    }
Пример #2
0
    private void CreateOceanMesh()
    {
        oceanMeshs                = new GameObject[4];
        oceanMesh                 = new OceanMesh();
        oceanMesh.filetr          = gameObject.AddComponent <MeshFilter>();
        oceanMesh.render          = gameObject.AddComponent <MeshRenderer>();
        oceanMesh.mesh            = new Mesh();
        oceanMesh.filetr.mesh     = oceanMesh.mesh;
        oceanMesh.render.material = mat_Ocean;

        oceanMesh.vertIndexs = new int[(oceanMeshSize - 1) * (oceanMeshSize - 1) * 6];
        oceanMesh.vertexs    = new Vector3[oceanMeshSize * oceanMeshSize];
        oceanMesh.uvs        = new Vector2[oceanMeshSize * oceanMeshSize];

        int inx = 0;

        for (int i = 0; i < oceanMeshSize; i++)
        {
            for (int j = 0; j < oceanMeshSize; j++)
            {
                int index = i * oceanMeshSize + j;
                oceanMesh.vertexs[index] = new Vector3((j - oceanMeshSize / 2.0f) * oceanLenght / oceanMeshSize, 0, (i - oceanMeshSize / 2.0f) * oceanLenght / oceanMeshSize);
                oceanMesh.uvs[index]     = new Vector2(j / (oceanMeshSize - 1.0f), i / (oceanMeshSize - 1.0f));

                if (i != oceanMeshSize - 1 && j != oceanMeshSize - 1)
                {
                    oceanMesh.vertIndexs[inx++] = index;
                    oceanMesh.vertIndexs[inx++] = index + oceanMeshSize;
                    oceanMesh.vertIndexs[inx++] = index + oceanMeshSize + 1;

                    oceanMesh.vertIndexs[inx++] = index;
                    oceanMesh.vertIndexs[inx++] = index + oceanMeshSize + 1;
                    oceanMesh.vertIndexs[inx++] = index + 1;
                }
            }
        }
        oceanMesh.mesh.vertices = oceanMesh.vertexs;
        oceanMesh.mesh.SetIndices(oceanMesh.vertIndexs, MeshTopology.Triangles, 0);
        oceanMesh.mesh.uv = oceanMesh.uvs;

        mat_Ocean.SetTexture("_Displace", m_displace);
        mat_Ocean.SetTexture("_NormalBubbles", m_normalBubbles);
    }