using System; using UnityEngine; using UnityEngine.Rendering; namespace UnityEditor.Rendering { /// /// Attribute specifying wich type of Debug Item should this drawer be used with. /// public class DebugUIDrawerAttribute : Attribute { internal readonly Type type; /// /// Constructor for DebugUIDraw Attribute /// /// Type of Debug Item this draw should be used with. public DebugUIDrawerAttribute(Type type) { this.type = type; } } /// /// Debug Item Drawer /// public class DebugUIDrawer { /// /// Cast into the proper type. /// /// Type of the drawer /// Object to be cast /// Returns o cast to type T protected T Cast(object o) where T : class { var casted = o as T; string typeName = o == null ? "null" : o.GetType().ToString(); if (casted == null) throw new InvalidOperationException("Can't cast " + typeName + " to " + typeof(T)); return casted; } /// /// Implement this to execute processing before UI rendering. /// /// Widget that is going to be rendered. /// Debug State associated with the Debug Item. public virtual void Begin(DebugUI.Widget widget, DebugState state) {} /// /// Implement this to execute UI rendering. /// /// Widget that is going to be rendered. /// Debug State associated with the Debug Item. /// Returns the state of the widget. public virtual bool OnGUI(DebugUI.Widget widget, DebugState state) { return true; } /// /// Implement this to execute processing after UI rendering. /// /// Widget that is going to be rendered. /// Debug State associated with the Debug Item. public virtual void End(DebugUI.Widget widget, DebugState state) {} /// /// Applies a value to the widget and the Debug State of the Debug Item. /// /// Debug Item widget. /// Debug State associated with the Debug Item /// Input value. protected void Apply(DebugUI.IValueField widget, DebugState state, object value) { Undo.RegisterCompleteObjectUndo(state, "Debug Property Change"); state.SetValue(value, widget); widget.SetValue(value); EditorUtility.SetDirty(state); DebugState.m_CurrentDirtyState = state; UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); } /// /// Prepares the rendering Rect of the Drawer/ /// /// Height of the rect. /// Appropriate Rect for drawing. protected Rect PrepareControlRect(float height = -1) { if (height < 0) height = EditorGUIUtility.singleLineHeight; var rect = GUILayoutUtility.GetRect(1f, 1f, height, height); rect.width -= 2f; rect.xMin += 2f; EditorGUIUtility.labelWidth = rect.width / 2f; return rect; } } }