Guest User

Untitled

a guest
Feb 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. [CanEditMultipleObjects, CustomEditor(typeof(BaseMonoBehaviour), true)]
  2. public class BaseMonoBehaviourEditor : Editor
  3. {
  4. public override void OnInspectorGUI()
  5. {
  6. serializedObject.Update();
  7.  
  8. SerializedProperty iterator = serializedObject.GetIterator();
  9. bool enterChildren = true;
  10. while (iterator.NextVisible(enterChildren))
  11. {
  12. enterChildren = false;
  13.  
  14. OnPropertyGUI(property);
  15. }
  16.  
  17. serializedObject.ApplyModifiedProperties();
  18. }
  19.  
  20. public void OnPropertyGUI(SerializedProperty property)
  21. {
  22. OnPropertyGUI(property, new GUIContent(property.displayName, property.tooltip));
  23. }
  24.  
  25. public void OnPropertyGUI(SerializedProperty property, GUIContent label)
  26. {
  27. BaseMonoBehaviour t = target as BaseMonoBehaviour;
  28.  
  29. EditorGUI.BeginChangeCheck();
  30.  
  31. DrawProperty(property, label);
  32.  
  33. if (EditorGUI.EndChangeCheck())
  34. {
  35. property.serializedObject.ApplyModifiedProperties();
  36. property.serializedObject.Update();
  37. t.OnValidateProperty(property.name);
  38. }
  39. }
  40.  
  41. public void OnPropertyGUI(Rect position, SerializedProperty property, GUIContent label)
  42. {
  43. BaseMonoBehaviour t = target as BaseMonoBehaviour;
  44.  
  45. EditorGUI.BeginChangeCheck();
  46.  
  47. DrawProperty(position, property, label);
  48.  
  49. if (EditorGUI.EndChangeCheck())
  50. {
  51. property.serializedObject.ApplyModifiedProperties();
  52. property.serializedObject.Update();
  53. t.OnValidateProperty(property.name);
  54. }
  55. }
  56.  
  57. public virtual Rect GetPropertyControlRect(SerializedProperty property, GUIContent label, params GUILayoutOption[] options)
  58. {
  59. return EditorGUILayout.GetControlRect(!string.IsNullOrEmpty(label.text), EditorGUI.GetPropertyHeight(property, label, true), options);
  60. }
  61.  
  62. protected virtual void DrawProperty(SerializedProperty property, GUIContent label, params GUILayoutOption[] options)
  63. {
  64. Rect position = GetPropertyControlRect(property, label, options);
  65. DrawProperty(position, property, label);
  66. }
  67.  
  68. protected virtual void DrawProperty(Rect position, SerializedProperty property, GUIContent label)
  69. {
  70. EditorGUI.PropertyField(position, property, label);
  71. }
  72. }
Add Comment
Please, Sign In to add comment