三国卡牌客户端基础资源仓库
yyl
2025-05-30 8cb6ac07e11cc70922bd4c484773c6afb7a97fd9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using UnityEngine;
using UnityEditor;
 
[CustomEditor(typeof(UIBase))]
public class UIBaseInspector : Editor
{
    SerializedProperty uiLayer;
    SerializedProperty uiName;
    SerializedProperty isMainUI;
    SerializedProperty supportParentChildRelation;
    SerializedProperty isPersistent;
    SerializedProperty maxIdleRounds;
    SerializedProperty openAnimationType;
    SerializedProperty closeAnimationType;
    SerializedProperty animationDuration;
    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");
        animationEase = serializedObject.FindProperty("animationEase");
        openMask = serializedObject.FindProperty("openMask");
        clickEmptySpaceClose = serializedObject.FindProperty("clickEmptySpaceClose");
    }
 
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
 
        EditorGUILayout.PropertyField(uiLayer);
        EditorGUILayout.PropertyField(uiName);
        EditorGUILayout.PropertyField(isMainUI);
        EditorGUILayout.PropertyField(supportParentChildRelation);
 
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("持久化设置", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(isPersistent);
        if (isPersistent.boolValue)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(maxIdleRounds);
            EditorGUI.indentLevel--;
        }
 
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("动画设置", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(openAnimationType);
        EditorGUILayout.PropertyField(closeAnimationType);
        if (openAnimationType.enumValueIndex != 0 || closeAnimationType.enumValueIndex != 0)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(animationDuration);
            EditorGUILayout.PropertyField(animationEase);
            EditorGUI.indentLevel--;
        }
 
        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;
                    openMask.boolValue = true;
                }
                else
                {
                    openMask.boolValue = false;
                    clickEmptySpaceClose.boolValue = true;
                }
            }
            else
            {
                openMask.boolValue = tempOpenMask;
                clickEmptySpaceClose.boolValue = tempClickEmptyClose;
            }
        }
        
        EditorGUILayout.EndHorizontal();
 
        serializedObject.ApplyModifiedProperties();
    }
}