Created
November 2, 2013 23:29
-
-
Save bcatcho/7284639 to your computer and use it in GitHub Desktop.
The beginnings of a helper class to render procedural meshes in edit mode. (unity3d)
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
public class EditorRenderer | |
{ | |
public Mesh Mesh {get;set;} | |
public Material Material {get;set;} | |
private Transform _transform; | |
public Transform Transform | |
{ | |
get { return _transform; } | |
set | |
{ | |
_transform = value; | |
_matrix = _transform.localToWorldMatrix; | |
} | |
} | |
public int Layer {get;set;} | |
private Matrix4x4 _matrix; | |
public static EditorRenderer CreateRenderer(Mesh inMesh, Material inMaterial, Transform inTransform, int inLayer) | |
{ | |
if ( Application.isEditor && Application.isPlaying) | |
{ | |
return new EditorRenderer() | |
{ | |
Mesh = inMesh, | |
Material = inMaterial, | |
Transform = inTransform, | |
Layer = inLayer, | |
}; | |
} | |
return null; | |
} | |
public void Render() | |
{ | |
if (Transform.hasChanged) | |
{ | |
_matrix = Transform.localToWorldMatrix; | |
Transform.hasChanged = false; | |
} | |
Graphics.DrawMesh(Mesh, _matrix, Material, Layer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment