101 lines
3.2 KiB
C#
101 lines
3.2 KiB
C#
using System.Collections.Generic;
|
|
using Sirenix.OdinInspector.Editor;
|
|
using Sirenix.Utilities;
|
|
using Sirenix.Utilities.Editor;
|
|
using UnityEditor;
|
|
using UnityEditor.VersionControl;
|
|
using UnityEngine;
|
|
namespace SkillEditor
|
|
{
|
|
public class CharacterBuilder : OdinEditorWindow
|
|
{
|
|
|
|
private static CharacterBuilder _instance;
|
|
|
|
|
|
// [MenuItem("Tools/角色组装器")]
|
|
private static void _OpenWindow()
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = GetWindow<CharacterBuilder>();
|
|
_instance.titleContent = new UnityEngine.GUIContent("角色创建器");
|
|
}
|
|
_instance.position = GUIHelper.GetEditorWindowRect().AlignCenter(400, 600);
|
|
_instance.Show();
|
|
}
|
|
|
|
private int _selectBaseModelIndex;
|
|
private List<GameObject> _baseModelList;
|
|
|
|
protected override void OnGUI()
|
|
{
|
|
// base.OnGUI();
|
|
|
|
// 搜寻指定目录下的所有fbx
|
|
if (_baseModelList == null)
|
|
{
|
|
_baseModelList = new List<GameObject>();
|
|
var fbxList = AssetDatabase.FindAssets("t:Model", new[]
|
|
{
|
|
"Assets/Art/Character/Models/Players",
|
|
"Assets/Art/Character/Models/Enemy"
|
|
});
|
|
foreach (var fbxGuid in fbxList)
|
|
{
|
|
var fbxPath = AssetDatabase.GUIDToAssetPath(fbxGuid);
|
|
// 检查设置
|
|
if (!_CheckModelImportSetting(fbxPath))
|
|
{
|
|
return;
|
|
}
|
|
// Debug.Log("fbxPath:" + fbxPath);
|
|
var fbx = AssetDatabase.LoadAssetAtPath<GameObject>(fbxPath);
|
|
_baseModelList.Add(fbx);
|
|
}
|
|
}
|
|
|
|
|
|
if (GUILayout.Button("创建角色"))
|
|
{
|
|
}
|
|
}
|
|
|
|
private bool _CheckModelImportSetting(string fbxPath)
|
|
{
|
|
// 先checkout资源
|
|
// VersionControlSystem.Checkout(fbxPath);
|
|
|
|
// 获取import
|
|
var importer = AssetImporter.GetAtPath(fbxPath) as ModelImporter;
|
|
if (importer == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var hasChanged = false;
|
|
// 确保Animation Type为Generic
|
|
if (importer.animationType != ModelImporterAnimationType.Generic)
|
|
{
|
|
importer.animationType = ModelImporterAnimationType.Generic;
|
|
hasChanged = true;
|
|
}
|
|
// Avatar Definition为Create From This Model
|
|
if (importer.avatarSetup != ModelImporterAvatarSetup.CreateFromThisModel)
|
|
{
|
|
importer.avatarSetup = ModelImporterAvatarSetup.CreateFromThisModel;
|
|
hasChanged = true;
|
|
}
|
|
// // Root node 为 对应的body
|
|
// var transPathList = importer.transformPaths;
|
|
// importer.motionNodeName = transPathList[0];
|
|
//
|
|
// importer.SaveAndReimport();
|
|
// AssetDatabase.Refresh();
|
|
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|