Created
November 4, 2021 20:41
-
-
Save LaserKaspar/4381cd10cd8c19383761718ecc667d15 to your computer and use it in GitHub Desktop.
(UnityEngine) Quickly create materials. Can be extended to work with other types of materials. (currently: Universal Render Pipeline/Lit)
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 System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEditor; | |
using UnityEngine; | |
public class MaterialHelper : EditorWindow | |
{ | |
public string path = "Materials/"; | |
public string materialName; | |
public Texture2D texture; | |
public Color color; | |
[MenuItem("Editor/MaterialHelper")] | |
static void Init() | |
{ | |
// Get existing open window or if none, make a new one: | |
MaterialHelper window = (MaterialHelper)EditorWindow.GetWindow(typeof(MaterialHelper)); | |
window.Show(); | |
} | |
private void OnGUI() | |
{ | |
path = EditorGUILayout.TextField("Path", path); | |
materialName = EditorGUILayout.TextField("Matname", materialName); | |
texture = (Texture2D)EditorGUILayout.ObjectField("Select Texture", | |
texture, | |
typeof(Texture2D)); | |
color = EditorGUILayout.ColorField("Select Color", color); | |
if (GUILayout.Button("Create new Material")) | |
{ | |
CreateMaterial(); | |
} | |
} | |
void CreateMaterial() { | |
// Create a simple material asset | |
Material material = new Material (Shader.Find("Universal Render Pipeline/Lit")); | |
material.SetTexture("_BaseMap", texture); | |
material.SetColor("_BaseColor", color); | |
AssetDatabase.CreateAsset(material, "Assets/" + path + materialName + ".mat"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment