Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HorizontalOrVerticalLayoutGroupEditor.cs 4.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEditorInternal;
  4. using UnityEditor.AnimatedValues;
  5. namespace UnityEditor.UI
  6. {
  7. [CustomEditor(typeof(HorizontalOrVerticalLayoutGroup), true)]
  8. [CanEditMultipleObjects]
  9. /// <summary>
  10. /// Custom Editor for the HorizontalOrVerticalLayoutGroupEditor Component.
  11. /// Extend this class to write a custom editor for a component derived from HorizontalOrVerticalLayoutGroupEditor.
  12. /// </summary>
  13. public class HorizontalOrVerticalLayoutGroupEditor : Editor
  14. {
  15. SerializedProperty m_Padding;
  16. SerializedProperty m_Spacing;
  17. SerializedProperty m_ChildAlignment;
  18. SerializedProperty m_ChildControlWidth;
  19. SerializedProperty m_ChildControlHeight;
  20. SerializedProperty m_ChildScaleWidth;
  21. SerializedProperty m_ChildScaleHeight;
  22. SerializedProperty m_ChildForceExpandWidth;
  23. SerializedProperty m_ChildForceExpandHeight;
  24. SerializedProperty m_ReverseArrangement;
  25. protected virtual void OnEnable()
  26. {
  27. m_Padding = serializedObject.FindProperty("m_Padding");
  28. m_Spacing = serializedObject.FindProperty("m_Spacing");
  29. m_ChildAlignment = serializedObject.FindProperty("m_ChildAlignment");
  30. m_ChildControlWidth = serializedObject.FindProperty("m_ChildControlWidth");
  31. m_ChildControlHeight = serializedObject.FindProperty("m_ChildControlHeight");
  32. m_ChildScaleWidth = serializedObject.FindProperty("m_ChildScaleWidth");
  33. m_ChildScaleHeight = serializedObject.FindProperty("m_ChildScaleHeight");
  34. m_ChildForceExpandWidth = serializedObject.FindProperty("m_ChildForceExpandWidth");
  35. m_ChildForceExpandHeight = serializedObject.FindProperty("m_ChildForceExpandHeight");
  36. m_ReverseArrangement = serializedObject.FindProperty("m_ReverseArrangement");
  37. }
  38. public override void OnInspectorGUI()
  39. {
  40. serializedObject.Update();
  41. EditorGUILayout.PropertyField(m_Padding, true);
  42. EditorGUILayout.PropertyField(m_Spacing, true);
  43. EditorGUILayout.PropertyField(m_ChildAlignment, true);
  44. EditorGUILayout.PropertyField(m_ReverseArrangement, true);
  45. Rect rect = EditorGUILayout.GetControlRect();
  46. rect = EditorGUI.PrefixLabel(rect, -1, EditorGUIUtility.TrTextContent("Control Child Size"));
  47. rect.width = Mathf.Max(50, (rect.width - 4) / 3);
  48. EditorGUIUtility.labelWidth = 50;
  49. ToggleLeft(rect, m_ChildControlWidth, EditorGUIUtility.TrTextContent("Width"));
  50. rect.x += rect.width + 2;
  51. ToggleLeft(rect, m_ChildControlHeight, EditorGUIUtility.TrTextContent("Height"));
  52. EditorGUIUtility.labelWidth = 0;
  53. rect = EditorGUILayout.GetControlRect();
  54. rect = EditorGUI.PrefixLabel(rect, -1, EditorGUIUtility.TrTextContent("Use Child Scale"));
  55. rect.width = Mathf.Max(50, (rect.width - 4) / 3);
  56. EditorGUIUtility.labelWidth = 50;
  57. ToggleLeft(rect, m_ChildScaleWidth, EditorGUIUtility.TrTextContent("Width"));
  58. rect.x += rect.width + 2;
  59. ToggleLeft(rect, m_ChildScaleHeight, EditorGUIUtility.TrTextContent("Height"));
  60. EditorGUIUtility.labelWidth = 0;
  61. rect = EditorGUILayout.GetControlRect();
  62. rect = EditorGUI.PrefixLabel(rect, -1, EditorGUIUtility.TrTextContent("Child Force Expand"));
  63. rect.width = Mathf.Max(50, (rect.width - 4) / 3);
  64. EditorGUIUtility.labelWidth = 50;
  65. ToggleLeft(rect, m_ChildForceExpandWidth, EditorGUIUtility.TrTextContent("Width"));
  66. rect.x += rect.width + 2;
  67. ToggleLeft(rect, m_ChildForceExpandHeight, EditorGUIUtility.TrTextContent("Height"));
  68. EditorGUIUtility.labelWidth = 0;
  69. serializedObject.ApplyModifiedProperties();
  70. }
  71. void ToggleLeft(Rect position, SerializedProperty property, GUIContent label)
  72. {
  73. bool toggle = property.boolValue;
  74. EditorGUI.BeginProperty(position, label, property);
  75. EditorGUI.BeginChangeCheck();
  76. int oldIndent = EditorGUI.indentLevel;
  77. EditorGUI.indentLevel = 0;
  78. toggle = EditorGUI.ToggleLeft(position, label, toggle);
  79. EditorGUI.indentLevel = oldIndent;
  80. if (EditorGUI.EndChangeCheck())
  81. {
  82. property.boolValue = property.hasMultipleDifferentValues ? true : !property.boolValue;
  83. }
  84. EditorGUI.EndProperty();
  85. }
  86. }
  87. }