Last active
March 5, 2019 10:20
-
-
Save keenanwoodall/b189359e8498c244496212122ca1e8e0 to your computer and use it in GitHub Desktop.
A helper class for drawing a transform's rotation field in the same way as the Transform editor in Unity.
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
using System; | |
using System.Reflection; | |
using UnityEngine; | |
using UnityEditor; | |
/// <summary> | |
/// Abstracts the reflection required to use the internal TransformRotationGUI class. | |
/// </summary> | |
public class TransformRotationGUI | |
{ | |
private object transformRotationGUI; | |
private MethodInfo onEnable; | |
private MethodInfo rotationField; | |
public TransformRotationGUI () | |
{ | |
if (transformRotationGUI == null) | |
{ | |
var type = Type.GetType ("UnityEditor.TransformRotationGUI,UnityEditor"); | |
onEnable = type.GetMethod ("OnEnable"); | |
rotationField = type.GetMethod ("RotationField", new Type[] { }); | |
transformRotationGUI = Activator.CreateInstance (type); | |
} | |
} | |
/// <summary> | |
/// Initializes the GUI. | |
/// </summary> | |
public void Initialize (SerializedProperty property, GUIContent content) | |
{ | |
onEnable.Invoke (transformRotationGUI, new object[] { property, content }); | |
} | |
/// <summary> | |
/// Draws the rotation GUI. | |
/// </summary> | |
public void Draw () | |
{ | |
rotationField.Invoke (transformRotationGUI, null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment