Skip to content

Instantly share code, notes, and snippets.

@seiji
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seiji/9547760ccd836486d7cb to your computer and use it in GitHub Desktop.
Save seiji/9547760ccd836486d7cb to your computer and use it in GitHub Desktop.
Create simple mesh
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