diff options
Diffstat (limited to 'Assets/uGUI-2017.1/Editor/UI/HorizontalOrVerticalLayoutGroupEditor.cs')
-rw-r--r-- | Assets/uGUI-2017.1/Editor/UI/HorizontalOrVerticalLayoutGroupEditor.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Assets/uGUI-2017.1/Editor/UI/HorizontalOrVerticalLayoutGroupEditor.cs b/Assets/uGUI-2017.1/Editor/UI/HorizontalOrVerticalLayoutGroupEditor.cs new file mode 100644 index 0000000..01b17b8 --- /dev/null +++ b/Assets/uGUI-2017.1/Editor/UI/HorizontalOrVerticalLayoutGroupEditor.cs @@ -0,0 +1,75 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEditorInternal; +using UnityEditor.AnimatedValues; + +namespace UnityEditor.UI +{ + [CustomEditor(typeof(HorizontalOrVerticalLayoutGroup), true)] + [CanEditMultipleObjects] + public class HorizontalOrVerticalLayoutGroupEditor : Editor + { + SerializedProperty m_Padding; + SerializedProperty m_Spacing; + SerializedProperty m_ChildAlignment; + SerializedProperty m_ChildControlWidth; + SerializedProperty m_ChildControlHeight; + SerializedProperty m_ChildForceExpandWidth; + SerializedProperty m_ChildForceExpandHeight; + + protected virtual void OnEnable() + { + m_Padding = serializedObject.FindProperty("m_Padding"); + m_Spacing = serializedObject.FindProperty("m_Spacing"); + m_ChildAlignment = serializedObject.FindProperty("m_ChildAlignment"); + m_ChildControlWidth = serializedObject.FindProperty("m_ChildControlWidth"); + m_ChildControlHeight = serializedObject.FindProperty("m_ChildControlHeight"); + m_ChildForceExpandWidth = serializedObject.FindProperty("m_ChildForceExpandWidth"); + m_ChildForceExpandHeight = serializedObject.FindProperty("m_ChildForceExpandHeight"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + EditorGUILayout.PropertyField(m_Padding, true); + EditorGUILayout.PropertyField(m_Spacing, true); + EditorGUILayout.PropertyField(m_ChildAlignment, true); + + Rect rect = EditorGUILayout.GetControlRect(); + rect = EditorGUI.PrefixLabel(rect, -1, new GUIContent("Child Controls Size")); + rect.width = Mathf.Max(50, (rect.width - 4) / 3); + EditorGUIUtility.labelWidth = 50; + ToggleLeft(rect, m_ChildControlWidth, new GUIContent("Width")); + rect.x += rect.width + 2; + ToggleLeft(rect, m_ChildControlHeight, new GUIContent("Height")); + EditorGUIUtility.labelWidth = 0; + + rect = EditorGUILayout.GetControlRect(); + rect = EditorGUI.PrefixLabel(rect, -1, new GUIContent("Child Force Expand")); + rect.width = Mathf.Max(50, (rect.width - 4) / 3); + EditorGUIUtility.labelWidth = 50; + ToggleLeft(rect, m_ChildForceExpandWidth, new GUIContent("Width")); + rect.x += rect.width + 2; + ToggleLeft(rect, m_ChildForceExpandHeight, new GUIContent("Height")); + EditorGUIUtility.labelWidth = 0; + + serializedObject.ApplyModifiedProperties(); + } + + void ToggleLeft(Rect position, SerializedProperty property, GUIContent label) + { + bool toggle = property.boolValue; + EditorGUI.showMixedValue = property.hasMultipleDifferentValues; + EditorGUI.BeginChangeCheck(); + int oldIndent = EditorGUI.indentLevel; + EditorGUI.indentLevel = 0; + toggle = EditorGUI.ToggleLeft(position, label, toggle); + EditorGUI.indentLevel = oldIndent; + if (EditorGUI.EndChangeCheck()) + { + property.boolValue = property.hasMultipleDifferentValues ? true : !property.boolValue; + } + EditorGUI.showMixedValue = false; + } + } +} |