private static void AssetsDeleted(string[] assets) { ShaderHelper.AssetsDeleted(assets); UnityFixer.OnAssetDeleteCheckDrawingDLL(assets); if (CheckForEditorRemove(assets)) { Debug.Log("ShaderEditor is being deleted."); Config.Singleton.verion = "0"; Config.Singleton.save(); ModuleHandler.OnEditorRemove(); } }
public static void UpdateRenderQueue(Material material, Shader defaultShader) { if (material.shader.renderQueue != material.renderQueue) { Shader renderQueueShader = defaultShader; if (material.renderQueue != renderQueueShader.renderQueue) { renderQueueShader = ShaderHelper.createRenderQueueShaderIfNotExists(defaultShader, material.renderQueue, true); } material.shader = renderQueueShader; } }
private static void AssetsDeleted(string[] assets) { VRCInterface.SetVRCDefineSybolIfSDKDeleted(assets); ShaderHelper.AssetsDeleted(assets); UnityFixer.OnAssetDeleteCheckDrawingDLL(assets); if (CheckForEditorRemove(assets)) { Debug.Log("ThryEditor is being deleted."); Config.Get().verion = "0"; Config.Get().save(); ModuleHandler.OnEditorRemove(); } }
//---------------------Stuff checkers and fixers------------------- //checks if slected shaders is using editor private void OnSelectionChange() { string[] selectedAssets = Selection.assetGUIDs; if (selectedAssets.Length == 1) { UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(AssetDatabase.GUIDToAssetPath(selectedAssets[0])); if (obj.GetType() == typeof(Shader)) { Shader shader = (Shader)obj; if (ShaderHelper.IsShaderUsingThryEditor(shader)) { Mediator.SetActiveShader(shader, new Material(shader)); } } } this.Repaint(); }
public static void SetMaterialPropertyValue(MaterialProperty p, Material[] materials, string value) { if (p.type == MaterialProperty.PropType.Texture) { Texture tex = AssetDatabase.LoadAssetAtPath <Texture>(value); if (tex != null) { foreach (Material m in materials) { m.SetTexture(p.name, tex); } } } else if (p.type == MaterialProperty.PropType.Float || p.type == MaterialProperty.PropType.Range) { float f_value; if (float.TryParse(value, out f_value)) { p.floatValue = f_value; string[] drawer = ShaderHelper.GetDrawer(p); if (drawer != null && drawer.Length > 1 && drawer[0] == "Toggle" && drawer[1] != "__") { MaterialHelper.ToggleKeyword(p, drawer[1], f_value == 1); } } } else if (p.type == MaterialProperty.PropType.Vector) { string[] xyzw = value.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(p.name, vector); } } else if (p.type == MaterialProperty.PropType.Color) { Color col = Converter.stringToColor(value); foreach (Material m in materials) { m.SetColor(p.name, col); } } }
public static void backupSingleMaterial(Material m) { if (restoring_in_progress) { return; } string[] mats = new string[0]; if (!File.Exists(PATH.MATERIALS_BACKUP_FILE)) { File.CreateText(PATH.MATERIALS_BACKUP_FILE).Close(); } else { mats = FileHelper.ReadFileIntoString(PATH.MATERIALS_BACKUP_FILE).Split(new string[] { "\n" }, System.StringSplitOptions.None); } bool updated = false; string matGuid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m.GetInstanceID())); string newString = ""; for (int mat = 0; mat < mats.Length; mat++) { if (mats[mat].Contains(matGuid)) { updated = true; newString += matGuid + ":" + ShaderHelper.getDefaultShaderName(m.shader.name) + ":" + m.renderQueue + "\r\n"; } else { newString += mats[mat] + "\n"; } } if (!updated) { newString += matGuid + ":" + ShaderHelper.getDefaultShaderName(m.shader.name) + ":" + m.renderQueue; } else { newString = newString.Substring(0, newString.LastIndexOf("\n")); } FileHelper.WriteStringToFile(newString, PATH.MATERIALS_BACKUP_FILE); }
static void FixKeywords() { IEnumerable <Material> materials = AssetDatabase.FindAssets("t:material").Select(g => AssetDatabase.GUIDToAssetPath(g)).Where(p => string.IsNullOrEmpty(p) == false) .Select(p => AssetDatabase.LoadAssetAtPath <Material>(p)).Where(m => m != null && m.shader != null) .Where(m => ShaderOptimizer.IsMaterialLocked(m) == false && ShaderHelper.IsShaderUsingThryShaderEditor(m.shader)); float f = 0; int count = materials.Count(); foreach (Material m in materials) { for (int i = 0; i < m.shader.GetPropertyCount(); i++) { if (m.shader.GetPropertyType(i) == UnityEngine.Rendering.ShaderPropertyType.Float) { ShaderHelper.EnableDisableKeywordsBasedOnTheirFloatValue(new Material[] { m }, m.shader, m.shader.GetPropertyName(i)); } } EditorUtility.DisplayProgressBar("Fixing Keywords", m.name, f++ / count); } EditorUtility.ClearProgressBar(); }
public static void BackupAllMaterials() { if (restoring_in_progress) { return; } EditorUtility.DisplayProgressBar("Backup materials", "", 0); Dictionary <string, string> materials_to_backup = new Dictionary <string, string>(); string[] materialGuids = AssetDatabase.FindAssets("t:material"); for (int mG = 0; mG < materialGuids.Length; mG++) { Material material = AssetDatabase.LoadAssetAtPath <Material>(AssetDatabase.GUIDToAssetPath(materialGuids[mG])); if (!MaterialShaderBroken(material)) { materials_to_backup[materialGuids[mG]] = ShaderHelper.getDefaultShaderName(material.shader.name); } EditorUtility.DisplayProgressBar("Backup materials", material.name, (float)(mG + 1) / materialGuids.Length); } FileHelper.SaveDictionaryToFile(PATH.MATERIALS_BACKUP_FILE, materials_to_backup); EditorUtility.ClearProgressBar(); }
//save mats public static void backupAllMaterials() { if (restoring_in_progress) { return; } if (!File.Exists(PATH.MATERIALS_BACKUP_FILE)) { File.CreateText(PATH.MATERIALS_BACKUP_FILE).Close(); } EditorUtility.DisplayProgressBar("Backup materials", "", 0); StreamWriter writer = new StreamWriter(PATH.MATERIALS_BACKUP_FILE, false); string[] materialGuids = AssetDatabase.FindAssets("t:material"); for (int mG = 0; mG < materialGuids.Length; mG++) { Material material = AssetDatabase.LoadAssetAtPath <Material>(AssetDatabase.GUIDToAssetPath(materialGuids[mG])); writer.WriteLine(materialGuids[mG] + ":" + ShaderHelper.getDefaultShaderName(material.shader.name) + ":" + material.renderQueue); EditorUtility.DisplayProgressBar("Backup materials", "", (float)(mG + 1) / materialGuids.Length); } writer.Close(); EditorUtility.ClearProgressBar(); }
private static void AssetsMoved(string[] movedAssets, string[] movedFromAssetPaths) { ShaderHelper.AssetsMoved(movedFromAssetPaths, movedAssets); }
private static void AssetsImported(string[] assets) { VRCInterface.SetVRCDefineSybolIfSDKImported(assets); ShaderHelper.AssetsImported(assets); }
private static void AssetsImported(string[] assets) { ShaderHelper.AssetsImported(assets); }
void OnGUI() { if (shaders == null) { this.shaders = ShaderHelper.GetThryEditorShaderNames(); if (Settings.activeShader != null) { for (int i = 0; i < shaders.Length; i++) { if (shaders[i] == Settings.activeShader.name) { selectedShaderIndex = i; } } } } if (propertyBackground == null) { setupStyle(); } Shader activeShader = Settings.activeShader; int newIndex = EditorGUILayout.Popup(selectedShaderIndex, shaders, GUILayout.MaxWidth(500)); if (selectedShaderIndex == -1) { newIndex = 0; } if (newIndex != selectedShaderIndex) { selectedShaderIndex = newIndex; selectedPreset = 0; Settings.setActiveShader(Shader.Find(shaders[selectedShaderIndex])); activeShader = Settings.activeShader; reloadProperties = true; } if (activeShader != null) { PresetHandler presetHandler = Settings.presetHandler; if (presetHandler.shaderHasPresetPath()) { Dictionary <string, List <string[]> > presets = presetHandler.getPresets(); string[] presetStrings = new string[presets.Count + 1]; int i = 0; foreach (KeyValuePair <string, List <string[]> > entry in presets) { presetStrings[i++] = entry.Key; } presetStrings[presets.Count] = "<New Preset>"; GUILayout.BeginHorizontal(); int newSelectedPreset = EditorGUILayout.Popup(selectedPreset, presetStrings, GUILayout.MaxWidth(500)); if (newSelectedPreset != selectedPreset || reloadProperties) { this.selectedPreset = newSelectedPreset; if (newSelectedPreset == presetStrings.Length - 1) { newPreset = true; newPresetName = "<name>"; properties = null; } else { this.properties = presetHandler.getPropertiesOfPreset(presetStrings[selectedPreset]); List <string> unusedProperties = new List <string>(); foreach (string pName in presetHandler.getPropertyNames()) { bool unused = true; foreach (string[] p in this.properties) { if (p[0] == pName) { unused = false; } } if (unused) { unusedProperties.Add(pName); } } this.unusedProperties = unusedProperties.ToArray(); reloadProperties = false; newPreset = false; } } if (GUILayout.Button("Delete", GUILayout.MaxWidth(80))) { presetHandler.removePreset(presetStrings[selectedPreset]); reloadProperties = true; Repaint(); } GUILayout.EndHorizontal(); if (newPreset) { GUILayout.BeginHorizontal(); newPresetName = GUILayout.TextField(newPresetName, GUILayout.MaxWidth(150)); if (GUILayout.Button("Add Preset", GUILayout.MaxWidth(80))) { presetHandler.addNewPreset(newPresetName); reloadProperties = true; Repaint(); selectedPreset = presetStrings.Length - 1; } GUILayout.EndHorizontal(); } scrollPos = GUILayout.BeginScrollView(scrollPos); if (properties != null) { for (i = 0; i < properties.Count; i++) { if (i % 2 == 0) { GUILayout.BeginHorizontal(propertyBackground); } else { GUILayout.BeginHorizontal(); } //properties[i][0] = GUILayout.TextField(properties[i][0], GUILayout.MaxWidth(200)); GUILayout.Label(properties[i][0], GUILayout.MaxWidth(150)); bool typeFound = false; ShaderUtil.ShaderPropertyType propertyType = ShaderUtil.ShaderPropertyType.Float; for (int p = 0; p < ShaderUtil.GetPropertyCount(activeShader); p++) { if (ShaderUtil.GetPropertyName(activeShader, p) == properties[i][0]) { propertyType = ShaderUtil.GetPropertyType(activeShader, p); typeFound = true; break; } } if (typeFound) { switch (propertyType) { case ShaderUtil.ShaderPropertyType.Color: float[] rgba = new float[4] { 1, 1, 1, 1 }; string[] rgbaString = properties[i][1].Split(','); if (rgbaString.Length > 0) { float.TryParse(rgbaString[0], out rgba[0]); } if (rgbaString.Length > 1) { float.TryParse(rgbaString[1], out rgba[1]); } if (rgbaString.Length > 2) { float.TryParse(rgbaString[2], out rgba[2]); } if (rgbaString.Length > 3) { float.TryParse(rgbaString[3], out rgba[3]); } Color p = EditorGUI.ColorField(EditorGUILayout.GetControlRect(GUILayout.MaxWidth(204)), new GUIContent(), new Color(rgba[0], rgba[1], rgba[2], rgba[3]), true, true, true, new ColorPickerHDRConfig(0, 1000, 0, 1000)); properties[i][1] = "" + p.r + "," + p.g + "," + p.b + "," + p.a; break; case ShaderUtil.ShaderPropertyType.TexEnv: string[] guids = AssetDatabase.FindAssets(properties[i][1]); Texture texture = null; if (guids.Length > 0) { texture = AssetDatabase.LoadAssetAtPath <Texture>(AssetDatabase.GUIDToAssetPath(guids[0])); } #pragma warning disable CS0618 // Type or member is obsolete texture = (Texture)EditorGUI.ObjectField(EditorGUILayout.GetControlRect(GUILayout.MaxWidth(100)), texture, typeof(Texture)); #pragma warning restore CS0618 // Type or member is obsolete if (texture != null) { properties[i][1] = texture.name; } GUILayout.Label("(" + properties[i][1] + ")", GUILayout.MaxWidth(100)); break; case ShaderUtil.ShaderPropertyType.Vector: Vector4 vector = Helper.stringToVector(properties[i][1]); vector = EditorGUI.Vector4Field(EditorGUILayout.GetControlRect(GUILayout.MaxWidth(204)), "", vector); properties[i][1] = "" + vector.x + "," + vector.y + "," + vector.z + "," + vector.w; break; default: properties[i][1] = GUILayout.TextField(properties[i][1], GUILayout.MaxWidth(204)); break; } } else { properties[i][1] = GUILayout.TextField(properties[i][1], GUILayout.MaxWidth(204)); } if (GUILayout.Button("Delete", GUILayout.MaxWidth(80))) { properties.RemoveAt(i); this.reloadProperties = true; saveProperties(presetHandler, presetStrings); } GUILayout.EndHorizontal(); } //new preset gui GUILayout.BeginHorizontal(); addPropertyIndex = EditorGUILayout.Popup(addPropertyIndex, unusedProperties, GUILayout.MaxWidth(150)); if (GUILayout.Button("Add", GUILayout.MaxWidth(80))) { this.reloadProperties = true; properties.Add(new string[] { unusedProperties[addPropertyIndex], "" }); saveProperties(presetHandler, presetStrings); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); if (GUILayout.Button("Save", GUILayout.MinWidth(50))) { saveProperties(presetHandler, presetStrings); } Event e = Event.current; if (e.isKey) { if (Event.current.keyCode == (KeyCode.Return)) { saveProperties(presetHandler, presetStrings); } } } } }
void OnGUI() { scrollPos = GUILayout.BeginScrollView(scrollPos); bool init = false; if (paths == null) { paths = new List <string>(); shaders = new List <Shader>(); 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); paths.Add(path); shaders.Add(shader); } 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] = ShaderHelper.IsShaderUsingShaderEditor(shaders[p]); 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]; if (setEditor[i]) { addShaderEditor(path); } else { removeShaderEditor(path); } } wasEditor[i] = setEditor[i]; } AssetDatabase.Refresh(); ShaderEditor.RepaintActive(); } }
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(ShaderHelper.getDefaultShaderName(shader.name), out differentQueueShaderPaths); if (differentQueueShaderPaths == null) { differentQueueShaderPaths = new List <string>(); this.differentQueueShaderPaths.Add(ShaderHelper.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] = ShaderHelper.IsShaderUsingThryEditor(shaders[p]); 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(); } }
private void OnGUI() { if (poiShaders == null || reload) { string[] shaderGuids = AssetDatabase.FindAssets("t:shader"); List <string> poiShaders = new List <string>(); foreach (string g in shaderGuids) { Shader shader = AssetDatabase.LoadAssetAtPath <Shader>(AssetDatabase.GUIDToAssetPath(g)); if (ShaderHelper.IsShaderUsingThryEditor(shader)) { string defaultShaderName = ShaderHelper.getDefaultShaderName(shader.name); if (!poiShaders.Contains(defaultShaderName)) { poiShaders.Add(defaultShaderName); } } } this.poiShaders = new string[poiShaders.Count + 1]; for (int i = 0; i < poiShaders.Count; i++) { this.poiShaders[i + 1] = poiShaders[i]; } } GUILayout.Label("With thry editor the render queue selection in the material editor creates copies of the shader with different queues to make it work in vrchat. \n With this tool you can pre create those shader files so you don't have to wait."); Shader activeShader = Mediator.active_shader; if (activeShader != null) { poiShaders[0] = ShaderHelper.getDefaultShaderName(activeShader.name); } else { poiShaders[0] = "None"; } int newSelectShader = EditorGUILayout.Popup(0, poiShaders, GUILayout.MaxWidth(200)); if (newSelectShader != selectedShader) { selectedShader = newSelectShader; activeShader = Shader.Find(poiShaders[newSelectShader]); Mediator.SetActiveShader(activeShader); } if (activeShader != null) { string defaultShaderName = ShaderHelper.getDefaultShaderName(activeShader.name);; Shader defaultShader = Shader.Find(defaultShaderName); GUIStyle style = new GUIStyle(GUI.skin.label); style.richText = true; EditorGUILayout.LabelField("<size=16>" + defaultShaderName + "</size>", style, GUILayout.MinHeight(18)); GUILayout.Label("Generate Render Queue Shaders", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); if (GUILayout.Button("Generate All Queues", GUILayout.MaxWidth(200))) { for (int i = createShadersFrom; i <= createShadersTo; i++) { ShaderHelper.createRenderQueueShaderIfNotExists(defaultShader, i, false); } AssetDatabase.Refresh(); } GUILayout.Label("from", GUILayout.MaxWidth(30)); createShadersFrom = EditorGUILayout.IntField(createShadersFrom, GUILayout.MaxWidth(50)); GUILayout.Label("to", GUILayout.MaxWidth(15)); createShadersTo = EditorGUILayout.IntField(createShadersTo, GUILayout.MaxWidth(50)); GUILayout.EndHorizontal(); if (GUILayout.Button("Generate most common Queues", GUILayout.MaxWidth(200))) { foreach (int i in COMMON_QUEUES) { ShaderHelper.createRenderQueueShaderIfNotExists(defaultShader, i, false); } AssetDatabase.Refresh(); } } }