SlideHorizontalOrVerticalLayoutGroupEditor.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. [CustomEditor(typeof(SlideHorizontalOrVerticalLayoutGroup), true)]
  6. [CanEditMultipleObjects]
  7. public class SlideHorizontalOrVerticalLayoutGroupEditor : Editor
  8. {
  9. SerializedProperty m_Padding;
  10. SerializedProperty m_Spacing;
  11. SerializedProperty m_ChildAlignment;
  12. SerializedProperty m_ChildControlWidth;
  13. SerializedProperty m_ChildControlHeight;
  14. SerializedProperty m_ChildForceExpandWidth;
  15. SerializedProperty m_ChildForceExpandHeight;
  16. SerializedProperty m_SnapEnable;
  17. SerializedProperty m_InverseChildPosEnable;
  18. SerializedProperty m_InvisibleVaild;
  19. protected virtual void OnEnable()
  20. {
  21. m_Padding = serializedObject.FindProperty("m_Padding");
  22. m_Spacing = serializedObject.FindProperty("m_Spacing");
  23. m_ChildAlignment = serializedObject.FindProperty("m_ChildAlignment");
  24. m_ChildControlWidth = serializedObject.FindProperty("m_ChildControlWidth");
  25. m_ChildControlHeight = serializedObject.FindProperty("m_ChildControlHeight");
  26. m_ChildForceExpandWidth = serializedObject.FindProperty("m_ChildForceExpandWidth");
  27. m_ChildForceExpandHeight = serializedObject.FindProperty("m_ChildForceExpandHeight");
  28. m_SnapEnable = serializedObject.FindProperty("m_SnapEnable");
  29. m_InverseChildPosEnable = serializedObject.FindProperty("m_InverseChildPosEnable");
  30. m_InvisibleVaild = serializedObject.FindProperty("m_InvisibleVaild");
  31. }
  32. public override void OnInspectorGUI()
  33. {
  34. serializedObject.Update();
  35. EditorGUILayout.PropertyField(m_Padding, true);
  36. EditorGUILayout.PropertyField(m_Spacing, true);
  37. EditorGUILayout.PropertyField(m_ChildAlignment, true);
  38. Rect rect = EditorGUILayout.GetControlRect();
  39. rect = EditorGUI.PrefixLabel(rect, -1, EditorGUIUtility.TrTextContent("Child Controls Size"));
  40. rect.width = Mathf.Max(50, (rect.width - 4) / 3);
  41. EditorGUIUtility.labelWidth = 50;
  42. ToggleLeft(rect, m_ChildControlWidth, EditorGUIUtility.TrTextContent("Width"));
  43. rect.x += rect.width + 2;
  44. ToggleLeft(rect, m_ChildControlHeight, EditorGUIUtility.TrTextContent("Height"));
  45. EditorGUIUtility.labelWidth = 0;
  46. rect = EditorGUILayout.GetControlRect();
  47. rect = EditorGUI.PrefixLabel(rect, -1, EditorGUIUtility.TrTextContent("Child Force Expand"));
  48. rect.width = Mathf.Max(50, (rect.width - 4) / 3);
  49. EditorGUIUtility.labelWidth = 50;
  50. ToggleLeft(rect, m_ChildForceExpandWidth, EditorGUIUtility.TrTextContent("Width"));
  51. rect.x += rect.width + 2;
  52. ToggleLeft(rect, m_ChildForceExpandHeight, EditorGUIUtility.TrTextContent("Height"));
  53. EditorGUIUtility.labelWidth = 0;
  54. EditorGUILayout.PropertyField(m_SnapEnable, true);
  55. EditorGUILayout.PropertyField(m_InverseChildPosEnable, true);
  56. if (!m_ChildControlWidth.boolValue && !m_ChildControlHeight.boolValue)
  57. {
  58. EditorGUILayout.PropertyField(m_InvisibleVaild, true);
  59. }
  60. else
  61. {
  62. if (m_InvisibleVaild.boolValue)
  63. {
  64. m_InvisibleVaild.boolValue = false;
  65. }
  66. }
  67. serializedObject.ApplyModifiedProperties();
  68. }
  69. void ToggleLeft(Rect position, SerializedProperty property, GUIContent label)
  70. {
  71. bool toggle = property.boolValue;
  72. EditorGUI.showMixedValue = property.hasMultipleDifferentValues;
  73. EditorGUI.BeginChangeCheck();
  74. int oldIndent = EditorGUI.indentLevel;
  75. EditorGUI.indentLevel = 0;
  76. toggle = EditorGUI.ToggleLeft(position, label, toggle);
  77. EditorGUI.indentLevel = oldIndent;
  78. if (EditorGUI.EndChangeCheck())
  79. {
  80. property.boolValue = property.hasMultipleDifferentValues ? true : !property.boolValue;
  81. }
  82. EditorGUI.showMixedValue = false;
  83. }
  84. }