diff options
| author | Tom Harley | 2018-09-03 23:34:21 +0100 |
|---|---|---|
| committer | Tom Harley | 2018-09-03 23:36:01 +0100 |
| commit | 5440734d820606b29a795c46172ade5d7eba8efb (patch) | |
| tree | 85867f40afb02cfa2a5028b515ed0a195866b7e9 /Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs | |
| download | powerless-5440734d820606b29a795c46172ade5d7eba8efb.tar.gz powerless-5440734d820606b29a795c46172ade5d7eba8efb.zip | |
Initial commit
Diffstat (limited to 'Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs')
| -rw-r--r-- | Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs b/Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs new file mode 100644 index 0000000..d1a5165 --- /dev/null +++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs @@ -0,0 +1,61 @@ +using UnityEngine; +using UnityEditor; +using System.Reflection; + +namespace Cinemachine.Editor +{ + [CustomPropertyDrawer(typeof(LensSettingsPropertyAttribute))] + public sealed class LensSettingsPropertyDrawer : PropertyDrawer + { + const int vSpace = 2; + bool mExpanded = true; + LensSettings def = new LensSettings(); // to access name strings + + public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) + { + float height = EditorGUIUtility.singleLineHeight; + rect.height = height; + mExpanded = EditorGUI.Foldout(rect, mExpanded, label); + if (mExpanded) + { + bool ortho = false; + PropertyInfo pi = typeof(LensSettings).GetProperty( + "Orthographic", BindingFlags.NonPublic | BindingFlags.Instance); + if (pi != null) + ortho = bool.Equals(true, pi.GetValue(GetPropertyValue(property), null)); + + ++EditorGUI.indentLevel; + rect.y += height + vSpace; + if (ortho) + EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => def.OrthographicSize)); + else + EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => def.FieldOfView)); + rect.y += height + vSpace; + EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => def.NearClipPlane)); + rect.y += height + vSpace; + EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => def.FarClipPlane)); + rect.y += height + vSpace; + EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => def.Dutch)); + --EditorGUI.indentLevel; + } + } + + object GetPropertyValue(SerializedProperty property) + { + var targetObject = property.serializedObject.targetObject; + var targetObjectClassType = targetObject.GetType(); + var field = targetObjectClassType.GetField(property.propertyPath); + if (field != null) + return field.GetValue(targetObject); + return null; + } + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + float height = EditorGUIUtility.singleLineHeight + vSpace; + if (mExpanded) + height *= 5; + return height; + } + } +} |
