コード例 #1
0
ファイル: Drawing.cs プロジェクト: mengtest/CYMCommon
        public static GameObject CreateSurface(string name, List <Vector3> surfPoints, int[] indices, Material material, Rect rect, Vector2 textureScale, Vector2 textureOffset, float textureRotation, bool rotateInLocalSpace, DisposalManager disposalManager)
        {
            GameObject hexa = new GameObject(name, typeof(MeshRenderer), typeof(MeshFilter));

            disposalManager.MarkForDisposal(hexa);
            hexa.hideFlags |= HideFlags.HideInHierarchy;

            Mesh mesh = new Mesh();

            disposalManager.MarkForDisposal(mesh);
            mesh.SetVertices(surfPoints);
            mesh.SetTriangles(indices, 0, true);
            // uv mapping
            if (material != null && material.HasProperty("_MainTex") && material.mainTexture != null)
            {
                int       len = surfPoints.Count;
                Vector2[] uv  = new Vector2[len];
                for (int k = 0; k < len; k++)
                {
                    Vector2 coor = surfPoints [k];
                    Vector2 normCoor;
                    if (rotateInLocalSpace)
                    {
                        normCoor = new Vector2((coor.x - rect.xMin) / rect.width, (coor.y - rect.yMin) / rect.height);
                        if (textureRotation != 0)
                        {
                            normCoor = RotatePoint(normCoor, Misc.Vector2half, textureRotation);
                        }
                        normCoor.x = 0.5f + (normCoor.x - 0.5f) / textureScale.x;
                        normCoor.y = 0.5f + (normCoor.y - 0.5f) / textureScale.y;
                        normCoor  -= textureOffset;
                    }
                    else
                    {
                        coor.x /= textureScale.x;
                        coor.y /= textureScale.y;
                        if (textureRotation != 0)
                        {
                            coor = RotatePoint(coor, Vector2.zero, textureRotation);
                        }
                        coor    -= textureOffset;
                        normCoor = new Vector2((coor.x - rect.xMin) / rect.width, (coor.y - rect.yMin) / rect.height);
                    }
                    uv [k] = normCoor;
                }
                mesh.uv = uv;
            }
            mesh.RecalculateNormals();

            MeshFilter meshFilter = hexa.GetComponent <MeshFilter> ();

            meshFilter.mesh = mesh;

            hexa.GetComponent <Renderer> ().sharedMaterial = material;
            return(hexa);
        }
コード例 #2
0
ファイル: Drawing.cs プロジェクト: mengtest/CYMCommon
 public static GameObject CreateSurface(string name, List <Vector3> surfPoints, int[] indices, Material material, DisposalManager disposalManager)
 {
     return(CreateSurface(name, surfPoints, indices, material, dummyRect, Misc.Vector2one, Misc.Vector2zero, 0, false, disposalManager));
 }