prefab 工具
parent
32ba10b0c8
commit
445f552aa9
|
|
@ -16,17 +16,17 @@ namespace Art.temp.Editor.CharacterData
|
|||
{
|
||||
case 'A':
|
||||
{
|
||||
PlayerInformation player = new(nameId);
|
||||
var player = CharacterFactory.CreatePlayer(nameId);
|
||||
return player.DisplayPrefab;
|
||||
}
|
||||
case 'E':
|
||||
{
|
||||
EnemyInformation enemy = new(nameId);
|
||||
var enemy = CharacterFactory.CreateEmeny(nameId);
|
||||
return enemy.DisplayPrefab;
|
||||
}
|
||||
case 'N':
|
||||
{
|
||||
NpcInformation npc = new(nameId);
|
||||
var npc = CharacterFactory.CreateNpc(nameId);
|
||||
return npc.DisplayPrefab;
|
||||
}
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -53,12 +53,13 @@ namespace Art.temp.Editor.PlayerBrowser
|
|||
foreach (Person person in source)
|
||||
{
|
||||
string personId = person.id;
|
||||
PlayerInformation player0 = new(personId);
|
||||
var player0 = CharacterFactory.CreatePlayer(personId);
|
||||
|
||||
char[] chars = personId.ToCharArray();
|
||||
chars[personId.Length - 4] = '1';
|
||||
var nameId = new string(chars);
|
||||
PlayerInformation player1 = new(nameId);
|
||||
var player1 = CharacterFactory.CreatePlayer(nameId);
|
||||
|
||||
|
||||
var row = new VisualElement() { name = "row" };
|
||||
row.Add(new Label(personId));
|
||||
|
|
@ -84,11 +85,11 @@ namespace Art.temp.Editor.PlayerBrowser
|
|||
private static bool IsDone(Person person)
|
||||
{
|
||||
var personId = person.id;
|
||||
PlayerInformation player0 = new(personId);
|
||||
var player0 = CharacterFactory.CreatePlayer(personId);
|
||||
char[] chars = personId.ToCharArray();
|
||||
chars[personId.Length - 4] = '1';
|
||||
var nameId = new string(chars);
|
||||
PlayerInformation player1 = new(nameId);
|
||||
var player1 = CharacterFactory.CreatePlayer(nameId);
|
||||
if (ErrorMsg(player0.Model, person.model_0) != "")
|
||||
{
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -46,8 +46,8 @@ namespace Art.temp.Editor.PlayerBrowser
|
|||
chars[personId.Length - 4] = '1';
|
||||
string nameId = new(chars);
|
||||
|
||||
PlayerInformation player1 = new(personId);
|
||||
PlayerInformation player2 = new(nameId);
|
||||
var player1 = CharacterFactory.CreatePlayer(personId);
|
||||
var player2 = CharacterFactory.CreatePlayer(nameId);
|
||||
if (player1.AutoPrefab)
|
||||
{
|
||||
((Label)item).style.color = Color.green;
|
||||
|
|
@ -89,7 +89,7 @@ namespace Art.temp.Editor.PlayerBrowser
|
|||
|
||||
private static void CreateVe(VisualElement pane, string nameId)
|
||||
{
|
||||
PlayerInformation player = new(nameId);
|
||||
var player = CharacterFactory.CreatePlayer(nameId);
|
||||
|
||||
pane.Add(new Label("资源完成度"));
|
||||
pane.Add(new ObjectField("模型") { value = player.Model });
|
||||
|
|
|
|||
|
|
@ -4,19 +4,22 @@ using Art.temp.Editor.CharacterData;
|
|||
using MagicaCloth2;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
// ReSharper disable IdentifierTypo
|
||||
|
||||
namespace Art.temp.Editor.PrefabTool
|
||||
{
|
||||
public abstract class CharacterInfo
|
||||
public class CharacterInfo
|
||||
{
|
||||
private readonly string nameId;
|
||||
private readonly string personId;
|
||||
private readonly string folderId;
|
||||
private readonly string category;
|
||||
|
||||
protected CharacterInfo(string nameId)
|
||||
public CharacterInfo(string nameId, string category)
|
||||
{
|
||||
this.nameId = nameId; // AA01001
|
||||
this.category = category;
|
||||
char[] chars = nameId.ToCharArray();
|
||||
chars[nameId.Length - 4] = '0';
|
||||
personId = new string(chars);
|
||||
|
|
@ -24,7 +27,10 @@ namespace Art.temp.Editor.PrefabTool
|
|||
}
|
||||
|
||||
private const string Head = "Root/Bip001/Bip001 Spine/Bip001 Spine1/Bip001 Neck/Bip001 Head/";
|
||||
private const string Grip01 = "Root/Bip001/Bip001 Spine/Bip001 Spine1/Bip001 R Clavicle/Bip001 R UpperArm/Bip001 R Forearm/Bip001 R Hand/Grip_point01/";
|
||||
|
||||
private const string Grip01 =
|
||||
"Root/Bip001/Bip001 Spine/Bip001 Spine1/Bip001 R Clavicle/Bip001 R UpperArm/Bip001 R Forearm/Bip001 R Hand/Grip_point01/";
|
||||
|
||||
private const string Mount01 = "Root/Bip001/Bip001 Spine/Mount_point01/";
|
||||
|
||||
private const string AnimPath = "Assets/Art/Animations/Battle/Skill/ani_{0}_skill01.fbx";
|
||||
|
|
@ -34,16 +40,31 @@ namespace Art.temp.Editor.PrefabTool
|
|||
private const string DisplayPath = "Assets/Art/Character/Prefabs/{0}_S/P_S_{1}.prefab";
|
||||
|
||||
private Person Config => JsonData.GetPersons().FirstOrDefault(a => a.id == personId);
|
||||
protected abstract string Category { get; }
|
||||
public GameObject Model => AssetDatabase.LoadAssetAtPath<GameObject>(string.Format(ModelPath, Category, folderId, nameId));
|
||||
public GameObject Prefab => AssetDatabase.LoadAssetAtPath<GameObject>(string.Format(PrefabPath, Category, nameId));
|
||||
public GameObject DisplayPrefab => AssetDatabase.LoadAssetAtPath<GameObject>(string.Format(DisplayPath, Category, nameId));
|
||||
public GameObject AutoPrefab => AssetDatabase.LoadAssetAtPath<GameObject>(string.Format(AutoPath, nameId, Config.weapon));
|
||||
|
||||
|
||||
public GameObject Model =>
|
||||
AssetDatabase.LoadAssetAtPath<GameObject>(string.Format(ModelPath, category, folderId, nameId));
|
||||
|
||||
public GameObject Prefab =>
|
||||
AssetDatabase.LoadAssetAtPath<GameObject>(string.Format(PrefabPath, category, nameId));
|
||||
|
||||
public GameObject DisplayPrefab =>
|
||||
AssetDatabase.LoadAssetAtPath<GameObject>(string.Format(DisplayPath, category, nameId));
|
||||
|
||||
public GameObject AutoPrefab =>
|
||||
AssetDatabase.LoadAssetAtPath<GameObject>(string.Format(AutoPath, nameId, Config.weapon));
|
||||
|
||||
public Object Skill => AssetDatabase.LoadAssetAtPath<Object>(string.Format(AnimPath, personId));
|
||||
|
||||
// rebuild prefab and display prefab
|
||||
public void Rebuild()
|
||||
{
|
||||
if (Model == null)
|
||||
{
|
||||
Debug.LogWarning("基础信息不正确,找不到模型文件");
|
||||
return;
|
||||
}
|
||||
|
||||
// preset model
|
||||
var objPath = AssetDatabase.GetAssetPath(Model);
|
||||
var modelImporter = AssetImporter.GetAtPath(objPath) as ModelImporter;
|
||||
|
|
@ -60,7 +81,8 @@ namespace Art.temp.Editor.PrefabTool
|
|||
|
||||
// Add emoji
|
||||
Transform head = objInstance.transform.Find(Head);
|
||||
GameObject emoji = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Art/Character/Models/Emoji/G_emoji.FBX");
|
||||
GameObject emoji =
|
||||
AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Art/Character/Models/Emoji/G_emoji.FBX");
|
||||
GameObject emojiInstance = (GameObject)PrefabUtility.InstantiatePrefab(emoji);
|
||||
emojiInstance.transform.parent = head;
|
||||
|
||||
|
|
@ -78,11 +100,12 @@ namespace Art.temp.Editor.PrefabTool
|
|||
{
|
||||
GunInfo gun = new("G" + Config.weapon.PadLeft(5, '0'));
|
||||
Transform grip = objInstance.transform.Find(Grip01);
|
||||
if(grip == null)
|
||||
if (grip == null)
|
||||
{
|
||||
Debug.LogError("没有武器挂点,终止");
|
||||
return;
|
||||
}
|
||||
|
||||
PrefabUtility.InstantiatePrefab(gun.Prefab, grip);
|
||||
}
|
||||
else
|
||||
|
|
@ -105,7 +128,8 @@ namespace Art.temp.Editor.PrefabTool
|
|||
if (Config.aniSet != "")
|
||||
{
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
string acPath = $"Assets/Art/Animations/animator/display_ovrride_{Config.aniSet}.overrideController";
|
||||
string acPath =
|
||||
$"Assets/Art/Animations/animator/display_ovrride_{Config.aniSet}.overrideController";
|
||||
// config animator controller
|
||||
Animator animator = objInstance.GetComponent<Animator>();
|
||||
var controller = AssetDatabase.LoadAssetAtPath<RuntimeAnimatorController>(acPath);
|
||||
|
|
@ -124,13 +148,14 @@ namespace Art.temp.Editor.PrefabTool
|
|||
}
|
||||
}
|
||||
|
||||
string displayPath = string.Format(DisplayPath, Category, nameId);
|
||||
string prefabPath = string.Format(PrefabPath, Category, nameId);
|
||||
string displayPath = string.Format(DisplayPath, category, nameId);
|
||||
string prefabPath = string.Format(PrefabPath, category, nameId);
|
||||
PrefabUtility.SaveAsPrefabAssetAndConnect(prefab, displayPath, InteractionMode.AutomatedAction);
|
||||
PrefabUtility.SaveAsPrefabAsset(prefab, prefabPath);
|
||||
Debug.Log(displayPath);
|
||||
Debug.Log(prefab);
|
||||
}
|
||||
|
||||
// ReSharper disable once IdentifierTypo
|
||||
private static void AddMagicaCloth(GameObject go)
|
||||
{
|
||||
|
|
@ -187,25 +212,11 @@ namespace Art.temp.Editor.PrefabTool
|
|||
}
|
||||
}
|
||||
|
||||
public class PlayerInformation : CharacterInfo
|
||||
|
||||
public static class CharacterFactory
|
||||
{
|
||||
public PlayerInformation(string nameId) : base(nameId) { }
|
||||
|
||||
protected override string Category => "Players";
|
||||
public static CharacterInfo CreatePlayer(string nameId) => new CharacterInfo(nameId, "Players");
|
||||
public static CharacterInfo CreateNpc(string nameId) => new CharacterInfo(nameId, "Npc");
|
||||
public static CharacterInfo CreateEmeny(string nameId) => new CharacterInfo(nameId, "Enemy");
|
||||
}
|
||||
|
||||
|
||||
public class EnemyInformation : CharacterInfo
|
||||
{
|
||||
public EnemyInformation(string nameId) : base(nameId) { }
|
||||
|
||||
protected override string Category => "Enemy";
|
||||
}
|
||||
|
||||
public class NpcInformation : CharacterInfo
|
||||
{
|
||||
public NpcInformation(string nameId) : base(nameId) { }
|
||||
|
||||
protected override string Category => "Npc";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -83,18 +83,15 @@ namespace Art.temp.Editor.PrefabTool
|
|||
|
||||
else if (id.StartsWith("A"))
|
||||
{
|
||||
PlayerInformation player = new(id);
|
||||
player.Rebuild();
|
||||
CharacterFactory.CreatePlayer(id).Rebuild();
|
||||
}
|
||||
else if (id.StartsWith("E"))
|
||||
{
|
||||
EnemyInformation enemy = new(id);
|
||||
enemy.Rebuild();
|
||||
CharacterFactory.CreateEmeny(id).Rebuild();
|
||||
}
|
||||
else if (id.StartsWith("N"))
|
||||
{
|
||||
NpcInformation npc = new(id);
|
||||
npc.Rebuild();
|
||||
CharacterFactory.CreateNpc(id).Rebuild();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue