Created
March 3, 2015 21:15
-
-
Save mikelovesrobots/e526809506a17b4db65b to your computer and use it in GitHub Desktop.
Bulk Material Creator for Unity3d. Just select your textures, then select from the menu Assets > Bulk Material Creator, assign a shader and hit create. MIT License.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class BulkMaterialCreator : ScriptableWizard | |
{ | |
public Shader Shader; | |
[MenuItem("Assets/Bulk Material Creator")] | |
static void CreateWizard() { | |
ScriptableWizard.DisplayWizard("Bulk Material Creator",typeof(BulkMaterialCreator)); | |
} | |
void OnWizardUpdate() { | |
} | |
void OnWizardCreate() { | |
foreach (var obj in Selection.objects) { | |
if (obj.GetType() == typeof(Texture2D)) { | |
var texture = (Texture2D)obj; | |
var material = GenerateMaterial(texture); | |
var path = GetDirectory(obj) + "/" + material.name + ".mat"; | |
AssetDatabase.CreateAsset(material, path); | |
} | |
} | |
} | |
private Material GenerateMaterial(Texture2D texture) { | |
var material = new Material(Shader); | |
material.name = texture.name; | |
material.mainTexture = texture; | |
return material; | |
} | |
private string GetDirectory(Object obj) { | |
var path = AssetDatabase.GetAssetPath(obj); | |
if (path.Contains('/')) { | |
path = path.Substring(0, path.LastIndexOf('/')); | |
} | |
return path; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I modified this script to allow changing which property to apply the texture to and add a suffix to the material name
Useful for VRChat MatCap Lit shader using property
_MatCap