少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
using System.Collections.Generic;
using UnityEngine;
using System.IO;
 
#if UNITY_EDITOR
using UnityEditor;
#endif
 
namespace H2Engine
{
    public class Bhv_MapTrigger : MonoBehaviour
    {
        [HideInInspector]
        public int id;
        [HideInInspector]
        public MapTrigger.E_TriggerType triggerType = MapTrigger.E_TriggerType.Trigger;
        [HideInInspector]
        public Evt.E_EventType type = Evt.E_EventType.Enemy;
        [HideInInspector]
        public int prevID = -1;
        [HideInInspector]
        public int nextID = -1;
        [HideInInspector]
        public List<int> eventIDList = new List<int>();
 
#if UNITY_EDITOR
 
        [HideInInspector]
        public BoxCollider boxCollider;
 
        private bool showDetail = false;
        private bool showEventList = false;
 
        public void Save(BinaryWriter bw)
        {
            bw.Write(id);
            bw.Write((byte)triggerType);
            bw.Write((byte)type);
            bw.Write(prevID);
            bw.Write(nextID);
            bw.Write((float)System.Math.Round(transform.position.x, 2));
            bw.Write((float)System.Math.Round(transform.position.y, 2));
            bw.Write((float)System.Math.Round(transform.position.z, 2));
            bw.Write((float)System.Math.Round(boxCollider.size.x, 2));
            bw.Write((float)System.Math.Round(boxCollider.size.z, 2));
            bw.Write((float)System.Math.Round(transform.eulerAngles.y, 2));
            bw.Write(eventIDList.Count);
            foreach (var _eventID in eventIDList)
            {
                bw.Write(_eventID);
            }
        }
 
        public void SaveJson(System.Text.StringBuilder stringBuilder)
        {
            stringBuilder.Append("{");
            stringBuilder.Append("\"id\":").Append(id).Append(",");
            stringBuilder.Append("\"triggerType\":").Append((byte)triggerType).Append(",");
            stringBuilder.Append("\"type\":").Append((byte)type).Append(",");
            stringBuilder.Append("\"prevID\":").Append(prevID).Append(",");
            stringBuilder.Append("\"nextID\":").Append(nextID).Append(",");
            stringBuilder.Append("\"px\":").Append((float)System.Math.Round(transform.position.x, 2)).Append(",");
            stringBuilder.Append("\"py\":").Append((float)System.Math.Round(transform.position.y, 2)).Append(",");
            stringBuilder.Append("\"pz\":").Append((float)System.Math.Round(transform.position.z, 2)).Append(",");
            stringBuilder.Append("\"sx\":").Append((float)System.Math.Round(boxCollider.size.x, 2)).Append(",");
            stringBuilder.Append("\"sz\":").Append((float)System.Math.Round(boxCollider.size.z, 2)).Append(",");
            stringBuilder.Append("\"ey\":").Append((float)System.Math.Round(transform.eulerAngles.y, 2)).Append(",");
            stringBuilder.Append("\"eventIDList\":[");
            if (eventIDList.Count > 0)
            {
                stringBuilder.Append(eventIDList[0]);
                for (int i = 1; i < eventIDList.Count; ++i)
                {
                    stringBuilder.Append(",").Append(eventIDList[i]);
                }
            }
            stringBuilder.Append("]");
            stringBuilder.Append("}");
        }
 
        public void LoadJson(LitJson.JsonData json)
        {
            eventIDList.Clear();
 
            id = (int)json["id"];
            triggerType = (MapTrigger.E_TriggerType)(byte)json["triggerType"];
            type = (Evt.E_EventType)(byte)json["type"];
            prevID = (int)json["prevID"];
            nextID = (int)json["nextID"];
            float _pX = Bhv_MapData.GetJsonFloat(json["px"]);
            float _pY = Bhv_MapData.GetJsonFloat(json["py"]);
            float _pZ = Bhv_MapData.GetJsonFloat(json["pz"]);
            float _x = Bhv_MapData.GetJsonFloat(json["sx"]);
            float _z = Bhv_MapData.GetJsonFloat(json["sz"]);
            float _eY = Bhv_MapData.GetJsonFloat(json["ey"]);
            transform.position = new Vector3(_pX, _pY, _pZ);
            boxCollider.size = new Vector3(_x, 1, _z);
            transform.eulerAngles = new Vector3(0, _eY, 0);
            var _jsonData = json["eventIDList"];
            for (int i = 0; i < _jsonData.Count; ++i)
            {
                eventIDList.Add((int)_jsonData[i]);
            }
        }
 
        public void Export(BinaryWriter bw)
        {
            Save(bw);
        }
 
