| | |
| | | using UnityEngine; |
| | | using UnityEditor; |
| | | |
| | | [CustomEditor(typeof(UIBase))] |
| | | [CustomEditor(typeof(UIBase), true)] |
| | | public class UIBaseInspector : Editor |
| | | { |
| | | SerializedProperty uiLayer; |
| | |
| | | SerializedProperty supportParentChildRelation; |
| | | SerializedProperty isPersistent; |
| | | SerializedProperty maxIdleRounds; |
| | | |
| | | // 动画相关 |
| | | SerializedProperty openAnimationType; |
| | | SerializedProperty closeAnimationType; |
| | | SerializedProperty animationDuration; |
| | | SerializedProperty animeRoot; |
| | | SerializedProperty animeDuration; |
| | | SerializedProperty animationEase; |
| | | |
| | | SerializedProperty openMask; |
| | | SerializedProperty clickEmptySpaceClose; |
| | | |
| | | void OnEnable() |
| | | { |
| | | // 获取所有SerializedProperty |
| | | uiLayer = serializedObject.FindProperty("uiLayer"); |
| | | uiName = serializedObject.FindProperty("uiName"); |
| | | isMainUI = serializedObject.FindProperty("isMainUI"); |
| | | supportParentChildRelation = serializedObject.FindProperty("supportParentChildRelation"); |
| | | isPersistent = serializedObject.FindProperty("isPersistent"); |
| | | maxIdleRounds = serializedObject.FindProperty("maxIdleRounds"); |
| | | |
| | | openAnimationType = serializedObject.FindProperty("openAnimationType"); |
| | | closeAnimationType = serializedObject.FindProperty("closeAnimationType"); |
| | | animationDuration = serializedObject.FindProperty("animationDuration"); |
| | | animeRoot = serializedObject.FindProperty("_rectTransform"); |
| | | animeDuration = serializedObject.FindProperty("animeDuration"); |
| | | animationEase = serializedObject.FindProperty("animationEase"); |
| | | |
| | | openMask = serializedObject.FindProperty("openMask"); |
| | | clickEmptySpaceClose = serializedObject.FindProperty("clickEmptySpaceClose"); |
| | | } |
| | |
| | | EditorGUILayout.LabelField("动画设置", EditorStyles.boldLabel); |
| | | EditorGUILayout.PropertyField(openAnimationType); |
| | | EditorGUILayout.PropertyField(closeAnimationType); |
| | | EditorGUILayout.PropertyField(animeRoot, new GUIContent("animeRoot (动画根节点)")); |
| | | if (openAnimationType.enumValueIndex != 0 || closeAnimationType.enumValueIndex != 0) |
| | | { |
| | | EditorGUI.indentLevel++; |
| | | EditorGUILayout.PropertyField(animationDuration); |
| | | EditorGUILayout.PropertyField(animeDuration); |
| | | EditorGUILayout.PropertyField(animationEase); |
| | | EditorGUI.indentLevel--; |
| | | } |
| | | // 动画生效提示 |
| | | if ((openAnimationType.enumValueIndex != 0 || closeAnimationType.enumValueIndex != 0) && animeRoot.objectReferenceValue == null) |
| | | { |
| | | EditorGUILayout.HelpBox("如需动画生效,必须指定 animeRoot(动画根节点)!", MessageType.Warning); |
| | | } |
| | | |
| | | EditorGUILayout.Space(); |
| | | EditorGUILayout.LabelField("遮罩设置", EditorStyles.boldLabel); |
| | | |
| | | // 使用BeginHorizontal来创建一个水平布局组 |
| | | EditorGUILayout.BeginHorizontal(); |
| | | |
| | | // 创建一个开关按钮组 |
| | | EditorGUI.BeginChangeCheck(); |
| | | bool tempOpenMask = GUILayout.Toggle(openMask.boolValue, "开启遮罩", EditorStyles.miniButtonLeft); |
| | | bool tempClickEmptyClose = GUILayout.Toggle(clickEmptySpaceClose.boolValue, "点击空白关闭", EditorStyles.miniButtonRight); |
| | | |
| | | // 如果有改变 |
| | | if (EditorGUI.EndChangeCheck()) |
| | | { |
| | | // 确保只有一个可以为true |
| | | if (tempOpenMask && tempClickEmptyClose) |
| | | { |
| | | // 如果两个都为true,保持最后改变的那个为true |
| | | if (openMask.boolValue != tempOpenMask) |
| | | { |
| | | clickEmptySpaceClose.boolValue = false; |
| | |
| | | clickEmptySpaceClose.boolValue = tempClickEmptyClose; |
| | | } |
| | | } |
| | | |
| | | EditorGUILayout.EndHorizontal(); |
| | | |
| | | serializedObject.ApplyModifiedProperties(); |