少年修仙传客户端基础资源
lcy
2025-05-08 058f8809f1cdca65e5d0c322cbe7eb09d2353791
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
using UnityEngine;
using UnityEditor;
using vnxbqy.UI;
using UnityEditorInternal;
 
[CustomEditor(typeof(WidgetBehavior), true)]
public class WidgetBehaviorEditor : Editor
{
 
    ReorderableList list;
    void OnEnable()
    {
        var serProp = this.serializedObject.FindProperty("widgets");
        this.list = new ReorderableList(serProp.serializedObject, serProp, true, true, true, true);
        this.list.drawHeaderCallback = this.OnDrawListHeader;
        this.list.drawElementCallback = this.OnDrawListElement;
        this.list.onAddCallback = this.OnAddCallback;
    }
    void OnDrawListHeader(Rect rect)
    {
        var spacing = 10f;
        var arect = rect;
        arect.height = EditorGUIUtility.singleLineHeight;
        arect.x += 15;
        arect.width = 200;
        EditorGUI.LabelField(arect, "Name");
        arect.x += arect.width + spacing;
        arect.width = 200;
        EditorGUI.LabelField(arect, "GameObject");
    }
 
    void OnAddCallback(ReorderableList list)
    {
        if (list.serializedProperty != null)
        {
            list.serializedProperty.arraySize++;
            list.index = list.serializedProperty.arraySize - 1;
 
            SerializedProperty itemData = list.serializedProperty.GetArrayElementAtIndex(list.index);
            var namePop = itemData.FindPropertyRelative("name");
            namePop.stringValue = null;
            var goPop = itemData.FindPropertyRelative("gameObject");
            goPop.objectReferenceValue = null;
        }
        else
        {
            ReorderableList.defaultBehaviours.DoAddButton(list);
        }
    }
 
    void OnDrawListElement(Rect rect, int index, bool isActive, bool isFocused)
    {
        var spacing = 10f;
        var arect = rect;
        var element = this.list.serializedProperty.GetArrayElementAtIndex(index);
 
        var nameProperty = element.FindPropertyRelative("name");
        var goProperty = element.FindPropertyRelative("gameObject");
 
        arect.height = EditorGUIUtility.singleLineHeight;
        arect.width = 200;
        if (goProperty.objectReferenceValue != null && string.IsNullOrEmpty(nameProperty.stringValue))
            nameProperty.stringValue = EditorGUI.TextField(arect, goProperty.objectReferenceValue.name);
        else
            nameProperty.stringValue = EditorGUI.TextField(arect, nameProperty.stringValue);
        arect.x += arect.width + spacing;
        arect.width = 200;
        EditorGUI.PropertyField(arect, goProperty, GUIContent.none);
    }
 
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        this.serializedObject.Update();
        var property = list.serializedProperty;
        property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, property.displayName);
        if (property.isExpanded)
        {
            this.list.DoLayoutList();
        }
        this.serializedObject.ApplyModifiedProperties();
    }
 
}