Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [CanEditMultipleObjects, CustomEditor(typeof(BaseMonoBehaviour), true)]
- public class BaseMonoBehaviourEditor : Editor
- {
- public override void OnInspectorGUI()
- {
- serializedObject.Update();
- SerializedProperty iterator = serializedObject.GetIterator();
- bool enterChildren = true;
- while (iterator.NextVisible(enterChildren))
- {
- enterChildren = false;
- OnPropertyGUI(property);
- }
- serializedObject.ApplyModifiedProperties();
- }
- public void OnPropertyGUI(SerializedProperty property)
- {
- OnPropertyGUI(property, new GUIContent(property.displayName, property.tooltip));
- }
- public void OnPropertyGUI(SerializedProperty property, GUIContent label)
- {
- BaseMonoBehaviour t = target as BaseMonoBehaviour;
- EditorGUI.BeginChangeCheck();
- DrawProperty(property, label);
- if (EditorGUI.EndChangeCheck())
- {
- property.serializedObject.ApplyModifiedProperties();
- property.serializedObject.Update();
- t.OnValidateProperty(property.name);
- }
- }
- public void OnPropertyGUI(Rect position, SerializedProperty property, GUIContent label)
- {
- BaseMonoBehaviour t = target as BaseMonoBehaviour;
- EditorGUI.BeginChangeCheck();
- DrawProperty(position, property, label);
- if (EditorGUI.EndChangeCheck())
- {
- property.serializedObject.ApplyModifiedProperties();
- property.serializedObject.Update();
- t.OnValidateProperty(property.name);
- }
- }
- public virtual Rect GetPropertyControlRect(SerializedProperty property, GUIContent label, params GUILayoutOption[] options)
- {
- return EditorGUILayout.GetControlRect(!string.IsNullOrEmpty(label.text), EditorGUI.GetPropertyHeight(property, label, true), options);
- }
- protected virtual void DrawProperty(SerializedProperty property, GUIContent label, params GUILayoutOption[] options)
- {
- Rect position = GetPropertyControlRect(property, label, options);
- DrawProperty(position, property, label);
- }
- protected virtual void DrawProperty(Rect position, SerializedProperty property, GUIContent label)
- {
- EditorGUI.PropertyField(position, property, label);
- }
- }
Add Comment
Please, Sign In to add comment