mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-11 04:54:17 -05:00
52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using UniGLTF;
|
|
using UnityEditor;
|
|
|
|
|
|
namespace VRM
|
|
{
|
|
#if !VRM_STOP_ASSETPOSTPROCESSOR
|
|
public class vrmAssetPostprocessor : AssetPostprocessor
|
|
{
|
|
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
|
|
{
|
|
foreach (string path in importedAssets)
|
|
{
|
|
var ext = Path.GetExtension(path).ToLower();
|
|
if (ext == ".vrm")
|
|
{
|
|
ImportVrm(UnityPath.FromUnityPath(path));
|
|
}
|
|
}
|
|
}
|
|
|
|
static void ImportVrm(UnityPath path)
|
|
{
|
|
if (!path.IsUnderAssetsFolder)
|
|
{
|
|
throw new Exception();
|
|
}
|
|
var context = new VRMImporterContext();
|
|
context.ParseGlb(File.ReadAllBytes(path.FullPath));
|
|
|
|
var prefabPath = path.Parent.Child(path.FileNameWithoutExtension + ".prefab");
|
|
|
|
// save texture assets !
|
|
context.SaveTexturesAsPng(prefabPath);
|
|
|
|
EditorApplication.delayCall += () =>
|
|
{
|
|
//
|
|
// after textures imported
|
|
//
|
|
context.Load();
|
|
context.SaveAsAsset(prefabPath);
|
|
context.Destroy(false);
|
|
};
|
|
}
|
|
}
|
|
#endif
|
|
}
|