42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class FbxTextureExtractor : MonoBehaviour
|
|
{
|
|
public string fbxFolder = "Assets/GameAssets/Models/»ú¹ñÄÚÉ豸/°å¿¨";
|
|
public string textureFolder = "Assets/Textures_/";
|
|
|
|
void Start()
|
|
{
|
|
UnpackTextures();
|
|
}
|
|
|
|
|
|
[ContextMenu("-------")]
|
|
void UnpackTextures()
|
|
{
|
|
string[] fbxFiles = Directory.GetFiles(fbxFolder, "*.fbx");
|
|
foreach (string fbxFile in fbxFiles)
|
|
{
|
|
string fbxPath = fbxFile.Replace(Application.dataPath, "Assets");
|
|
Object fbxPrefab = AssetDatabase.LoadMainAssetAtPath(fbxPath);
|
|
Object[] dependencies = EditorUtility.CollectDependencies(new Object[] { fbxPrefab });
|
|
foreach (Object obj in dependencies)
|
|
{
|
|
if (obj is Texture2D)
|
|
{
|
|
string texturePath = AssetDatabase.GetAssetPath(obj);
|
|
string newTexturePath = textureFolder + obj.name + ".jpg";
|
|
if (File.Exists(newTexturePath))
|
|
{
|
|
FileUtil.DeleteFileOrDirectory(newTexturePath);
|
|
}
|
|
FileUtil.CopyFileOrDirectory(texturePath, newTexturePath);
|
|
AssetDatabase.ImportAsset(newTexturePath);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|