少年修仙传客户端基础资源
dabaoji
2023-11-13 0a23e1b83f8fda8ab9f9e32fe71c26c431faf63a
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
using System.IO;
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Animations;
 
using System;
 
public class ActorEditor : EditorWindow
{
 
    [MenuItem("程序/角色相关/角色生成工具")]
    static void ActorBuildTool()
    {
        EditorWindow _window = CreateInstance<ActorEditor>();
        _window.Show();
    }
 
    [MenuItem("程序/角色相关/卸载NPC动画状态机")]
    static void RemoveAnimator()
    {
        var _dict = NPCConfig.GetValues();
        int i = 0;
        foreach (var _model in _dict)
        {
            if (_model.NPCType != 0
             && _model.NPCType != 2
             && _model.NPCType != 3
             && _model.NPCType != 4
             && _model.NPCType != 5
             && _model.NPCType != 8
             && _model.NPCType != 9
             && _model.NPCType != 14
             && _model.NPCType != 16
             && _model.NPCType != 17
             && _model.NPCType != 18
             && _model.NPCType != 19)
            {
                continue;
            }
 
            if (string.IsNullOrEmpty(_model.MODE))
            {
                continue;
            }
 
 
        }
    }
 
    private enum BuildNpcType
    {
        Npc,
        Pet,
        Horse,
        Guard,
    }
 
    private BuildNpcType m_NpcType;
 
    private bool m_GenerateNoExist = false;
    private bool m_GenerateAnimationClip = false;
    private bool m_GenerateController = false;
    private bool m_GeneratePrefab = false;
    private bool m_GenerateUIController = false;
 
    private int m_ModelResID;
    private int m_NpcID;
    private string m_ModelName;
    private string m_BuildName;
 
    public bool m_HighMesh;
 
    private NpcResourcesBuilder m_NpcResBuilder;
    private ModelResourcesBuilder m_ModelResBuilder;
 
    private void OnEnable()
    {
        ConfigInitiator.EditorLoad();
        m_NpcResBuilder = new NpcResourcesBuilder();
        m_ModelResBuilder = new ModelResourcesBuilder();
    }
 
