예제 #1
0
    //-------------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;
    }
예제 #2
0
    //-------------Main Function--------------
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
    {
        if (firstOnGUICall || (reloadNextDraw && Event.current.type == EventType.Layout))
        {
            current                        = new EditorData();
            current.editor                 = materialEditor;
            current.gui                    = this;
            current.properties             = props;
            current.textureArrayProperties = new List <ShaderProperty>();
            current.firstCall              = true;
        }

        //handle events
        UpdateEvents();

        //first time call inits
        if (firstOnGUICall || (reloadNextDraw && Event.current.type == EventType.Layout))
        {
            OnOpen();
        }
        current.shader = current.materials[0].shader;

        currentlyDrawing = current;

        //sync shader and get preset handler
        Config config = Config.Get();

        if (current.materials != null)
        {
            Mediator.SetActiveShader(current.materials[0].shader, presetHandler: presetHandler);
        }


        //editor settings button + shader name + presets
        EditorGUILayout.BeginHorizontal();
        //draw editor settings button
        if (GUILayout.Button(new GUIContent(" Thry Editor", Styles.settings_icon), EditorStyles.largeLabel, new GUILayoutOption[] { GUILayout.MaxHeight(20) }))
        {
            Settings window = Settings.getInstance();
            window.Show();
            window.Focus();
        }
        EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);

        //draw master label if exists
        if (masterLabelText != null)
        {
            GuiHelper.DrawMasterLabel(masterLabelText, GUILayoutUtility.GetLastRect().y);
        }
        //draw presets if exists

        presetHandler.drawPresets(current.properties, current.materials);
        EditorGUILayout.EndHorizontal();

        //shader properties
        foreach (ShaderPart part in shaderparts.parts)
        {
            part.Draw();
        }

        //Render Queue selection
        if (config.showRenderQueue)
        {
            if (config.renderQueueShaders)
            {
                customRenderQueueFieldInput = GuiHelper.drawRenderQueueSelector(current.defaultShader, customRenderQueueFieldInput);
                EditorGUILayout.LabelField("Default: " + current.defaultShader.name);
                EditorGUILayout.LabelField("Shader: " + current.shader.name);
            }
            else
            {
                materialEditor.RenderQueueField();
            }
        }

        //footer
        GuiHelper.drawFooters(footer);

        Event e      = Event.current;
        bool  isUndo = (e.type == EventType.ExecuteCommand || e.type == EventType.ValidateCommand) && e.commandName == "UndoRedoPerformed";

        if (reloadNextDraw && Event.current.type == EventType.Layout)
        {
            reloadNextDraw = false;
        }
        if (isUndo)
        {
            reloadNextDraw = true;
        }

        //on swap
        if (on_swap_to_actions != null && swapped_to_shader)
        {
            foreach (DefineableAction a in on_swap_to_actions)
            {
                a.Perform();
            }
            on_swap_to_actions = null;
            swapped_to_shader  = false;
        }

        //test if material has been reset
        if (wasUsed && e.type == EventType.Repaint)
        {
            if (!current.materials[0].HasProperty("thry_has_not_been_reset"))
            {
                reloadNextDraw = true;
                HandleReset();
                wasUsed = true;
            }
        }

        if (e.type == EventType.Used)
        {
            wasUsed = true;
        }
        if (config.showRenderQueue && config.renderQueueShaders)
        {
            UpdateRenderQueueInstance();
        }
        if (input.HadMouseDownRepaint)
        {
            input.HadMouseDown = false;
        }
        input.HadMouseDownRepaint = false;
        current.firstCall         = false;
    }
