Example #1
0
        public override void DrawDefault()
        {
            Rect pos = GUILayoutUtility.GetRect(content, ThryEditorGuiHelper.vectorPropertyStyle);

            ThryEditorGuiHelper.drawConfigTextureProperty(pos, materialProperty, content, currentlyDrawing.editor, true);
            DrawingData.lastGuiObjectRect = pos;
        }
Example #2
0
    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();

        ThryEditorGuiHelper.SetupStyle();

        //init settings texture
        byte[] fileData = File.ReadAllBytes(AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("thrySettigsIcon")[0]));
        settingsTexture = new Texture2D(2, 2);
        settingsTexture.LoadImage(fileData);

        //init master label
        MaterialProperty shader_master_label = FindProperty(current.properties, "shader_master_label");

        if (shader_master_label != null)
        {
            masterLabelText = shader_master_label.displayName;
        }

        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 == "shader_is_using_thry_editor")
            {
                p.floatValue = MATERIAL_NOT_RESET;
            }
        }

        if (current.materials != null)
        {
            foreach (Material m in current.materials)
            {
                ShaderImportFixer.backupSingleMaterial(m);
            }
        }
        firstOnGUICall = false;
    }
Example #3
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;
        }

        //handle events
        Event e = Event.current;

        if (e.type == EventType.MouseDown)
        {
            hadMouseClickEvent = true;
        }
        if (hadMouseClickEvent && e.type == EventType.Repaint)
        {
            isMouseClick = 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)
        {
            ThryEditorGuiHelper.DrawMasterLabel(masterLabelText);
        }
        //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)
            {
                customQueueFieldInput = ThryEditorGuiHelper.drawRenderQueueSelector(current.defaultShader, customQueueFieldInput);
                EditorGUILayout.LabelField("Default: " + current.defaultShader.name);
                EditorGUILayout.LabelField("Shader: " + current.shader.name);
            }
            else
            {
                materialEditor.RenderQueueField();
            }
        }

        //footer
        ThryEditorGuiHelper.drawFooters(footer);

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

        if (reloadNextDraw)
        {
            reloadNextDraw = false;
        }
        if (isUndo)
        {
            reloadNextDraw = true;
        }

        //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 (isMouseClick)
        {
            hadMouseClickEvent = false;
        }
        isMouseClick = false;
    }