Last active
August 29, 2015 14:01
-
-
Save seiji/9547760ccd836486d7cb to your computer and use it in GitHub Desktop.
Create simple mesh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Create() | |
{ | |
float x = 512.0f; | |
float y = 341.0f; | |
Mesh mesh = (Mesh)AssetDatabase.LoadAssetAtPath("Assets/UI/SimpleMesh.asset", typeof(Mesh)); | |
if( mesh == null) | |
{ | |
mesh = new Mesh(); | |
mesh.name = "SimpleMesh"; | |
float vx = x * 0.5f, vy = y * 0.5f; | |
mesh.vertices = new Vector3[]{ | |
Vector3.left * vx + Vector3.up * vy, | |
Vector3.right * vx + Vector3.up * vy, | |
Vector3.right * vx + Vector3.down * vy, | |
Vector3.left * vx + Vector3.down * vy | |
}; | |
mesh.triangles = new int[]{ | |
0, 1, 2, | |
2, 3, 0 | |
}; | |
mesh.uv = new Vector2[]{ | |
new Vector2(1.0f, 1.0f), | |
new Vector2(0.0f, 1.0f), | |
new Vector2(0.0f, 0.0f), | |
new Vector2(1.0f, 0.0f) | |
}; | |
mesh.RecalculateNormals (); | |
mesh.RecalculateBounds (); | |
mesh.Optimize (); | |
AssetDatabase.CreateAsset(mesh, "Assets/UI/SimpleMesh.asset"); | |
AssetDatabase.SaveAssets(); | |
} | |
mesh.RecalculateBounds(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment