少年修仙传客户端代码仓库
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
using UnityEngine;
using System.Collections.Generic;
using System;
 
#if UNITY_EDITOR
using UnityEditor;
using System.IO;
#endif
 
public class SoMapObjectGenerate : ScriptableObject
{
    public List<int> missionList = new List<int>();
    public List<GenerateNPC> generateNPCList = new List<GenerateNPC>();
 
    [Serializable]
    public class GenerateNPC
    {
        public List<NpcInfo> npcList = new List<NpcInfo>();
    }
 
    [Serializable]
    public class NpcInfo
    {
        public int npcID;
        public Vector3 position;
        public Vector3 rotation;
    }
}
 
#if UNITY_EDITOR
[CustomEditor(typeof(SoMapObjectGenerate))]
public class SoMapObjectGenerateEditor : Editor
{
    private int m_MissionID;
    private int m_NpcID;
    private Vector3 m_BornPos;
    private Vector3 m_BornDir;
    private Dictionary<int, bool> m_FoldOut = new Dictionary<int, bool>();
    private static readonly GUIContent _line = new GUIContent("--------------------------------------------------------------------------------");
 
    [MenuItem("程序/地图对象生成配置")]
    static void CreateSoMapObjectGenerate()
    {
        SoMapObjectGenerate _config = CreateInstance<SoMapObjectGenerate>();
        string _createName = string.Format(ScriptableObjectLoader.SoMapObjectGenerate_Suffix,
                                           DateTime.UtcNow.ToFileTimeUtc());
        string _path = ResourcesPath.ResourcesOutPath + "refdata/ScriptableObject/SoMapObjectGenerate/";
        if (Directory.Exists(_path) == false)
        {
            Directory.CreateDirectory(_path);
        }
        _path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
                                      "refdata/ScriptableObject/SoMapObjectGenerate/",
                                      _createName,
                                      ".asset");
        AssetDatabase.CreateAsset(_config, _path);
        AssetDatabase.Refresh();
        ProjectWindowUtil.ShowCreatedAsset(_config);
    }
 
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
 
        SoMapObjectGenerate _target = target as SoMapObjectGenerate;
        EditorGUILayout.BeginHorizontal();
        m_MissionID = EditorGUILayout.IntField("任务ID", m_MissionID);
        if (GUILayout.Button("增加任务刷怪信息"))
        {
            if (m_MissionID != 0)
            {
                _target.missionList.Add(m_MissionID);
                _target.generateNPCList.Add(new SoMapObjectGenerate.GenerateNPC());
            }
        }
        EditorGUILayout.EndHorizontal();
 
        int _deleteIndex = -1;
        int _deleteNpcIndex = -1;
 
        for (int i = 0; i < _target.missionList.Count; ++i)
        {
            if (m_FoldOut.ContainsKey(_target.missionList[i]) == false)
            {
                m_FoldOut.Add(_target.missionList[i], true);
            }
 
            EditorGUILayout.BeginHorizontal();
 
            m_FoldOut[_target.missionList[i]] = EditorGUILayout.Foldout(m_FoldOut[_target.missionList[i]], "任务: " + _target.missionList[i]);
 
            if (GUILayout.Button("删除"))
            {
                _deleteIndex = i;
            }
 
            EditorGUILayout.EndHorizontal();
 
            if (m_FoldOut[_target.missionList[i]])
            {
                m_MissionID = EditorGUILayout.IntField("任务ID", m_MissionID);
                if (GUILayout.Button("修改任务ID"))
                {
                    if (m_MissionID != 0)
                    {
                        _target.missionList[i] = m_MissionID;
                    }
                }
 
                m_NpcID = EditorGUILayout.IntField("NpcID", m_NpcID);
                m_BornPos = EditorGUILayout.Vector3Field("出生点(客户端坐标)", m_BornPos);
                m_BornDir = EditorGUILayout.Vector3Field("旋转", m_BornDir);
 
                if (GUILayout.Button("增加NPC信息"))
                {
                    if (m_NpcID != 0)
                    {
                        SoMapObjectGenerate.NpcInfo _npcInfo = new SoMapObjectGenerate.NpcInfo();
                        _npcInfo.npcID = m_NpcID;
                        _npcInfo.position = m_BornPos;
                        _npcInfo.rotation = m_BornDir;
 
                        _target.generateNPCList[i].npcList.Add(_npcInfo);
                    }
                }
 
                EditorGUI.indentLevel += 1;
 
                for (int j = 0; j < _target.generateNPCList[i].npcList.Count; ++j)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.BeginVertical();
                    _target.generateNPCList[i].npcList[j].npcID = EditorGUILayout.IntField("NpcID", _target.generateNPCList[i].npcList[j].npcID);
                    _target.generateNPCList[i].npcList[j].position = EditorGUILayout.Vector3Field("出生点(客户端坐标)", _target.generateNPCList[i].npcList[j].position);
                    _target.generateNPCList[i].npcList[j].rotation = EditorGUILayout.Vector3Field("朝向", _target.generateNPCList[i].npcList[j].rotation);
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical();
                    if (GUILayout.Button("删除", GUILayout.Height(50)))
                    {
                        _deleteNpcIndex = j;
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                    if (j != _target.generateNPCList[i].npcList.Count - 1)
                    {
                        EditorGUILayout.LabelField(_line);
                    }
                }
 
                if (_deleteNpcIndex != -1)
                {
                    _target.generateNPCList[i].npcList.RemoveAt(_deleteNpcIndex);
                }
 
                EditorGUI.indentLevel -= 1;
            }
        }
 
        if (_deleteIndex >= 0)
        {
            _target.missionList.RemoveAt(_deleteIndex);
            _target.generateNPCList.RemoveAt(_deleteIndex);
        }
 
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            serializedObject.ApplyModifiedProperties();
        }
 
    }
}
#endif