예제 #3
0
    //-------------Main Function--------------
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
    {
        if (firstOnGUICall || (reloadNextDraw && Event.current.type == EventType.Layout))
        {
            current                        = new EditorData();
            current.editor                 = materialEditor;
            current.gui                    = this;
            current.properties             = props;
            current.textureArrayProperties = new List <ShaderProperty>();
            current.firstCall              = true;
        }

        //handle events
        UpdateEvents();

        //first time call inits
        if (firstOnGUICall || (reloadNextDraw && Event.current.type == EventType.Layout))
        {
            OnOpen();
        }
        current.shader = current.materials[0].shader;

        currentlyDrawing = current;

        //sync shader and get preset handler
        Config config = Config.Get();

        if (current.materials != null)
        {
            Mediator.SetActiveShader(current.materials[0].shader, presetHandler: presetHandler);
        }


        //TOP Bar
        Rect mainHeaderRect = EditorGUILayout.BeginHorizontal();

        //draw editor settings button
        if (GUILayout.Button(new GUIContent("", Styles.settings_icon), EditorStyles.largeLabel, GUILayout.MaxHeight(20), GUILayout.MaxWidth(20)))
        {
            Thry.Settings window = Thry.Settings.getInstance();
            window.Show();
            window.Focus();
        }
        EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
        if (GUILayout.Button(Styles.search_icon, EditorStyles.largeLabel, GUILayout.MaxHeight(20)))
        {
            show_search_bar = !show_search_bar;
        }

        //draw master label if exists
        if (masterLabelText != null)
        {
            GuiHelper.DrawMasterLabel(masterLabelText, mainHeaderRect);
        }

        Rect visibilityButtonPosition = GUILayoutUtility.GetRect(new GUIContent(Styles.visibility_icon), EditorStyles.largeLabel, GUILayout.MaxHeight(20), GUILayout.MaxWidth(20));

        if (GUI.Button(visibilityButtonPosition, Styles.visibility_icon, EditorStyles.largeLabel))
        {
            HeaderHider.DrawHeaderHiderMenu(visibilityButtonPosition, current.shaderParts);
        }
        EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
        //draw presets if exists
        presetHandler.drawPresets(current.properties, current.materials);
        EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);

        EditorGUILayout.EndHorizontal();

        if (show_search_bar)
        {
            header_search_term = EditorGUILayout.TextField(header_search_term);
        }

        //PROPERTIES
        if (header_search_term == "" || show_search_bar == false)
        {
            foreach (ShaderPart part in shaderparts.parts)
            {
                part.Draw();
            }
        }
        else
        {
            foreach (ShaderPart part in current.propertyDictionary.Values)
            {
                if (IsSearchedFor(part, header_search_term))
                {
                    part.Draw();
                }
            }
        }

        //Render Queue selection
        if (config.showRenderQueue)
        {
            if (config.renderQueueShaders)
            {
                customRenderQueueFieldInput = GuiHelper.drawRenderQueueSelector(current.defaultShader, customRenderQueueFieldInput);
                EditorGUILayout.LabelField("Default: " + current.defaultShader.name);
                EditorGUILayout.LabelField("Shader: " + current.shader.name);
            }
            else
            {
                materialEditor.RenderQueueField();
            }
        }

        //footer
        GuiHelper.drawFooters(footer);

        EditorGUILayout.LabelField("@UI Powered by Thryrallo", Styles.made_by_style);

        Event e      = Event.current;
        bool  isUndo = (e.type == EventType.ExecuteCommand || e.type == EventType.ValidateCommand) && e.commandName == "UndoRedoPerformed";

        if (reloadNextDraw && Event.current.type == EventType.Layout)
        {
            reloadNextDraw = false;
        }
        if (isUndo)
        {
            reloadNextDraw = true;
        }

        //on swap
        if (on_swap_to_actions != null && swapped_to_shader)
        {
            foreach (DefineableAction a in on_swap_to_actions)
            {
                a.Perform();
            }
            on_swap_to_actions = null;
            swapped_to_shader  = false;
        }

        //test if material has been reset
        if (wasUsed && e.type == EventType.Repaint)
        {
            if (current.materials[0].HasProperty("shader_is_using_thry_editor") && current.materials[0].GetFloat("shader_is_using_thry_editor") != 69)
            {
                reloadNextDraw = true;
                HandleReset();
                wasUsed = true;
            }
        }

        if (e.type == EventType.Used)
        {
            wasUsed = true;
        }
        if (config.showRenderQueue && config.renderQueueShaders)
        {
            UpdateRenderQueueInstance();
        }
        if (input.HadMouseDownRepaint)
        {
            input.HadMouseDown = false;
        }
        input.HadMouseDownRepaint = false;
        current.firstCall         = false;
    }