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();
|
}
|
}
|
|
}
|