public static Material GetMaterial(Shader shader, UIEffect.ToneMode tone, UIEffect.ColorMode color, UIEffect.BlurMode blur) { string variantName = Path.GetFileName(shader.name) + (0 < tone ? "-" + tone : "") + (0 < color ? "-" + color : "") + (0 < blur ? "-" + blur : ""); var path = AssetDatabase.FindAssets("t:Material " + variantName) .Select(x => AssetDatabase.GUIDToAssetPath(x)) .SingleOrDefault(x => Path.GetFileNameWithoutExtension(x) == variantName); return(path != null ? AssetDatabase.LoadAssetAtPath <Material>(path) : null); }
public static Material GetOrCreateMaterial(Shader shader, UIEffect.ToneMode tone, UIEffect.ColorMode color, UIEffect.BlurMode blur) { Material mat = UIEffect.GetMaterial(shader, tone, color, blur); if (!mat) { mat = new Material(shader); if (0 < tone) { mat.EnableKeyword("UI_TONE_" + tone.ToString().ToUpper()); } if (0 < color) { mat.EnableKeyword("UI_COLOR_" + color.ToString().ToUpper()); } if (0 < blur) { mat.EnableKeyword("UI_BLUR_" + blur.ToString().ToUpper()); } mat.name = Path.GetFileName(shader.name) + (0 < tone ? "-" + tone : "") + (0 < color ? "-" + color : "") + (0 < blur ? "-" + blur : ""); //mat.hideFlags = HideFlags.NotEditable; Directory.CreateDirectory("Assets/UIEffect/Materials"); AssetDatabase.CreateAsset(mat, "Assets/UIEffect/Materials/" + mat.name + ".mat"); } return(mat); }