//-------------Draw Functions---------------- public void OnOpen() { Config config = Config.Get(); //get material targets UnityEngine.Object[] targets = current.editor.targets; current.materials = new Material[targets.Length]; for (int i = 0; i < targets.Length; i++) { current.materials[i] = targets[i] as Material; } presetHandler = new PresetHandler(current.properties); current.shader = current.materials[0].shader; string defaultShaderName = current.materials[0].shader.name.Split(new string[] { "-queue" }, System.StringSplitOptions.None)[0].Replace(".differentQueues/", ""); current.defaultShader = Shader.Find(defaultShaderName); //collect shader properties CollectAllProperties(); //update render queue if render queue selection is deactivated if (!config.renderQueueShaders && !config.showRenderQueue) { current.materials[0].renderQueue = current.defaultShader.renderQueue; UpdateRenderQueueInstance(); } current.materials[0].SetInt("thry_has_not_been_reset", 69); firstOnGUICall = false; }
public void OnOpen() { Config config = Config.Get(); //get material targets Object[] targets = current.editor.targets; current.materials = new Material[targets.Length]; for (int i = 0; i < targets.Length; i++) { current.materials[i] = targets[i] as Material; } //collect shader properties CollectAllProperties(); presetHandler = new PresetHandler(current.properties); //init settings texture if (settingsTexture == null) { byte[] fileData = File.ReadAllBytes(AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("thry_settings_icon")[0])); settingsTexture = new Texture2D(2, 2); settingsTexture.LoadImage(fileData); } current.shader = current.materials[0].shader; string defaultShaderName = current.materials[0].shader.name.Split(new string[] { "-queue" }, System.StringSplitOptions.None)[0].Replace(".differentQueues/", ""); current.defaultShader = Shader.Find(defaultShaderName); //update render queue if render queue selection is deactivated if (!config.renderQueueShaders && !config.showRenderQueue) { current.materials[0].renderQueue = current.defaultShader.renderQueue; UpdateRenderQueueInstance(); } foreach (MaterialProperty p in current.properties) { if (p.name == PROPERTY_NAME_USING_THRY_EDITOR) { p.floatValue = MATERIAL_NOT_RESET; } } if (current.materials != null) { foreach (Material m in current.materials) { ShaderImportFixer.backupSingleMaterial(m); } } firstOnGUICall = false; }
//-------------Main Function-------------- public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { if (firstOnGUICall || reloadNextDraw) { current = new EditorData(); current.editor = materialEditor; current.gui = this; current.properties = props; current.textureArrayProperties = new List <ShaderProperty>(); current.firstCall = true; current.draw_material_option_dsgi = false; current.draw_material_option_instancing = false; current.draw_material_option_lightmap = false; } //handle events Event e = Event.current; MouseClick = e.type == EventType.MouseDown; if (MouseClick) { HadMouseDown = true; } if (HadMouseDown && e.type == EventType.Repaint) { HadMouseDownRepaint = true; } //first time call inits if (firstOnGUICall || reloadNextDraw) { OnOpen(); } currentlyDrawing = current; //sync shader and get preset handler Config config = Config.Get(); Settings.setActiveShader(current.materials[0].shader); presetHandler = Settings.presetHandler; //editor settings button + shader name + presets EditorGUILayout.BeginHorizontal(); //draw editor settings button if (GUILayout.Button(settingsTexture, new GUILayoutOption[] { GUILayout.MaxWidth(24), GUILayout.MaxHeight(18) })) { Settings window = Settings.getInstance(); window.Show(); window.Focus(); } //draw master label if exists if (masterLabelText != null) { GuiHelper.DrawMasterLabel(masterLabelText); } //draw presets if exists presetHandler.drawPresets(current.properties, current.materials); EditorGUILayout.EndHorizontal(); //shader properties foreach (ShaderPart part in shaderparts.parts) { part.Draw(); } //Mateiral Options if (current.draw_material_option_lightmap) { GuiHelper.DrawLightmapFlagsOptions(); } if (current.draw_material_option_instancing) { GuiHelper.DrawInstancingOptions(); } if (current.draw_material_option_dsgi) { GuiHelper.DrawDSGIOptions(); } //Render Queue selection if (config.showRenderQueue) { if (config.renderQueueShaders) { customQueueFieldInput = GuiHelper.drawRenderQueueSelector(current.defaultShader, customQueueFieldInput); EditorGUILayout.LabelField("Default: " + current.defaultShader.name); EditorGUILayout.LabelField("Shader: " + current.shader.name); } else { materialEditor.RenderQueueField(); } } //footer GuiHelper.drawFooters(footer); bool isUndo = (e.type == EventType.ExecuteCommand || e.type == EventType.ValidateCommand) && e.commandName == "UndoRedoPerformed"; if (reloadNextDraw) { reloadNextDraw = false; } if (isUndo) { reloadNextDraw = true; } //save last drag position, because mouse postion is wrong on drag dropped event if (Event.current.type == EventType.DragUpdated) { lastDragPosition = Event.current.mousePosition; } //test if material has been reset if (wasUsed && e.type == EventType.Repaint) { foreach (MaterialProperty p in props) { if (p.name == "shader_is_using_thry_editor" && p.floatValue != MATERIAL_NOT_RESET) { reloadNextDraw = true; TextTextureDrawer.ResetMaterials(); break; } } wasUsed = false; } if (e.type == EventType.Used) { wasUsed = true; } if (config.showRenderQueue && config.renderQueueShaders) { UpdateRenderQueueInstance(); } if (HadMouseDownRepaint) { HadMouseDown = false; } HadMouseDownRepaint = false; current.firstCall = false; }