thanks for letting me know
i wrote a small unity script that is crawling threw the textures of your project and crates a new material. it highly depends on how the assets and textures are named. so it wont work for everyone, but still. here it is:
using System.Collections;
using System.IO;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class MaterialImporter : MonoBehaviour
{
public string basecolor;
public string normal;
public string metallic;
private void Reset() {
Search();
}
public void Search() {
// Debug.Log("lets go!" + gameObject.name);
basecolor = null;
normal = null;
metallic = null;
string[] results;
results = AssetDatabase.FindAssets(gameObject.name);
foreach (string guid in results) {
// Debug.Log("testI: " + AssetDatabase.GUIDToAssetPath(guid));
}
foreach (string guidone in results) {
if (AssetDatabase.GUIDToAssetPath(guidone).Contains("basecolor")) {
if (basecolor == null) {
basecolor = AssetDatabase.GUIDToAssetPath(guidone);
Debug.Log("base: " + AssetDatabase.GUIDToAssetPath(guidone));
}
}
if (AssetDatabase.GUIDToAssetPath(guidone).Contains("normal")) {
// normal = guidone;
if (normal == null) {
normal = AssetDatabase.GUIDToAssetPath(guidone);
Debug.Log("normal: " + AssetDatabase.GUIDToAssetPath(guidone));
}
}
if (AssetDatabase.GUIDToAssetPath(guidone).Contains("metallic")) {
//metallic = guidone;
if (metallic == null) {
metallic = AssetDatabase.GUIDToAssetPath(guidone);
Debug.Log("metallic: " + AssetDatabase.GUIDToAssetPath(guidone));
}
}
}
Material material = new Material(Shader.Find("Standard"));
AssetDatabase.CreateAsset(material, "Assets/" + gameObject.name + ".mat");
var rend = gameObject.GetComponent<Renderer>();
TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(normal);
importer.textureType = TextureImporterType.NormalMap;
Texture2D basecl = (Texture2D)AssetDatabase.LoadAssetAtPath(basecolor, typeof(Texture2D));
Texture2D normalmap = (Texture2D)AssetDatabase.LoadAssetAtPath(normal, typeof(Texture2D));
Texture2D metall = (Texture2D)AssetDatabase.LoadAssetAtPath(metallic, typeof(Texture2D));
Material m = (Material)AssetDatabase.LoadAssetAtPath("Assets/" + gameObject.name + ".mat", typeof(Material));
m.SetTexture("_MainTex", basecl);
m.SetTexture("_BumpMap", normalmap);
m.SetTexture("_MetallicGlossMap", metall);
m.SetFloat("_Glossiness", 0);
m.SetFloat("_Metallic", 0);
m.SetFloat("_GlossMapScale", 0.5f);
rend.sharedMaterial = m;
Prefab();
}
public void Prefab() {
// and name it as the GameObject's name with the .Prefab format
string localPath = "Assets/Prefabs" + gameObject.name + ".prefab";
// Make sure the file name is unique, in case an existing Prefab has the same name.
localPath = AssetDatabase.GenerateUniqueAssetPath(localPath);
// Create the new Prefab.
PrefabUtility.SaveAsPrefabAssetAndConnect(gameObject, localPath, InteractionMode.UserAction);
// DestroyImmediate(gameObject);
}
}