    private void OnGUI()
    {
        GUILayout.Space(4);
 
        EditorGUILayout.LabelField("# 生成Npc角色资源 #");
 
        EditorGUILayout.BeginVertical();
        m_ModelName = EditorGUILayout.TextField("来源名", m_ModelName);
        m_BuildName = EditorGUILayout.TextField("生成名", m_BuildName);
        EditorGUILayout.BeginHorizontal();
        m_NpcType = (BuildNpcType)EditorGUILayout.EnumPopup("类型:", m_NpcType);
        m_HighMesh = EditorGUILayout.ToggleLeft("高模", m_HighMesh);
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
        EditorGUILayout.BeginHorizontal();
        m_GenerateNoExist = GUILayout.Toggle(m_GenerateNoExist, "只生成不存在的");
        m_GeneratePrefab = GUILayout.Toggle(m_GeneratePrefab, "Prefab");
        m_GenerateAnimationClip = GUILayout.Toggle(m_GenerateAnimationClip, "Clips");
        m_GenerateController = GUILayout.Toggle(m_GenerateController, "Controller");
        m_GenerateUIController = GUILayout.Toggle(m_GenerateUIController, "UI_Controller");
        ResourcesBuilder.OnlyBuildNoExist = m_GenerateNoExist;
        ResourcesBuilder.IsBuildPrefab = m_GeneratePrefab;
        ResourcesBuilder.IsBuildAnimationClip = m_GenerateAnimationClip;
        ResourcesBuilder.IsBuildAnimatorController = m_GenerateController;
        ResourcesBuilder.IsBuildAnimatorUIController = m_GenerateUIController;
        EditorGUILayout.EndHorizontal();
 
        if (GUILayout.Button("单独生成", GUILayout.Height(24)))
        {
            m_NpcResBuilder.BuildNpc(m_ModelName, m_BuildName, (int)m_NpcType, m_HighMesh);
        }
 
        if (GUILayout.Button("按照给定的NPC配置信息生成"))
        {
            bool _result = EditorUtility.DisplayDialog("温馨提醒", "生成所有换装资源将会耗费比较长的时间, 请记得几点, 是否是需要生成所有的资源, 如果不是, 记得可以去掉不生成的资源,是不是不需要生成已经存在的资源, 如果不需要, 记得勾选[只生成不存在的]", "确认生成", "我按错了");
            if (_result)
            {
                BuildAllUIAnimatorController();
            }
        }
 
        GUILayout.Space(10);
 
        EditorGUILayout.LabelField("# 换装资源生成(坐骑, 衣服, 武器, 翅膀) #");
 
        m_ModelResID = EditorGUILayout.IntField("ModelResID", m_ModelResID);
 
        if (GUILayout.Button("单独生成", GUILayout.Height(24)))
        {
            m_ModelResBuilder.BuildModelRes(m_ModelResID, m_HighMesh);
        }
 
        if (GUILayout.Button("所有翅膀", GUILayout.Height(24)))
        {
 
            var _dict = ModelResConfig.GetValues();
            foreach (var _item in _dict)
            {
                if (_item.Type == (int)E_ModelResType.Wing)
                {
                    m_ModelResBuilder.BuildWing(_item.ID, m_HighMesh);
                }
            }
        }
 
        if (GUILayout.Button("所有武器", GUILayout.Height(24)))
        {
 
            var _dict = ModelResConfig.GetValues();
            foreach (var _item in _dict)
            {
                if (_item.Type == (int)E_ModelResType.Weapon)
                {
                    m_ModelResBuilder.BuildWeapon(_item.ID, m_HighMesh);
                }
            }
        }
 
        if (GUILayout.Button("所有副手", GUILayout.Height(24)))
        {
 
            var _dict = ModelResConfig.GetValues();
            foreach (var _item in _dict)
            {
                if (_item.Type == (int)E_ModelResType.Secondary)
                {
                    m_ModelResBuilder.BuildSecondary(_item.ID, m_HighMesh);
                }
            }
        }
 
        if (GUILayout.Button("所有衣服", GUILayout.Height(24)))
        {
 
            var _dict = ModelResConfig.GetValues();
            foreach (var _item in _dict)
            {
                if (_item.Type == (int)E_ModelResType.Suit)
                {
                    m_ModelResBuilder.BuildClothes(_item.ID, m_HighMesh);
                }
            }
        }
 
        if (GUILayout.Button("所有坐骑", GUILayout.Height(24)))
        {
 
            var _dict = ModelResConfig.GetValues();
            foreach (var _item in _dict)
            {
                if (_item.Type == (int)E_ModelResType.Horse)
                {
                    m_ModelResBuilder.BuildHorse(_item.ID, m_HighMesh);
                }
            }
        }
 
        if (GUILayout.Button("所有换装", GUILayout.Height(24)))
        {
            bool _result = EditorUtility.DisplayDialog("温馨提醒", "生成所有换装资源将会耗费比较长的时间, 请记得几点, 是否是需要生成所有的资源, 如果不是, 记得可以去掉不生成的资源,是不是不需要生成已经存在的资源, 如果不需要, 记得勾选[只生成不存在的]", "确认生成", "我按错了");
            if (_result)
            {
                var _dict = ModelResConfig.GetValues();
                foreach (var _item in _dict)
                {
                    m_ModelResBuilder.BuildModelRes(_item.ID, m_HighMesh);
                }
            }
        }
 
        GUILayout.Space(10);
 
        if (GUILayout.Button("重命名AssetBundle"))
        {
            ReAssetBundleName();
        }
    }
 
    private void BuildAllUIAnimatorController()
    {
        string _configPath = EditorUtility.OpenFilePanel("选择配置文件", Application.dataPath + "/Editor/Config", "txt");
        if (!string.IsNullOrEmpty(_configPath))
        {
            string[] _modeNames = File.ReadAllLines(_configPath);
            for (int i = 0; i < _modeNames.Length; ++i)
            {
                _modeNames[i] = _modeNames[i].Trim();
                if (string.IsNullOrEmpty(_modeNames[i]))
                {
                    continue;
                }
 
                var _kv = _modeNames[i].Split('\t');
 
                m_NpcResBuilder.BuildNpc(_kv[0], _kv[1], int.Parse(_kv[2]), m_HighMesh);
            }
        }
    }
 
    private List<string> m_Path = new List<string>();
 
