赞
踩
1.功能描述
a.可将fbx直接导出prefab。
b.同时为prefab预先按需挂载脚本文件。
c.同时为挂载的脚本设置参数,绑定资源等。
d.批量化处理,递归遍历算法,高效可扩展。
2.实现方式
a.Editor类
- using Lean.Touch;
- using Main;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Reflection;
- using UnityEditor;
- using UnityEngine;
- public enum SystemBody
- {
- [Description("Bones")]
- guge=1,
- [Description("Muscle")]
- jirou,
- [Description("Vein")]
- jingmai,
- [Description("Aetery")]
- dongmai,
- [Description("Bones")]
- neifenmi=5,
- [Description("Bones")]
- shenjing,
- [Description("Skin")]
- pifu,
- [Description("Lymph")]
- lingba,
- [Description("GenitourinrySelectable")]
- miniaoshengzhi,
- [Description("Respiratory")]
- xiaohua=10,
- [Description("Joint")]
- guanjie,
- [Description("Respiratory")]
- huxi,
- }
- public static class EnumExpand
- {
- public static T ToEnum<T>(this string str)
- {
- return (T)Enum.Parse(typeof(T), str);
- }
- }
-
- public class Fbx2Prefab : Editor
- {
-
- [MenuItem("Assets/Fbx2Prefab/Create GuGe Prefab")]
- public static void CreateGuGePre()
- {
- GameObject obj = Selection.gameObjects[0];
- GameObject pre = MonoBehaviour.Instantiate(obj);
- List<GameObject> prelist = new List<GameObject>();
- for (int i = 0; i < pre.transform.childCount; i++)
- {
- prelist.Add(pre.transform.GetChild(i).gameObject);
- }
- GameObjectTree tree = MonoBehaviour.FindObjectOfType<GameObjectTree>();
- tree.scriptObjs.Clear();
- tree.rootTransform = pre.transform;
- tree.scriptObjs.Add(MonoScript.FromScriptableObject(CreateInstance(typeof(BonesSelectable))));
- tree.scriptObjs.Add(MonoScript.FromScriptableObject(CreateInstance(typeof(LeanSelectableByFinger))));
- tree.AddMonoScript();
-
- var mts = Resources.FindObjectsOfTypeAll<Material>();//绑定材质球
- tree.SetCommponentValue<BonesSelectable>(mts.ToList().Find(p=>p.name== SystemBody.guge.ToString()));
-
- foreach (var item in prelist)
- {
- PrefabUtility.SaveAsPrefabAsset(item, $"Assets/Prefab/{item.name}.prefab");
- }
- DestroyImmediate(pre);
- }
- [MenuItem("Assets/Fbx2Prefab/Create Jirou Prefab")]
- public static void CreateJirouPre()
- {
- SystemBody body = SystemBody.jirou;
- CreateNormalPre(body);
- }
- [MenuItem("Assets/Fbx2Prefab/Create Normal Prefab")]
- public static void CreateNormalPre()
- {
- SystemBody body = SystemBody.jirou;
- string n = Selection.gameObjects[0]?.name;
- if (string.IsNullOrEmpty(n))
- {
- Debug.LogError("未选中");
- }
- else
- {
- body = n.ToLower().ToEnum<SystemBody>();
- }
- CreateNormalPre(body);
- }
- public static void CreateNormalPre(SystemBody body)
- {
- GameObject obj = Selection.gameObjects[0];
- GameObject pre = MonoBehaviour.Instantiate(obj);
- List<GameObject> prelist = new List<GameObject>();
- for (int i = 0; i < pre.transform.childCount; i++)
- {
- prelist.Add(pre.transform.GetChild(i).gameObject);
- }
- GameObjectTree tree = MonoBehaviour.FindObjectOfType<GameObjectTree>();
- tree.scriptObjs.Clear();
- tree.rootTransform = pre.transform;
- Type t = Assembly.Load("Unity.ModelView").GetType($"Main.{body.GetDescName()}Selectable");
- tree.scriptObjs.Add(MonoScript.FromScriptableObject(Cr
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。