Example #1
0
 private void DiscardChanges()
 {
     prop.textureValue = privious_preview_texture;
     SetGradient(TextureHelper.GetGradient(privious_preview_texture));
     gradient_has_been_edited = false;
     ShaderEditor.repaint();
 }
Example #2
0
 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;
     ShaderEditor.repaint();
 }
Example #3
0
        private static void Toggle(string configField, string label, string hover, GUIStyle label_style = null)
        {
            Config config = Config.Singleton;

            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();
                    ShaderEditor.repaint();
                }
            }
        }
Example #4
0
 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.Singleton.locale = Locale.editor.available_locales[Locale.editor.selected_locale_index];
         Config.Singleton.save();
         ShaderEditor.reload();
         ShaderEditor.repaint();
     }
 }
Example #5
0
        private static void Dropdown(string configField, string label, string hover, GUIStyle label_style = null)
        {
            Config config = Config.Singleton;

            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();
                    ShaderEditor.repaint();
                }
            }
        }
Example #6
0
        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(ShaderEditor.currentlyDrawing.propertyDictionary[r_property].materialProperty);
                }
            }
            if (DrawingData.currentTexProperty.reference_property_exists)
            {
                border.height += 8;
                border.height += editor.GetPropertyHeight(ShaderEditor.currentlyDrawing.propertyDictionary[DrawingData.currentTexProperty.options.reference_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.name == prop.name)
            {
                prop.textureValue = (Texture)EditorGUIUtility.GetObjectPickerObject();
                ShaderEditor.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 ((ShaderEditor.input.is_drag_drop_event) && preview_rect.Contains(ShaderEditor.input.mouse_position) && DragAndDrop.objectReferences[0] is Texture)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    if (ShaderEditor.input.is_drop_event)
                    {
                        DragAndDrop.AcceptDrag();
                        prop.textureValue = (Texture)DragAndDrop.objectReferences[0];
                    }
                }
            }

            //scale offset rect

            if (hasFoldoutProperties || DrawingData.currentTexProperty.options.reference_property != null)
            {
                EditorGUI.indentLevel += 2;

                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 + 30;
                    scale_offset_rect.x     += 30;
                    editor.TextureScaleOffsetProperty(scale_offset_rect, prop);
                    if (DrawingData.currentTexProperty.is_animatable)
                    {
                        DrawingData.currentTexProperty.HandleKajAnimatable();
                    }
                }
                float oldLabelWidth = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 128;

                PropertyOptions options = DrawingData.currentTexProperty.options;
                if (options.reference_property != null)
                {
                    ShaderProperty property = ShaderEditor.currentlyDrawing.propertyDictionary[options.reference_property];
                    ShaderEditor.currentlyDrawing.editor.ShaderProperty(property.materialProperty, property.content);
                }
                if (options.reference_properties != null)
                {
                    foreach (string r_property in options.reference_properties)
                    {
                        ShaderProperty property = ShaderEditor.currentlyDrawing.propertyDictionary[r_property];
                        ShaderEditor.currentlyDrawing.editor.ShaderProperty(property.materialProperty, property.content);
                        if (DrawingData.currentTexProperty.is_animatable)
                        {
                            property.HandleKajAnimatable();
                        }
                    }
                }
                EditorGUIUtility.labelWidth = oldLabelWidth;
                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;
        }
Example #7
0
 private void UpdatePreviewTexture(Texture texture)
 {
     data.preview_texture = texture;
     prop.textureValue    = texture;
     ShaderEditor.repaint();
 }
Example #8
0
        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.repaint();
            }
        }