unity3d SuperCombiner

效果很明显的模型优化插件

优化前:                                                                                       

优化后:

效果很明显,在需要合并的父物体上添加脚本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等待,保存目录里寻找

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值