//test if the path to the presets has changed public void testPresetsChanged(MaterialProperty[] props) { MaterialProperty presetsProperty = ThryEditor.FindProperty(props, ThryEditor.PROPERTY_NAME_PRESETS_FILE); loadProperties(props); if (presetsProperty != null) { hasPresets = true; testPresetsChanged(presetsProperty); } else { hasPresets = false; } }
//test if the path to the presets has changed public void testPresetsChanged(MaterialProperty[] props) { MaterialProperty presetsProperty = ThryEditor.FindProperty(props, "shader_presets"); loadProperties(props); if (presetsProperty != null) { hasPresets = true; testPresetsChanged(presetsProperty); } else { hasPresets = false; } }
/// <summary> /// Set Material Property value or Renderqueue of current Editor. /// </summary> /// <param name="key">Property Name or "render_queue"</param> /// <param name="value"></param> public static void SetMaterialValue(string key, string value) { MaterialProperty p = ThryEditor.FindProperty(ThryEditor.currentlyDrawing.properties, key); Material[] materials = ThryEditor.currentlyDrawing.materials; if (p != null) { MaterialHelper.SetMaterialPropertyValue(p, materials, value); } else if (key == "render_queue") { int q = 0; if (int.TryParse(value, out q)) { foreach (Material m in materials) { m.renderQueue = q; } } } }
public void applyPreset(string presetName, MaterialProperty[] props, Material[] materials) { ThryEditor.addUndo("Apply preset: " + presetName); List <string[]> sets; if (presets.TryGetValue(presetName, out sets)) { foreach (string[] set in sets) { MaterialProperty p = ThryEditor.FindProperty(props, set[0]); if (p != null) { if (p.type == MaterialProperty.PropType.Texture) { string[] guids = AssetDatabase.FindAssets(set[1] + " t:Texture", null); if (guids.Length == 0) { Debug.Log("Couldn't find texture: " + set[1]); } else { string path = AssetDatabase.GUIDToAssetPath(guids[0]); Texture tex = (Texture)EditorGUIUtility.Load(path); foreach (Material m in materials) { m.SetTexture(Shader.PropertyToID(set[0]), tex); } } } else if (p.type == MaterialProperty.PropType.Float || p.type == MaterialProperty.PropType.Range) { float value; if (float.TryParse(set[1], out value)) { foreach (Material m in materials) { m.SetFloat(Shader.PropertyToID(set[0]), value); } } } else if (p.type == MaterialProperty.PropType.Vector) { string[] xyzw = set[1].Split(",".ToCharArray()); Vector4 vector = new Vector4(float.Parse(xyzw[0]), float.Parse(xyzw[1]), float.Parse(xyzw[2]), float.Parse(xyzw[3])); foreach (Material m in materials) { m.SetVector(Shader.PropertyToID(set[0]), vector); } } else if (p.type == MaterialProperty.PropType.Color) { Color col = Helper.stringToColor(set[1]); foreach (Material m in materials) { m.SetColor(Shader.PropertyToID(set[0]), col); } } } else if (set[0] == "render_queue") { int q = 0; Debug.Log(set[0] + "," + set[1]); if (int.TryParse(set[1], out q)) { foreach (Material m in materials) { m.renderQueue = q; } } } } } ThryEditor.loadValuesFromMaterial(); ThryEditor.repaint(); }
public void applyPreset(string presetName, MaterialProperty[] props, Material[] materials) { ThryEditor.addUndo(Locale.editor.Get("apply_preset") + ": " + presetName); List <string[]> sets; if (presets.TryGetValue(presetName, out sets)) { foreach (string[] set in sets) { MaterialProperty p = ThryEditor.FindProperty(props, set[0]); if (p != null) { if (p.type == MaterialProperty.PropType.Texture) { Texture tex = AssetDatabase.LoadAssetAtPath <Texture>(set[1]); if (tex != null) { foreach (Material m in materials) { m.SetTexture(Shader.PropertyToID(set[0]), tex); } } } else if (p.type == MaterialProperty.PropType.Float || p.type == MaterialProperty.PropType.Range) { float value; if (float.TryParse(set[1], out value)) { foreach (Material m in materials) { m.SetFloat(Shader.PropertyToID(set[0]), value); } } } else if (p.type == MaterialProperty.PropType.Vector) { string[] xyzw = set[1].Split(",".ToCharArray()); Vector4 vector = new Vector4(float.Parse(xyzw[0]), float.Parse(xyzw[1]), float.Parse(xyzw[2]), float.Parse(xyzw[3])); foreach (Material m in materials) { m.SetVector(Shader.PropertyToID(set[0]), vector); } } else if (p.type == MaterialProperty.PropType.Color) { Color col = Converter.stringToColor(set[1]); foreach (Material m in materials) { m.SetColor(Shader.PropertyToID(set[0]), col); } } } else if (set[0] == "render_queue") { int q = 0; Debug.Log(set[0] + "," + set[1]); if (int.TryParse(set[1], out q)) { foreach (Material m in materials) { m.renderQueue = q; } } } } } ThryEditor.loadValuesFromMaterial(); ThryEditor.repaint(); }