This repository has been archived on 2026-01-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
AW_2025/Assets/Editor/MaterialExtractor.cs
2025-02-24 15:18:12 +09:00

49 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public static class MaterialExtractor
{
[MenuItem("Tools/MaterialExtract #P")]
public static void MaterialExtract()
{
return;
//Debug.Log(Selection.activeObject);
GameObject select = Selection.activeGameObject;
var selectMeshs = select.GetComponentsInChildren<MeshRenderer>();
var basePath = $"{Application.dataPath}/MaterialExtract";
var dir = $"{basePath}/{select.name}";
if (Directory.Exists(dir)){
Directory.CreateDirectory(dir);
Debug.Log($"Create Directory({dir})");
}
foreach(var m in selectMeshs)
{
object material = m.sharedMaterial;
if (material == null)
{
Debug.Log($"Missing={m.gameObject.name}");
continue;
}
using (MemoryStream ms = new MemoryStream())
{
var bf = new BinaryFormatter();
bf.Serialize(ms, material);
var buffer = ms.ToArray();
foreach (var b in buffer)
{
Debug.Log(b.ToString());
}
}
//Debug.Log(AssetDatabase.GetAssetPath(m.material));
//Debug.Log(material.name);
}
}
}