198 lines
7.5 KiB
C#
198 lines
7.5 KiB
C#
using Art.temp.Editor.CharacterData;
|
|
using Framework;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace Art.temp.Editor.PrefabTool
|
|
{
|
|
public class PrefabBuilderWin : EditorWindow
|
|
{
|
|
[MenuItem("Tools/*角色工具/Prefab Builder")]
|
|
public static void ShowWindow()
|
|
{
|
|
GetWindow<PrefabBuilderWin>("Prefab Builder");
|
|
}
|
|
|
|
public void CreateGUI()
|
|
{
|
|
var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Art/temp/Editor/CommonUSSFile.uss");
|
|
rootVisualElement.styleSheets.Add(styleSheet);
|
|
Label label1 = new() { text = "Select fbx to build prefab" };
|
|
rootVisualElement.Add(label1);
|
|
|
|
Button btn1 = new() { text = "apply" };
|
|
rootVisualElement.Add(btn1);
|
|
btn1.RegisterCallback<ClickEvent>(_ => CreatePrefab());
|
|
|
|
|
|
Label label2 = new() { text = "select prefab" };
|
|
rootVisualElement.Add(label2);
|
|
|
|
Button btn3 = new() { text = "create auto battery" };
|
|
rootVisualElement.Add(btn3);
|
|
btn3.RegisterCallback<ClickEvent>(_ => CreateAutoBattery());
|
|
|
|
Button show = new() { text = "show game object" };
|
|
rootVisualElement.Add(show);
|
|
show.RegisterCallback<ClickEvent>(_ => ShowInScene());
|
|
|
|
Label label3 = new() { text = "create all prefabs by config" };
|
|
rootVisualElement.Add(label3);
|
|
|
|
Button btn2 = new() { text = "display vehicle" };
|
|
rootVisualElement.Add(btn2);
|
|
btn2.RegisterCallback<ClickEvent>(_ => CreateDisplayCar());
|
|
|
|
Button btn4 = new() { text = "battle story character" };
|
|
rootVisualElement.Add(btn4);
|
|
btn4.RegisterCallback<ClickEvent>(_ => CreateBattleCharacter());
|
|
|
|
/*Button test = new() { text = "combine skinned mesh" };
|
|
rootVisualElement.Add(test);
|
|
test.RegisterCallback<ClickEvent>(_ => Combine());*/
|
|
}
|
|
|
|
|
|
private static void CreatePrefab()
|
|
{
|
|
foreach (GameObject go in Selection.gameObjects)
|
|
{
|
|
string id = go.name;
|
|
if (id.StartsWith("B"))
|
|
{
|
|
BagInfo bag = new(id);
|
|
bag.Rebuild();
|
|
}
|
|
else if (id.StartsWith("G"))
|
|
{
|
|
GunInfo gun = new(id);
|
|
gun.Rebuild();
|
|
}
|
|
else if (id.StartsWith("R"))
|
|
{
|
|
AnimHelper.PreSetModel(go);
|
|
BatteryInfo battery = new(id);
|
|
battery.Rebuild();
|
|
}
|
|
else if (id.StartsWith("C"))
|
|
{
|
|
AnimHelper.PreSetModel(go);
|
|
VehicleInfo car = new(id);
|
|
car.Rebuild();
|
|
}
|
|
|
|
else if (id.StartsWith("A"))
|
|
{
|
|
CharacterFactory.CreatePlayer(id).Rebuild();
|
|
}
|
|
else if (id.StartsWith("E"))
|
|
{
|
|
CharacterFactory.CreateEmeny(id).Rebuild();
|
|
}
|
|
else if (id.StartsWith("N"))
|
|
{
|
|
CharacterFactory.CreateNpc(id).Rebuild();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("Invalid file name");
|
|
}
|
|
}
|
|
|
|
AssetDatabase.Refresh();
|
|
}
|
|
|
|
|
|
// 使用 json 配置生成载具 300001
|
|
private static void CreateDisplayCar()
|
|
{
|
|
Vehicle[] config = JsonData.GetVehicles();
|
|
foreach (Vehicle v in config)
|
|
{
|
|
if (string.IsNullOrEmpty(v.id) || string.IsNullOrEmpty(v.vehicleName) ||
|
|
string.IsNullOrEmpty(v.batteryName))
|
|
{
|
|
Debug.LogWarning($"{v.id}: 配置不全");
|
|
continue;
|
|
}
|
|
|
|
GameObject carAsset = AssetDatabase.LoadAssetAtPath<GameObject>(
|
|
$"Assets/Art/Character/Prefabs/Vehicle/{v.vehicleName}.prefab"); // P_C00001_01
|
|
GameObject batteryAsset = AssetDatabase.LoadAssetAtPath<GameObject>(
|
|
$"Assets/Art/Character/Prefabs/Battery/{v.batteryName}.prefab"); // P_R0001_01
|
|
if (carAsset == null || batteryAsset == null)
|
|
{
|
|
Debug.LogWarning($"{v.id}: 缺少底盘或炮台资源");
|
|
continue;
|
|
}
|
|
|
|
string nameId = v.vehicleName.Split('_')[1];
|
|
GameObject instance = (GameObject)PrefabUtility.InstantiatePrefab(carAsset);
|
|
Transform pointBattery =
|
|
instance.transform.GetChild(0).Find($"Root/G_{nameId}_bone001/Battery_point01");
|
|
if (pointBattery == null)
|
|
pointBattery = instance.transform.GetChild(0).Find("Root/cog/Battery_point01");
|
|
PrefabUtility.InstantiatePrefab(batteryAsset, pointBattery);
|
|
PrefabUtility.UnpackPrefabInstance(instance, PrefabUnpackMode.Completely,
|
|
InteractionMode.AutomatedAction);
|
|
|
|
string path = $"Assets/Art/Character/Prefabs/Vehicle_S/{v.id}.prefab";
|
|
PrefabUtility.SaveAsPrefabAssetAndConnect(instance, path, InteractionMode.AutomatedAction);
|
|
instance.name = v.id;
|
|
Debug.Log(path);
|
|
}
|
|
}
|
|
|
|
private static void CreateAutoBattery()
|
|
{
|
|
foreach (GameObject go in Selection.gameObjects)
|
|
{
|
|
string id = go.name.Split('_')[1];
|
|
if (!id.StartsWith("R"))
|
|
{
|
|
Debug.LogWarning("is not battery prefab");
|
|
return;
|
|
}
|
|
|
|
BatteryInfo battery = new(id);
|
|
battery.RebuildAuto();
|
|
}
|
|
}
|
|
|
|
// 战斗角色 由 player npc 等创建
|
|
private static void CreateBattleCharacter()
|
|
{
|
|
var battleCharacterData = EditorTableManager.instance.tables.FightNPCConfig.DataList;
|
|
foreach (var battleCharacter in battleCharacterData)
|
|
{
|
|
string id = battleCharacter.NameId;
|
|
string modelNameId = battleCharacter.NameRead.Split("_")[0];
|
|
if (id.StartsWith("BN"))
|
|
{
|
|
// 找到 display prefab 角色
|
|
GameObject oldPrefab = AnimHelper.FindDisplayPrefab(modelNameId);
|
|
GameObject prefab = (GameObject)PrefabUtility.InstantiatePrefab(oldPrefab);
|
|
// 重命名
|
|
prefab.name = "P_" + id;
|
|
// 保存 prefab
|
|
PrefabUtility.UnpackPrefabInstance(prefab, PrefabUnpackMode.OutermostRoot,
|
|
InteractionMode.AutomatedAction);
|
|
string path = $"Assets/Art/Character/Prefabs/Npc/{prefab.name}.prefab";
|
|
PrefabUtility.SaveAsPrefabAssetAndConnect(prefab, path, InteractionMode.AutomatedAction);
|
|
Debug.Log($"创建战斗剧情角色:{prefab}");
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void ShowInScene()
|
|
{
|
|
var objects = Selection.gameObjects;
|
|
for (int i = 0; i < objects.Length; i++)
|
|
{
|
|
GameObject prefab = (GameObject)PrefabUtility.InstantiatePrefab(objects[i]);
|
|
prefab.transform.localPosition = new Vector3(-i, 0, 0);
|
|
}
|
|
}
|
|
}
|
|
} |