diff options
author | chai <chaifix@163.com> | 2020-10-08 09:50:33 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-10-08 09:50:33 +0800 |
commit | 00dae1bd426d892dff73a50f1c505afd1ac00a90 (patch) | |
tree | 5d75f8495406f5b8dd01595e3dd9216887996a34 /Assets/uGUI-2017.1/Editor/UI/PropertyDrawers/NavigationDrawer.cs |
+init
Diffstat (limited to 'Assets/uGUI-2017.1/Editor/UI/PropertyDrawers/NavigationDrawer.cs')
-rw-r--r-- | Assets/uGUI-2017.1/Editor/UI/PropertyDrawers/NavigationDrawer.cs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/Assets/uGUI-2017.1/Editor/UI/PropertyDrawers/NavigationDrawer.cs b/Assets/uGUI-2017.1/Editor/UI/PropertyDrawers/NavigationDrawer.cs new file mode 100644 index 0000000..2cfc4d3 --- /dev/null +++ b/Assets/uGUI-2017.1/Editor/UI/PropertyDrawers/NavigationDrawer.cs @@ -0,0 +1,83 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace UnityEditor.UI +{ + [CustomPropertyDrawer(typeof(Navigation), true)] + public class NavigationDrawer : PropertyDrawer + { + private class Styles + { + readonly public GUIContent navigationContent; + + public Styles() + { + navigationContent = new GUIContent("Navigation"); + } + } + + private static Styles s_Styles = null; + + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + if (s_Styles == null) + s_Styles = new Styles(); + + Rect drawRect = pos; + drawRect.height = EditorGUIUtility.singleLineHeight; + + SerializedProperty navigation = prop.FindPropertyRelative("m_Mode"); + Navigation.Mode navMode = GetNavigationMode(navigation); + + EditorGUI.PropertyField(drawRect, navigation, s_Styles.navigationContent); + + ++EditorGUI.indentLevel; + + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + + switch (navMode) + { + case Navigation.Mode.Explicit: + { + SerializedProperty selectOnUp = prop.FindPropertyRelative("m_SelectOnUp"); + SerializedProperty selectOnDown = prop.FindPropertyRelative("m_SelectOnDown"); + SerializedProperty selectOnLeft = prop.FindPropertyRelative("m_SelectOnLeft"); + SerializedProperty selectOnRight = prop.FindPropertyRelative("m_SelectOnRight"); + + EditorGUI.PropertyField(drawRect, selectOnUp); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, selectOnDown); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, selectOnLeft); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, selectOnRight); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + } + break; + } + + --EditorGUI.indentLevel; + } + + static Navigation.Mode GetNavigationMode(SerializedProperty navigation) + { + return (Navigation.Mode)navigation.enumValueIndex; + } + + public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) + { + SerializedProperty navigation = prop.FindPropertyRelative("m_Mode"); + if (navigation == null) + return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + + Navigation.Mode navMode = GetNavigationMode(navigation); + + switch (navMode) + { + case Navigation.Mode.None: return EditorGUIUtility.singleLineHeight; + case Navigation.Mode.Explicit: return 5 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing; + default: return EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; + } + } + } +} |