public void removePreset(string presetName) { removeFromPresetOptions(presetName); presets.Remove(presetName); savePresets(); ThryEditor.repaint(); }
private static void fixMaterials(List <Shader> shaders, List <string> importedShaderNames) { restoring_in_progress = true; StreamReader reader = new StreamReader(MATERIALS_BACKUP_FILE_PATH); string l; while ((l = reader.ReadLine()) != null) { if (l == "") { continue; } string[] materialData = l.Split(new string[] { ":" }, System.StringSplitOptions.None); Material material = AssetDatabase.LoadAssetAtPath <Material>(AssetDatabase.GUIDToAssetPath(materialData[0])); if (importedShaderNames.Contains(materialData[1])) { //Debug.Log("Restore this shader: " + materialData[1]); Shader shader = shaders[importedShaderNames.IndexOf(materialData[1])]; //Debug.Log("Shader: " + shader.name); material.shader = shader; material.renderQueue = int.Parse(materialData[2]); Helper.UpdateRenderQueue(material, shader); } } reader.Close(); restoring_in_progress = false; ThryEditor.repaint(); }
private void DiscardChanges() { prop.textureValue = privious_preview_texture; SetGradient(Helper.GetGradient(privious_preview_texture)); gradient_has_been_edited = false; ThryEditor.repaint(); }
public void Foldout(int xOffset, GUIContent content, ThryEditor gui) { var style = new GUIStyle("ShurikenModuleTitle"); style.font = new GUIStyle(EditorStyles.label).font; style.border = new RectOffset(15, 7, 4, 4); style.fixedHeight = 22; style.contentOffset = new Vector2(20f, -2f); style.margin.left = 30 * xOffset; var rect = GUILayoutUtility.GetRect(16f + 20f, 22f, style); DrawingData.lastGuiObjectRect = rect; GUI.Box(rect, content, style); var e = Event.current; var toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f); if (e.type == EventType.Repaint) { EditorStyles.foldout.Draw(toggleRect, false, false, getState(), false); } if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition) && !e.alt) { this.Toggle(); e.Use(); } }
private void UpdateGradientPreviewTexture() { data.preview_texture = Converter.GradientToTexture(data.gradient, textureSettings.width, textureSettings.height); textureSettings.ApplyModes(data.preview_texture); prop.textureValue = data.preview_texture; gradient_has_been_edited = true; ThryEditor.repaint(); }
public static void OnEditorRemove() { string dir_path = ThryEditor.GetThryEditorDirectoryPath() + "/thry_modules"; if (Directory.Exists(dir_path)) { TrashHandler.MoveDirectoryToTrash(dir_path); } }
public static void DrawLocaleSelection(GUIContent label, string[] locales, int selected) { EditorGUI.BeginChangeCheck(); selected = EditorGUILayout.Popup(label.text, selected, locales); if (EditorGUI.EndChangeCheck()) { ThryEditor.currentlyDrawing.propertyDictionary[ThryEditor.PROPERTY_NAME_LOCALE].materialProperty.floatValue = selected; ThryEditor.reload(); } }
private static string GetThryModulesDirectoryPath() { string editor_path = ThryEditor.GetThryEditorDirectoryPath(); if (editor_path == null) { editor_path = "Assets"; } return(editor_path + "/thry_modules"); }
static OnCompileHandler() { //Init Editor Variables with paths ThryEditor.GetThryEditorDirectoryPath(); VRCInterface.OnCompile(); Config.OnCompile(); ModuleHandler.OnCompile(); TrashHandler.EmptyThryTrash(); UnityFixer.CheckAPICompatibility(); //check that Net_2.0 is ApiLevel UnityFixer.CheckDrawingDll(); //check that drawing.dll is imported }
private static bool CheckForEditorRemove(string[] assets) { string test_for = ThryEditor.GetThryEditorDirectoryPath() + "/Editor/ThryEditor.cs"; foreach (string p in assets) { if (p == test_for) { return(true); } } return(false); }
public void Foldout(int xOffset, GUIContent content, ThryEditor gui) { var style = new GUIStyle(Styles.Get().dropDownHeader); style.margin.left = 30 * xOffset; var rect = GUILayoutUtility.GetRect(16f + 20f, 22f, style); DrawingData.lastGuiObjectRect = rect; //rect with text GUI.Box(rect, content, style); PropertyOptions options = ThryEditor.currentlyDrawing.currentProperty.options; if (options.button_right != null && options.button_right.condition_show.Test()) { Rect buttonRect = new Rect(rect); GUIContent buttoncontent = new GUIContent(options.button_right.text, options.button_right.hover); float width = Styles.Get().dropDownHeaderButton.CalcSize(buttoncontent).x; width = width < rect.width / 3 ? rect.width / 3 : width; buttonRect.x += buttonRect.width - width - 10; buttonRect.y += 2; buttonRect.width = width; if (GUI.Button(buttonRect, buttoncontent, Styles.Get().dropDownHeaderButton)) { if (options.button_right.action != null) { options.button_right.action.Perform(); } } EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Link); } var e = Event.current; var toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f); if (e.type == EventType.Repaint) { //small arrow EditorStyles.foldout.Draw(toggleRect, false, false, getState(), false); } if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition) && !e.alt) { this.Toggle(); e.Use(); } }
//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; } }
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) { MaterialHelper.SetMaterialValue(set[0], set[1]); } } ThryEditor.loadValuesFromMaterial(); ThryEditor.repaint(); }
//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; } }
private static void Toggle(string configField, string label, string hover, GUIStyle label_style = null) { Config config = Config.Get(); System.Reflection.FieldInfo field = typeof(Config).GetField(configField); if (field != null) { bool value = (bool)field.GetValue(config); if (Toggle(value, label, hover, label_style) != value) { field.SetValue(config, !value); config.save(); ThryEditor.repaint(); } } }
public void Foldout(int xOffset, GUIContent content, ThryEditor gui) { PropertyOptions options = ThryEditor.currentlyDrawing.currentProperty.options; Event e = Event.current; GUIStyle style = new GUIStyle(Styles.dropDownHeader); style.margin.left = 15 * xOffset + 15; Rect rect = GUILayoutUtility.GetRect(16f + 20f, 22f, style); DrawingData.lastGuiObjectHeaderRect = rect; DrawBoxAndContent(rect, e, content, options, style); DrawSmallArrow(rect, e); HandleToggleInput(e, rect); }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { importedShaderPaths.Clear(); foreach (string str in importedAssets) { if (scriptImportedAssetPaths.Contains(str)) { scriptImportedAssetPaths.Remove(str); continue; } //if (allShaderPaths.Contains(str)) continue; //else allShaderPaths.Add(str); Object asset = AssetDatabase.LoadAssetAtPath <Object>(str); if (asset != null && asset.GetType() == typeof(Shader)) { Shader shader = AssetDatabase.LoadAssetAtPath <Shader>(str); importedShaderPaths.Add(str); deleteQueueShaders(shader, str); } else if (asset != null && str.ToLower().Contains("ThryEditor")) { ThryEditor.reload(); } } if (importedShaderPaths.Count == 0) { return; } if (ignore) { return; } if (!Config.Get().showImportPopup) { return; } EditorWindow window = Helper.FindEditorWindow(typeof(ShaderImportFixerGui)); if (window == null) { window = EditorWindow.CreateInstance <ShaderImportFixerGui>(); } window.Show(); }
private static void InstallModule(string url, string name) { EditorUtility.DisplayProgressBar(name + " download progress", "", 0); WebHelper.DownloadStringASync(url, delegate(string s) { if (s.StartsWith("404")) { Debug.LogWarning(s); return; } //Debug.Log(s); ModuleInfo module_info = Parser.ParseToObject <ModuleInfo>(s); string thry_modules_path = ThryEditor.GetThryEditorDirectoryPath(); string temp_path = "temp_" + name; if (thry_modules_path == null) { thry_modules_path = "Assets"; } thry_modules_path += "/thry_modules"; string install_path = thry_modules_path + "/" + name; string base_url = url.RemoveFileName(); FileHelper.WriteStringToFile(s, temp_path + "/module.json"); int i = 0; foreach (string f in module_info.files) { //Debug.Log(base_url + f); WebHelper.DownloadFileASync(base_url + f, temp_path + "/" + f, delegate(string data) { i++; EditorUtility.DisplayProgressBar("Downloading files for " + name, "Downloaded " + base_url + f, (float)i / module_info.files.Count); if (i == module_info.files.Count) { EditorUtility.ClearProgressBar(); if (!Directory.Exists(thry_modules_path)) { Directory.CreateDirectory(thry_modules_path); } Directory.Move(temp_path, install_path); AssetDatabase.Refresh(); } }); } }); }
private static void LocaleDropdown() { EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent(Locale.editor.Get("locale"), Locale.editor.Get("locale_tooltip")), GUILayout.ExpandWidth(false)); Locale.editor.selected_locale_index = EditorGUILayout.Popup(Locale.editor.selected_locale_index, Locale.editor.available_locales, GUILayout.ExpandWidth(false)); if (Locale.editor.Get("translator").Length > 0) { GUILayout.Label(Locale.editor.Get("translation") + ": " + Locale.editor.Get("translator"), GUILayout.ExpandWidth(false)); } EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { Config.Get().locale = Locale.editor.available_locales[Locale.editor.selected_locale_index]; Config.Get().save(); ThryEditor.reload(); ThryEditor.repaint(); } }
/// <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; } } } }
private static void Dropdown(string configField, string label, string hover, GUIStyle label_style = null) { Config config = Config.Get(); System.Reflection.FieldInfo field = typeof(Config).GetField(configField); if (field != null) { Enum value = (Enum)field.GetValue(config); EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(57); GUILayout.Label(new GUIContent(label, hover), GUILayout.ExpandWidth(false)); value = EditorGUILayout.EnumPopup(value, GUILayout.ExpandWidth(false)); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { field.SetValue(config, value); config.save(); ThryEditor.repaint(); } } }
public static void restoreAllMaterials() { if (!File.Exists(MATERIALS_BACKUP_FILE_PATH)) { backupAllMaterials(); return; } StreamReader reader = new StreamReader(MATERIALS_BACKUP_FILE_PATH); string l; while ((l = reader.ReadLine()) != null) { string[] materialData = l.Split(new string[] { ":" }, System.StringSplitOptions.None); Material material = AssetDatabase.LoadAssetAtPath <Material>(AssetDatabase.GUIDToAssetPath(materialData[0])); Shader shader = Shader.Find(materialData[1]); material.shader = shader; material.renderQueue = int.Parse(materialData[2]); Helper.UpdateRenderQueue(material, shader); } ThryEditor.repaint(); reader.Close(); }
private void TextureToGradient(ref GradientData data) { Debug.Log("Texture converted to gradient."); int d = (int)Mathf.Sqrt(Mathf.Pow(data.texture.width, 2) + Mathf.Pow(data.texture.height, 2)); List <GradientColorKey> colorKeys = new List <GradientColorKey>(); List <GradientAlphaKey> alphaKeys = new List <GradientAlphaKey>(); colorKeys.Add(new GradientColorKey(data.texture.GetPixel(data.texture.width - 1, data.texture.height - 1), 1)); alphaKeys.Add(new GradientAlphaKey(data.texture.GetPixel(data.texture.width - 1, data.texture.height - 1).a, 1)); colorKeys.Add(new GradientColorKey(data.texture.GetPixel(0, 0), 0)); alphaKeys.Add(new GradientAlphaKey(data.texture.GetPixel(0, 0).a, 0)); int colKeys = 0; int alphaKeysCount = 0; bool isFlat = false; bool isNotFlat = false; float[][] prevSteps = new float[][] { GetSteps(GetColorAtI(ref data, 0, d), GetColorAtI(ref data, 1, d)), GetSteps(GetColorAtI(ref data, 0, d), GetColorAtI(ref data, 1, d)) }; bool wasFlat = false; int maxBetweenFlats = 3; int minFlat = 3; int flats = 0; int prevFlats = 0; int nonFlats = 0; float[][] steps = new float[d][]; float[] alphaStep = new float[d]; Color prevColor = GetColorAtI(ref data, 0, d); for (int i = 0; i < d; i++) { Color col = GetColorAtI(ref data, i, d); steps[i] = GetSteps(prevColor, col); alphaStep[i] = Mathf.Abs(prevColor.a - col.a); prevColor = col; } for (int r = 0; r < 1; r++) { for (int i = 1; i < d - 1; i++) { //Debug.Log(i+": "+steps[i][0] + "," + steps[i][1] + ","+steps[i][0]); bool returnToOldVal = false; if (!SameSteps(steps[i], steps[i + 1]) && SimilarSteps(steps[i], steps[i + 1], 0.1f)) { int n = i; while (++n < d && SimilarSteps(steps[i - 1], steps[n], 0.1f)) { if (SameSteps(steps[i - 1], steps[n])) { returnToOldVal = true; } } } if (returnToOldVal) { steps[i] = steps[i - 1]; } returnToOldVal = false; //Debug.Log(i + ": " + steps[i][0] + "," + steps[i][1] + "," + steps[i][0]); } } Color lastStableColor = GetColorAtI(ref data, 0, d); float lastStableTime = 0; bool added = false; for (int i = 1; i < d; i++) { Color col = GetColorAtI(ref data, i, d); float[] newColSteps = steps[i]; float time = (float)(i) / d; float[] diff = new float[] { prevSteps[0][0] - newColSteps[0], prevSteps[0][1] - newColSteps[1], prevSteps[0][2] - newColSteps[2] }; if (diff[0] == 0 && diff[1] == 0 && diff[2] == 0) { lastStableColor = col; lastStableTime = time; added = false; } else { if (added == false && colKeys++ < 6) { colorKeys.Add(new GradientColorKey(lastStableColor, lastStableTime)); } added = true; } float alphaDiff = Mathf.Abs(alphaStep[i - 1] - alphaStep[i]); if (alphaDiff > 0.05 && ++alphaKeysCount < 6) { alphaKeys.Add(new GradientAlphaKey(col.a, time)); } prevSteps[1] = prevSteps[0]; prevSteps[0] = newColSteps; bool thisOneFlat = newColSteps[0] == 0 && newColSteps[1] == 0 && newColSteps[2] == 0; if (thisOneFlat) { flats++; } else if (!wasFlat && !thisOneFlat) { nonFlats++; } else if (wasFlat && !thisOneFlat) { prevFlats = flats; flats = 0; nonFlats = 1; } if (flats >= minFlat && prevFlats >= minFlat && nonFlats <= maxBetweenFlats) { isFlat = true; } if (nonFlats > maxBetweenFlats) { isNotFlat = true; } wasFlat = thisOneFlat; } data.gradientObj.gradient.SetKeys(colorKeys.ToArray(), alphaKeys.ToArray()); if (isFlat && !isNotFlat) { data.gradientObj.gradient.mode = GradientMode.Fixed; } data.serializedGradient = new SerializedObject(data.gradientObj); data.colorGradient = data.serializedGradient.FindProperty("gradient"); ThryEditor.repaint(); }
public static void drawStylizedBigTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties, bool skip_drag_and_drop_handling = false) { position.x += (EditorGUI.indentLevel) * 15; position.width -= (EditorGUI.indentLevel) * 15; Rect rect = GUILayoutUtility.GetRect(label, Styles.bigTextureStyle); rect.x += (EditorGUI.indentLevel) * 15; rect.width -= (EditorGUI.indentLevel) * 15; Rect border = new Rect(rect); border.position = new Vector2(border.x, border.y - position.height); border.height += position.height; if (DrawingData.currentTexProperty.reference_properties_exist) { border.height += 8; foreach (string r_property in DrawingData.currentTexProperty.options.reference_properties) { border.height += editor.GetPropertyHeight(ThryEditor.currentlyDrawing.propertyDictionary[r_property].materialProperty); } } //background GUI.DrawTexture(border, Styles.rounded_texture, ScaleMode.StretchToFill, true); Rect quad = new Rect(border); quad.width = quad.height / 2; GUI.DrawTextureWithTexCoords(quad, Styles.rounded_texture, new Rect(0, 0, 0.5f, 1), true); quad.x += border.width - quad.width; GUI.DrawTextureWithTexCoords(quad, Styles.rounded_texture, new Rect(0.5f, 0, 0.5f, 1), true); quad.width = border.height - 4; quad.height = quad.width; quad.x = border.x + border.width - quad.width - 1; quad.y += 2; Rect preview_rect_border = new Rect(position); preview_rect_border.height = rect.height + position.height - 6; preview_rect_border.width = preview_rect_border.height; preview_rect_border.y += 3; preview_rect_border.x += position.width - preview_rect_border.width - 3; Rect preview_rect = new Rect(preview_rect_border); preview_rect.height -= 6; preview_rect.width -= 6; preview_rect.x += 3; preview_rect.y += 3; if (prop.hasMixedValue) { Rect mixedRect = new Rect(preview_rect); mixedRect.y -= 5; mixedRect.x += mixedRect.width / 2 - 4; GUI.Label(mixedRect, "_"); } else if (prop.textureValue != null) { GUI.DrawTexture(preview_rect, prop.textureValue); } GUI.DrawTexture(preview_rect_border, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 0, Color.grey, 3, 5); //selection button and pinging Rect select_rect = new Rect(preview_rect); select_rect.height = 12; select_rect.y += preview_rect.height - 12; if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == texturePickerWindow && texturePickerWindowProperty == prop) { prop.textureValue = (Texture)EditorGUIUtility.GetObjectPickerObject(); ThryEditor.repaint(); } if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == texturePickerWindow) { texturePickerWindow = -1; texturePickerWindowProperty = null; } if (GUI.Button(select_rect, "Select", EditorStyles.miniButton)) { EditorGUIUtility.ShowObjectPicker <Texture>(prop.textureValue, false, "", 0); texturePickerWindow = EditorGUIUtility.GetObjectPickerControlID(); texturePickerWindowProperty = prop; } else if (Event.current.type == EventType.MouseDown && preview_rect.Contains(Event.current.mousePosition)) { EditorGUIUtility.PingObject(prop.textureValue); } if (!skip_drag_and_drop_handling) { if ((ThryEditor.input.is_drag_drop_event) && preview_rect.Contains(ThryEditor.input.mouse_position) && DragAndDrop.objectReferences[0] is Texture) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (ThryEditor.input.is_drop_event) { DragAndDrop.AcceptDrag(); prop.textureValue = (Texture)DragAndDrop.objectReferences[0]; } } } //scale offset rect if (hasFoldoutProperties) { if (DrawingData.currentTexProperty.hasScaleOffset) { Rect scale_offset_rect = new Rect(position); scale_offset_rect.y += 37; scale_offset_rect.width -= 2 + preview_rect.width + 10; editor.TextureScaleOffsetProperty(scale_offset_rect, prop); } PropertyOptions options = DrawingData.currentTexProperty.options; if (options.reference_properties != null) { foreach (string r_property in options.reference_properties) { ShaderProperty property = ThryEditor.currentlyDrawing.propertyDictionary[r_property]; EditorGUI.indentLevel *= 2; ThryEditor.currentlyDrawing.editor.ShaderProperty(property.materialProperty, property.content); EditorGUI.indentLevel /= 2; } } } Rect label_rect = new Rect(position); label_rect.x += 2; label_rect.y += 2; GUI.Label(label_rect, label); GUILayoutUtility.GetRect(0, 5); DrawingData.lastGuiObjectHeaderRect = position; DrawingData.lastGuiObjectRect = border; }
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(); }
private void UpdatePreviewTexture(Texture texture) { data.preview_texture = texture; prop.textureValue = texture; ThryEditor.repaint(); }
void OnGUI() { scrollPos = GUILayout.BeginScrollView(scrollPos); bool init = false; if (paths == null) { paths = new List <string>(); shaders = new List <Shader>(); differentQueueShaderPaths = new Dictionary <string, List <string> >(); string[] shaderGuids = AssetDatabase.FindAssets("t:shader"); for (int sguid = 0; sguid < shaderGuids.Length; sguid++) { string path = AssetDatabase.GUIDToAssetPath(shaderGuids[sguid]); Shader shader = AssetDatabase.LoadAssetAtPath <Shader>(path); if (!path.Contains("_differentQueues/")) { paths.Add(path); shaders.Add(shader); } else { List <string> differentQueueShaderPaths; this.differentQueueShaderPaths.TryGetValue(Helper.getDefaultShaderName(shader.name), out differentQueueShaderPaths); if (differentQueueShaderPaths == null) { differentQueueShaderPaths = new List <string>(); this.differentQueueShaderPaths.Add(Helper.getDefaultShaderName(shader.name), differentQueueShaderPaths); } differentQueueShaderPaths.Add(path); } } if (setEditor == null || setEditor.Length != shaderGuids.Length) { setEditor = new bool[paths.Count]; wasEditor = new bool[paths.Count]; } init = true; } for (int p = 0; p < paths.Count; p++) { if (init) { EditorUtility.DisplayProgressBar("Load all shaders...", "", (float)p / paths.Count); setEditor[p] = (new Material(shaders[p])).HasProperty(ThryEditor.PROPERTY_NAME_USING_THRY_EDITOR); wasEditor[p] = setEditor[p]; } setEditor[p] = GUILayout.Toggle(setEditor[p], shaders[p].name); } if (init) { EditorUtility.ClearProgressBar(); } GUILayout.EndScrollView(); if (GUILayout.Button("Apply")) { for (int i = 0; i < paths.Count; i++) { if (wasEditor[i] != setEditor[i]) { string path = paths[i]; ShaderImportFixer.scriptImportedAssetPaths.Add(path); if (setEditor[i]) { addThryEditor(path); } else { removeThryEditor(path); } List <string> differentQueueShaderPaths; this.differentQueueShaderPaths.TryGetValue(shaders[i].name, out differentQueueShaderPaths); if (differentQueueShaderPaths != null) { foreach (string queueShaderPath in differentQueueShaderPaths) { ShaderImportFixer.scriptImportedAssetPaths.Add(queueShaderPath); if (setEditor[i]) { addThryEditor(queueShaderPath); } else { removeThryEditor(queueShaderPath); } } } } wasEditor[i] = setEditor[i]; } AssetDatabase.Refresh(); 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(); }