效果很明显的模型优化插件
优化前:
优化后:
效果很明显,在需要合并的父物体上添加脚本SuperCombiner
如果需要转换为fbx模型,可以使用官方免费查件FbxExporters,但一定先把textrue给提取出来,保存在peoject目录中
提取textrue脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public class textrueWindows : EditorWindow {
GameObject Game;
string path;
string ttt;
string textruename;
// Use this for initialization
public static void ShowWindows () {
EditorWindow da = EditorWindow.GetWindow(typeof(textrueWindows));
da.Show();
}
private void OnGUI()
{
GUILayout.Space(20);
Game = (GameObject)EditorGUILayout.ObjectField("选择prefab资源对象", Game, typeof(GameObject), true);
GUILayout.Space(20);
EditorGUILayout.BeginHorizontal();
textruename= EditorGUILayout.TextField("输入名称",textruename, GUILayout.Height(20f));
EditorGUILayout.EndHorizontal();
GUILayout.Space(20);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.TextField("路劲获取", path, GUILayout.Height(20f));
if (GUILayout.Button("...", GUILayout.Height(20f)))
{
string xmlpath = EditorUtility.OpenFolderPanel("选择放入贴图的目录文件夹", Application.dataPath, "");
if (xmlpath != "")
{
path = xmlpath.Substring(xmlpath.LastIndexOf("Assets"));
ttt = xmlpath;
}
}
EditorGUILayout.EndHorizontal();
GUILayout.Space(20);
if (GUILayout.Button("确定"))
{
if (Game == null)
{
EditorUtility.DisplayDialog("无资源", "请选择Prefab资源对象", "OK");
return;
}
if (textruename=="")
{
EditorUtility.DisplayDialog("无名称", "填写名称", "OK");
return;
}
if (path =="")
{
EditorUtility.DisplayDialog("无路径", "选择路径", "OK");
return;
}
CreatTeture(Game);
}
}
private void CreatTeture(GameObject prefabGameObject)
{
MeshRenderer[] meshes = prefabGameObject.GetComponentsInChildren<MeshRenderer>();
if(meshes.Length>1)
{
EditorUtility.DisplayDialog("多个预资源", "请选择一个Prefab资源对象", "OK");
}
else
{
Texture2D duk = meshes[0].sharedMaterial.mainTexture as Texture2D ;
SaveTextureToPNG(duk, ttt, textruename);
AssetDatabase.Refresh();
meshes[0].sharedMaterial.mainTexture = AssetDatabase.LoadAssetAtPath<Texture>(path + "/" + textruename + ".png");
//AssetDatabase.CreateAsset(duk, path+"/"+ textruename+".png");
}
// AssetDatabase.Refresh();
// prefabGameObject.
}
public void SaveTextureToPNG(Texture2D inputTex,string contents, string pngName)
{
byte[] bytes = inputTex.EncodeToPNG();
File.WriteAllBytes(contents + "/"+ pngName+".png", bytes);
}
}
[MenuItem("Tools/贴图")]
public static void Stati()
{
textrueWindows.ShowWindows();
}
使用这个自带插件转换Fbx也很方便,点击Combine等待,保存目录里寻找