| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #if UNITY_EDITOR
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.UI;
- namespace AdaptUI
- {
- [CustomEditor(typeof(UIVerticalLayoutGroup))]
- [CanEditMultipleObjects]
- public class UIVerticalLayoutGroupEditor : Editor
- {
- private SerializedProperty defaultLayout;
- private SerializedProperty iPhoneLayout;
- private SerializedProperty iPadLayout;
- private void OnEnable()
- {
- defaultLayout = serializedObject.FindProperty("defaultLayout");
- iPhoneLayout = serializedObject.FindProperty("iPhoneLayout");
- iPadLayout = serializedObject.FindProperty("iPadLayout");
- }
- public override void OnInspectorGUI()
- {
- UIVerticalLayoutGroup script = (UIVerticalLayoutGroup)target;
- VerticalLayoutGroup vertical = script.GetComponent<VerticalLayoutGroup>();
- EditorGUILayout.Space();
- EditorGUILayout.LabelField("UI 垂直布局", EditorStyles.boldLabel);
- DrawLayoutEditor(script, "默认布局", ref script.defaultLayout, vertical);
- DrawLayoutEditor(script, "iPhone 布局", ref script.iPhoneLayout, vertical);
- DrawLayoutEditor(script, "iPad 布局", ref script.iPadLayout, vertical);
- EditorGUILayout.Space();
- if (GUILayout.Button("应用当前布局"))
- {
- script.ApplyLayout();
- }
- serializedObject.ApplyModifiedProperties();
- }
- private void DrawLayoutEditor(UIVerticalLayoutGroup script, string title, ref UILayoutData layout, VerticalLayoutGroup verticalLayout)
- {
- EditorGUILayout.LabelField(title, EditorStyles.boldLabel);
- EditorGUI.indentLevel++;
- EditorGUILayout.LabelField("Padding", EditorStyles.boldLabel);
- layout.paddingLeft = EditorGUILayout.IntField("Left", layout.paddingLeft);
- layout.paddingRight = EditorGUILayout.IntField("Right", layout.paddingRight);
- layout.paddingTop = EditorGUILayout.IntField("Top", layout.paddingTop);
- layout.paddingBottom = EditorGUILayout.IntField("Bottom", layout.paddingBottom);
- layout.spacing = EditorGUILayout.FloatField("Spacing", layout.spacing);
- layout.childAlignment = (TextAnchor)EditorGUILayout.EnumPopup("Child Alignment", layout.childAlignment);
- layout.reverseArrangement = EditorGUILayout.Toggle("Reverse Arrangement", layout.reverseArrangement);
- layout.controlChildWidth = EditorGUILayout.Toggle("Control Child Width", layout.controlChildWidth);
- layout.controlChildHeight = EditorGUILayout.Toggle("Control Child Height", layout.controlChildHeight);
- layout.useChildScaleWidth = EditorGUILayout.Toggle("Use Child Scale Width", layout.useChildScaleWidth);
- layout.useChildScaleHeight = EditorGUILayout.Toggle("Use Child Scale Height", layout.useChildScaleHeight);
- layout.childForceExpandWidth = EditorGUILayout.Toggle("Child Force Expand Width", layout.childForceExpandWidth);
- layout.childForceExpandHeight = EditorGUILayout.Toggle("Child Force Expand Height", layout.childForceExpandHeight);
- if (GUILayout.Button("应用 " + title + " 布局"))
- {
- verticalLayout.padding.left = layout.paddingLeft;
- verticalLayout.padding.right = layout.paddingRight;
- verticalLayout.padding.top = layout.paddingTop;
- verticalLayout.padding.bottom = layout.paddingBottom;
- verticalLayout.spacing = layout.spacing;
- verticalLayout.childAlignment = layout.childAlignment;
- verticalLayout.reverseArrangement = layout.reverseArrangement;
- verticalLayout.childControlWidth = layout.controlChildWidth;
- verticalLayout.childControlHeight = layout.controlChildHeight;
- verticalLayout.childScaleWidth = layout.useChildScaleWidth;
- verticalLayout.childScaleHeight = layout.useChildScaleHeight;
- verticalLayout.childForceExpandWidth = layout.childForceExpandWidth;
- verticalLayout.childForceExpandHeight = layout.childForceExpandHeight;
- Undo.RecordObject(script, "Set " + title + " Layout");
- EditorUtility.SetDirty(script);
- }
- EditorGUI.indentLevel--;
- EditorGUILayout.Space();
- }
- }
- }
- #endif
|