Skip to content

Instantly share code, notes, and snippets.

@keenanwoodall
Last active March 5, 2019 10:20
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 keenanwoodall/b189359e8498c244496212122ca1e8e0 to your computer and use it in GitHub Desktop.
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.
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