        public void Load(BinaryReader br)
        {
            id = br.ReadInt32();
            triggerType = (MapTrigger.E_TriggerType)br.ReadByte();
            type = (Evt.E_EventType)br.ReadByte();
            prevID = br.ReadInt32();
            nextID = br.ReadInt32();
            float _pX = br.ReadSingle();
            float _pY = br.ReadSingle();
            float _pZ = br.ReadSingle();
            float _x = br.ReadSingle();
            float _z = br.ReadSingle();
            float _eY = br.ReadSingle();
            int _count = br.ReadInt32();
            for (int i = 0; i < _count; ++i)
            {
                eventIDList.Add(br.ReadInt32());
            }
            transform.position = new Vector3(_pX, _pY, _pZ);
            boxCollider.size = new Vector3(_x, 1, _z);
            transform.eulerAngles = new Vector3(0, _eY, 0);
        }
 
        public bool DrawUI(GUISkin guiSkin)
        {
            bool _result = false;
            EditorGUILayout.BeginVertical(guiSkin.box);
            EditorGUILayout.BeginHorizontal(GUILayout.Height(22));
            EditorGUI.indentLevel += 1;
            showDetail = EditorGUILayout.Foldout(showDetail, "", true, guiSkin.customStyles[3]);
            EditorGUILayout.LabelField("触发器ID:", guiSkin.customStyles[0], GUILayout.Height(22), GUILayout.Width(70));
            id = EditorGUILayout.IntField(id, guiSkin.textField, GUILayout.Height(22), GUILayout.Width(60));
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("查找", guiSkin.button, GUILayout.Width(60), GUILayout.Height(22)))
            {
                Selection.activeGameObject = gameObject;
                if (Selection.activeGameObject)
                {
                    SceneView.lastActiveSceneView.LookAt(Selection.activeGameObject.transform.position);
                }
            }
            if (GUILayout.Button("删除", guiSkin.button, GUILayout.Width(60), GUILayout.Height(22)))
            {
                _result = true;
            }
            EditorGUILayout.EndHorizontal();
            if (showDetail)
            {
                EditorGUILayout.BeginHorizontal(GUILayout.Height(22));
                EditorGUILayout.LabelField("触发器类型", guiSkin.customStyles[0], GUILayout.Height(22), GUILayout.Width(80));
                triggerType = (MapTrigger.E_TriggerType)EditorGUILayout.EnumPopup(triggerType, guiSkin.customStyles[1], GUILayout.Height(20), GUILayout.Width(100));
                if (triggerType != MapTrigger.E_TriggerType.EnterStage)
                {
                    var _descript = string.Empty;
                    if (triggerType == MapTrigger.E_TriggerType.Trigger)
                    {
                        _descript = "前置ID";
                    }
                    else if (triggerType == MapTrigger.E_TriggerType.Mission)
                    {
                        _descript = "任务ID";
                    }
                    EditorGUILayout.LabelField(_descript, guiSkin.customStyles[0], GUILayout.Height(22), GUILayout.Width(55));
                    prevID = EditorGUILayout.IntField(prevID, guiSkin.textField, GUILayout.Height(20));
                }
                EditorGUILayout.LabelField("结束触发", guiSkin.customStyles[0], GUILayout.Height(22), GUILayout.Width(55));
                nextID = EditorGUILayout.IntField(nextID, guiSkin.textField, GUILayout.Height(20));
                EditorGUILayout.EndHorizontal();
 
                EditorGUILayout.BeginVertical(guiSkin.customStyles[1]);
 
                EditorGUILayout.BeginHorizontal(GUILayout.Height(22));
                if (eventIDList.Count > 0)
                {
                    showEventList = EditorGUILayout.Foldout(showEventList, "  触发事件列表", true, guiSkin.customStyles[3]);
                }
                else
                {
                    EditorGUILayout.LabelField("  触发事件列表:", guiSkin.customStyles[0], GUILayout.Height(22), GUILayout.Width(100));
                    GUILayout.FlexibleSpace();
                }
                if (GUILayout.Button("添加", guiSkin.button, GUILayout.Width(60), GUILayout.Height(22)))
                {
                    eventIDList.Add(0);
                    showEventList = true;
                }
                EditorGUILayout.EndHorizontal();
 
                if (showEventList)
                {
                    for (int i = eventIDList.Count - 1; i >= 0; --i)
                    {
                        EditorGUILayout.BeginHorizontal(guiSkin.box, GUILayout.Height(22));
                        EditorGUILayout.LabelField("事件ID", guiSkin.customStyles[0], GUILayout.Height(20), GUILayout.Width(60));
                        eventIDList[i] = EditorGUILayout.IntField(eventIDList[i], guiSkin.textField, GUILayout.Height(22));
                        if (GUILayout.Button("删除", guiSkin.button, GUILayout.Width(60), GUILayout.Height(22)))
                        {
                            eventIDList.RemoveAt(i);
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUI.indentLevel -= 1;
            EditorGUILayout.EndVertical();
 
            return _result;
        }
#endif
    }
}