当前位置: 首页>>代码示例>>C#>>正文


C# Texture2D.FloodFillArea方法代码示例

本文整理汇总了C#中UnityEngine.Texture2D.FloodFillArea方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.FloodFillArea方法的具体用法?C# Texture2D.FloodFillArea怎么用?C# Texture2D.FloodFillArea使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Texture2D的用法示例。


在下文中一共展示了Texture2D.FloodFillArea方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateMesh

    void GenerateMesh()
    {
        // You can change that line to provide another MeshFilter

        Mesh mesh = new Mesh() ;
        mesh.Clear();

        float length = xSize;
        float width = ySize;
        int resX = PointsNum1D; // 2 minimum
        int resZ = PointsNum1D;

        int halfResZ = resZ / 2;

        shapeTexture = new Texture2D(PointsNum1D, PointsNum1D);
        for (int z = 0; z < resZ; z++)
        {
            float heightVal = Mathf.PerlinNoise(z * islandShapeStrength, 0);
            for (int i=0;i<resX;i++)
            {
                Color thisColor = i < heightVal * resX ? Color.red : Color.red;
                //Color thisColor =
                shapeTexture.SetPixel(i, z, thisColor);

            }
        }
        seed = System.DateTime.Now.Minute + System.DateTime.Now.Millisecond + System.DateTime.Now.Second;
        //Random.seed = seed;

        float radius = 50.0f;
        float startVal = -0.5f * Mathf.PI;
        int previousY = halfResZ + Mathf.FloorToInt(radius * Mathf.Sin(startVal));
        float perlinStart = 0.0f;// 10.0f;// Random.Range(0.0f, 1000.0f);
        for (float theta = startVal; theta < startVal+Mathf.PI*2.0f; theta += 0.0001f)
        {
            float heightVal = Mathf.PerlinNoise((theta - startVal) * islandShapeStrength, 0.0f) * 50.0f;
            float adjustedRadius = radius + heightVal;
            int x = halfResZ + Mathf.FloorToInt(adjustedRadius * Mathf.Cos(theta));
            int y = halfResZ + Mathf.FloorToInt(adjustedRadius * Mathf.Sin(theta));
            shapeTexture.SetPixel(x, y, Color.blue);
            shapeTexture.SetPixel(x+1, y+1, Color.blue);
        }
        //bool floodFill = false;
        if (floodFill)
        {
            shapeTexture.FloodFillArea(halfResZ, halfResZ, Color.blue);
        }
           shapeTexture.Apply();
        GetComponent<MeshRenderer>().sharedMaterial.SetTexture("Albedo",shapeTexture);
        Random randVals = new Random(); ;
        #region Vertices
        Vector3[] vertices = new Vector3[resX * resZ];
        for (int z = 0; z < resZ; z++)
        {
            // [ -length / 2, length / 2 ]
            float zPos = ((float)z / (resZ - 1) - .5f) * length;
            for (int x = 0; x < resX; x++)
            {

                // [ -width / 2, width / 2 ]
                float xPos = ((float)x / (resX - 1) - .5f) * width;
                float heightVal = Mathf.PerlinNoise(x * perlinStrength, z * perlinStrength)*maxHeight;
                Vector3 newPos = new Vector3(xPos, heightVal, zPos);
                if (shapeTexture.GetPixel(x,z).b == 0.0f)
                {
                    float closenessToEdgeX = Mathf.Abs(((float)x - (float)halfResZ) / (float)halfResZ);
                    float closenessToEdgeZ = Mathf.Abs(((float)z - (float)halfResZ) / (float)halfResZ);
                    float ratioVal = 1.0f - Mathf.Pow((closenessToEdgeX + closenessToEdgeZ), 3.0f);
                    newPos = tuckPoint;// new Vector3(0.0f, heightVal * ratioVal, 0.0f);
                }
                vertices[x + z * resX] = newPos;

            }
        }
        #endregion

        #region Normales
        Vector3[] normales = new Vector3[vertices.Length];
        for (int n = 0; n < normales.Length; n++)
            normales[n] = Vector3.up;
        #endregion

        #region UVs
        Vector2[] uvs = new Vector2[vertices.Length];
        for (int v = 0; v < resZ; v++)
        {
            for (int u = 0; u < resX; u++)
            {
                uvs[u + v * resX] = new Vector2((float)u / (resX - 1), (float)v / (resZ - 1));
            }
        }
        #endregion

        #region Triangles
        int nbFaces = (resX - 1) * (resZ - 1);
        int[] triangles = new int[nbFaces * 6];
        int t = 0;
        for (int face = 0; face < nbFaces; face++)
        {
            // Retrieve lower left corner from face ind
//.........这里部分代码省略.........
开发者ID:LaceMattley,项目名称:FloatyIsland,代码行数:101,代码来源:ProceduralMesh2.cs


注:本文中的UnityEngine.Texture2D.FloodFillArea方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。