aboutsummaryrefslogtreecommitdiff
path: root/Assets/Scripts/DamageVolumeSystem/Editor/DamageHostEditor.cs
blob: acf0388f96c4adf0e91b8f2657a2aec3a9672e61 (plain) (blame)
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
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;

namespace DamageVolumeSystem.Editor
{
    [CustomEditor(typeof(DamageHost))]
    public class DamageHostEditor : UnityEditor.Editor
    {
        /*
         * Editor page created by Mountools
         * Author : WangSoul
         * Date : 2026 / 05 / 09 - 15:26:18
         */
    
        public DamageHost damageHost;

        private void OnEnable()
        {
            damageHost = (DamageHost) target;
        }

        private void DrawDamageHostEditor()
        {
            EditorGUILayout.HelpBox("这玩意用来绑在产生伤害或接收伤害的物体上的,绑上去就能接收事件了,但是具体伤害事件还得单独接入,不同物体有不同的接收伤害模式。", MessageType.Info);
            
            EditorGUILayout.LabelField("伤害组 ID,同 ID 的物体不会互相伤害");
            DrawGroupButtons(ref damageHost.group, 12);

            EditorGUILayout.Space();
            
            EditorGUILayout.HelpBox($"当前组内发现 {damageHost.generators.Count} 个伤害生成器,修改了一定要记得重新搜寻", MessageType.Info);
            EditorGUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("搜寻"))
                {
                    damageHost.generators.Clear();
                    foreach (var generator in damageHost.gameObject.GetComponentsInChildren<DamageGenerator>())
                    {
                        damageHost.generators.Add(generator);
                        
                        generator.binding = damageHost;
                        EditorUtility.SetDirty(generator);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();;

            EditorGUILayout.Space();
            
            EditorGUILayout.HelpBox("这玩意是伤害事件,当有伤害发生时会执行,记得绑定", MessageType.Info);
        }
        
        private static void DrawGroupButtons(ref int groupValue, int buttonCount, int columns = 4)
        {
            for (int i = 0; i < buttonCount; i += columns)
            {
                EditorGUILayout.BeginHorizontal();
                for (int j = 0; j < columns && i + j < buttonCount; j++)
                {
                    int buttonValue = i + j;
                    var color = GUI.backgroundColor;
                    GUI.backgroundColor = (groupValue == buttonValue) ? new Color(0.51f, 0.69f, 1f) : color;
                    if (GUILayout.Button(buttonValue.ToString(), GUILayout.Width(24)))
                    {
                        groupValue = buttonValue;
                    }

                    GUI.backgroundColor = color;
                }
                EditorGUILayout.EndHorizontal();
            }
        }
        
        #region _
        
        public override void OnInspectorGUI()
        {
            Undo.RecordObject(damageHost, "Edit DamageHost");
            EditorGUI.BeginChangeCheck();
            
            DrawDamageHostEditor();
            DrawDefaultInspector();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(damageHost);
                Undo.FlushUndoRecordObjects();
                serializedObject.ApplyModifiedProperties();
            }
        }
        
        private bool Property(string label, string propertyName, params GUILayoutOption[] options)
        {
            return EditorGUILayout.PropertyField(serializedObject.FindProperty(propertyName), new GUIContent(label), options);
        }
        
        #endregion
    }
}
#endif