    private void ReAssetBundleName()
    {
        string _path = Application.dataPath + "/ResourcesOut/Gmodels";
        m_Path.Clear();
 
        GetFileList(_path);
 
        string _assetPath;
        string _assetName;
        string _temp;
 
        foreach (string _filePath in m_Path)
        {
            int _length = 0;
            _assetPath = _filePath.Substring(_path.IndexOf("Assets"));
            _temp = _filePath.Substring(_filePath.IndexOf("Gmodels") + 8);
 
            if (_filePath.Contains("CreateRole"))
            {
                continue;
            }
 
            if (_temp.IndexOf(Path.DirectorySeparatorChar) == -1)
            {
                if (_temp.Contains(InstanceResourcesLoader.raceSuffix))
                {
                    _length = InstanceResourcesLoader.raceSuffix.Length;
                }
                else if (_temp.Contains(InstanceResourcesLoader.horseSuffix))
                {
                    _length = InstanceResourcesLoader.horseSuffix.Length;
                }
                else if (_temp.Contains(InstanceResourcesLoader.weaponSuffix))
                {
                    _length = InstanceResourcesLoader.weaponSuffix.Length;
                }
                else if (_temp.Contains(InstanceResourcesLoader.secondarySuffix))
                {
                    _length = InstanceResourcesLoader.secondarySuffix.Length;
                }
                else if (_temp.Contains(InstanceResourcesLoader.wingSuffix))
                {
                    _length = InstanceResourcesLoader.wingSuffix.Length;
                }
                _assetName = Path.GetFileNameWithoutExtension(_temp).Substring(_length);
            }
            else
            {
                _assetName = _temp.Substring(0, _temp.IndexOf(Path.DirectorySeparatorChar));
            }
 
            AssetImporter _assetImport = AssetImporter.GetAtPath(_assetPath);
            _assetImport.assetBundleName = ResourcesPath.MOB_FOLDER_NAME + (InstanceResourcesLoader.raceSuffix + _assetName).ToLower();
            EditorUtility.SetDirty(_assetImport);
 
            _assetPath = "Assets/Art/Role/" + _assetName + "/Materials/" + _assetName + ".mat";
            _assetImport = AssetImporter.GetAtPath(_assetPath);
            if (_assetImport)
            {
                _assetImport.assetBundleName = null;
                EditorUtility.SetDirty(_assetImport);
            }
        }
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        m_Path.Clear();
    }
 
    private void GetFileList(string path)
    {
        string[] _filePaths = Directory.GetFiles(path);
 
        string _extension = null;
 
        foreach (string _filePath in _filePaths)
        {
            _extension = Path.GetExtension(_filePath);
 
            if (_filePath.Contains("Temple_AnimatorController"))
            {
                continue;
            }
 
            if (_extension.Contains(".anim")
             || _extension.Contains(".controller")
             || _extension.Contains(".prefab"))
            {
                m_Path.Add(_filePath);
            }
        }
 
        string[] _directories = Directory.GetDirectories(path);
 
        foreach (string _directory in _directories)
        {
            GetFileList(_directory);
        }
    }
 
    [MenuItem("Assets/角色编辑/导出选择的FBX的.anim到指定文件夹的AnimationClips文件夹下")]
    static void ExportAnimationClips()
    {
 
        UnityEngine.Object[] _selectObjects = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
        if (_selectObjects == null || _selectObjects.Length == 0)
        {
            return;
        }
 
        string _exportPath = EditorUtility.OpenFolderPanel("导出到文件夹", Application.dataPath, string.Empty);
        if (_exportPath != null)
        {
 
            _exportPath = _exportPath.Substring(_exportPath.LastIndexOf("Assets"));
 
            if (_exportPath.IndexOf("AnimationClips") == -1)
            {
                _exportPath = _exportPath + "/AnimationClips/";
            }
            else
            {
                _exportPath += "/";
            }
 
            if (new DirectoryInfo(_exportPath).Exists == false)
            {
                Directory.CreateDirectory(_exportPath);
            }
 
            string _assetPath = string.Empty;
            string _newAssetPath = string.Empty;
            string _assetName = string.Empty;
            UnityEngine.Object _clip = null;
            int _index = 0;
            foreach (var _object in _selectObjects)
            {
                _index += 1;
                _assetPath = AssetDatabase.GetAssetPath(_object);
                _assetName = _object.name.Substring(_object.name.IndexOf("@") + 1);
                _newAssetPath = _exportPath + _assetName + ".anim";
                _clip = AssetDatabase.LoadAssetAtPath(_assetPath, typeof(AnimationClip));
                AnimationClip _newClip = new AnimationClip();
                EditorUtility.CopySerialized(_clip, _newClip);
                _newClip.legacy = false; // 因为使用新的
                AssetDatabase.CreateAsset(_newClip, _newAssetPath);
                EditorUtility.DisplayProgressBar("导出动画中...",
                                                 string.Format("正在导出 {0} .", _object.name),
                                                 _index * 1f / _selectObjects.Length);
            }
            EditorUtility.ClearProgressBar();
            AssetDatabase.Refresh();
        }
    }
 
    [MenuItem("程序/角色相关/生成动画状态机配置文件")]
    static void GeneralAnimatorBuildConfig()
    {
        string _exportPath = EditorUtility.SaveFilePanel("导出到文件夹", Application.dataPath, "animatorBuildConfig", "asset");
        if (_exportPath != null)
        {
            AnimatorBuildConfig _config = ScriptableObject.CreateInstance<AnimatorBuildConfig>();
            _exportPath = _exportPath.Substring(_exportPath.LastIndexOf("Assets"));
            AssetDatabase.CreateAsset(_config, _exportPath);
            AssetDatabase.Refresh();
        }
    }
 
}