Beispiel #1
0
    private void AddColorControl(SerializedProperty colorProperty, GUIContent guiContent)
    {
        EditorGUI.BeginProperty(EditorGUILayout.GetControlRect(), primaryColorFieldLabel, primaryColorProperty);
        EditorGUI.BeginChangeCheck();

        Color color = EditorGUILayout.ColorField(guiContent, colorProperty.colorValue);

        if (EditorGUI.EndChangeCheck())
        {
            colorProperty.colorValue = color;
            serializedObject.ApplyModifiedProperties();
        }

        EditorGUI.EndProperty();

        GUILayout.Space(2);

        Color invertedColor  = new Color(1 - color.r, 1 - color.g, 1 - color.b, 1 - color.a);
        Color colorPlusWhite = new Color((1 + color.r) * 0.5f, (1 + color.g) * 0.5f, (1 + color.b) * 0.5f, 1f);
        Color colorPlusBlack = new Color(color.r * 0.5f, color.g * 0.5f, color.b * 0.5f, 1f);

        Rect rect = GUILayoutUtility.GetRect(10, 10);

        Rect rect1 = new Rect(rect.x, rect.y, (rect.width / 3f), rect.height);
        Rect rect2 = new Rect(rect.x + rect.width / 3f + rect.width / 30f, rect.y, (rect.width / 3f) * 0.8f, rect.height);
        Rect rect3 = new Rect(rect.x + 2 * rect.width / 3f, rect.y, (rect.width / 3f), rect.height);

        EditorGUIUtility.DrawColorSwatch(rect1, invertedColor);
        EditorGUIUtility.DrawColorSwatch(rect2, colorPlusWhite);
        EditorGUIUtility.DrawColorSwatch(rect3, colorPlusBlack);
    }
        public override void OnNodeGUI()
        {
            PWTerrainOutputMode oldTerrainMode = outputMode;

            outputMode = GetTerrainOutputMode();
            if (outputMode != oldTerrainMode)
            {
                UpdateOutputType();
            }

            EditorGUILayout.BeginHorizontal();
            if (outputBiome != null)
            {
                EditorGUIUtility.labelWidth = 72;
                EditorGUILayout.LabelField("id: " + outputBiome.id + " (" + outputBiome.name + ")");
                if (Event.current.type == EventType.Repaint)
                {
                    colorPreviewRect        = EditorGUILayout.GetControlRect();
                    colorPreviewRect.width -= 88;
                }
                else
                {
                    EditorGUILayout.GetControlRect();
                }
                EditorGUIUtility.DrawColorSwatch(colorPreviewRect, outputBiome.previewColor);
            }
            EditorGUILayout.EndHorizontal();

            //TODO: preview the modified terrain
        }
 void OnGUI()
 {
     if (GUILayout.Button("xxxx"))
     {
         EditorGUIUtility.DrawColorSwatch(new Rect(0, 0, 500, 500), Color.red);
     }
 }
Beispiel #4
0
        public override void OnNodeGUI()
        {
            EditorGUILayout.LabelField("Biome: " + outputBiome.name);
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUIUtility.labelWidth = 40;
                EditorGUILayout.LabelField("id: " + outputBiome.id);
                EditorGUIUtility.labelWidth = 0;
                Rect colorRect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight, GUILayout.ExpandWidth(true));
                if (e.type == EventType.Repaint)
                {
                    biomeColorPreviewRect = colorRect;
                }
                EditorGUI.BeginDisabledGroup(false);
                EditorGUIUtility.DrawColorSwatch(biomeColorPreviewRect, outputBiome.previewColor);
                EditorGUI.EndDisabledGroup();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.LabelField("Biome Graph reference");
            EditorGUI.BeginChangeCheck();
            biomeGraph = EditorGUILayout.ObjectField(biomeGraph, typeof(PWBiomeGraph), false) as PWBiomeGraph;
            if (EditorGUI.EndChangeCheck())
            {
                NotifyReload();
            }

            if (biomeGraph != null)
            {
                if (GUILayout.Button("Open " + biomeGraph.name))
                {
                    AssetDatabase.OpenAsset(biomeGraph);
                }
            }
        }
Beispiel #5
0
    void Draw_Colors()
    {
        int k   = 0;
        int top = 0;

        for (int i = 0; i < colors.Count; i++)
        {
            Rect r;
            if (top == 0)
            {
                r = new Rect(left_space + k * (size + space), top_space, size, size);
            }
            else
            {
                r = new Rect(left_space + k * (size + space), top * (size + space) + top_space, size, size);
            }
            EditorGUIUtility.DrawColorSwatch(r, colors[i]);
            k++;
            if (k == in_one_row)
            {
                k = 0;
                top++;
            }
        }
    }
 public void OnGUI(Rect rect, ComponentReference select)
 {
     if (selected?.serialized != null)
     {
         EditorGUIUtility.DrawColorSwatch(rect, new Color(0.1f, 0.1f, 0.1f, 0.5f));
         DrawProperties(selected.serialized, rect);
     }
 }
Beispiel #7
0
        public override void Draw(DrawInfo drawInfo)
        {
            base.Draw(drawInfo);

            if (!m_isVisible)
            {
                return;
            }

            if (m_isEditingFields && m_currentParameterType != PropertyType.Global)
            {
                if (m_materialMode && m_currentParameterType != PropertyType.Constant)
                {
                    EditorGUI.BeginChangeCheck();
#if UNITY_2018_1_OR_NEWER
                    m_materialValue = EditorGUIColorField(m_propertyDrawPos, m_dummyContent, m_materialValue, false, true, m_isHDR);
#else
                    m_materialValue = EditorGUIColorField(m_propertyDrawPos, m_dummyContent, m_materialValue, false, true, m_isHDR, m_hdrConfig);
#endif
                    if (EditorGUI.EndChangeCheck())
                    {
                        PreviewIsDirty          = true;
                        m_requireMaterialUpdate = true;
                        if (m_currentParameterType != PropertyType.Constant)
                        {
                            BeginDelayedDirtyProperty();
                        }
                    }
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
#if UNITY_2018_1_OR_NEWER
                    m_defaultValue = EditorGUIColorField(m_propertyDrawPos, m_dummyContent, m_defaultValue, false, true, m_isHDR);
#else
                    m_defaultValue = EditorGUIColorField(m_propertyDrawPos, m_dummyContent, m_defaultValue, false, true, m_isHDR, m_hdrConfig);
#endif
                    if (EditorGUI.EndChangeCheck())
                    {
                        PreviewIsDirty = true;
                        BeginDelayedDirtyProperty();
                    }
                }
            }
            else if (drawInfo.CurrentEventType == EventType.Repaint)
            {
                if (m_materialMode && m_currentParameterType != PropertyType.Constant)
                {
                    EditorGUIUtility.DrawColorSwatch(m_propertyDrawPos, m_materialValue);
                }
                else
                {
                    EditorGUIUtility.DrawColorSwatch(m_propertyDrawPos, m_defaultValue);
                }

                GUI.Label(m_propertyDrawPos, string.Empty, UIUtils.GetCustomStyle(CustomStyle.SamplerFrame));
            }
        }
        public static Rect DrawCustomSwatch(ColorInfo colorInfo, int size)
        {
            Rect rect = EditorGUILayout.GetControlRect(false, size, EditorStyles.colorField, GUILayout.Width(size));

            GUI.enabled = false;
            GUI.Button(rect, new GUIContent("", colorInfo.ToString()));
            GUI.enabled = true;
            EditorGUIUtility.DrawColorSwatch(rect, colorInfo.color);

            return(rect);
        }
Beispiel #9
0
    public static void xDrawTextureColor(this Rect r, Texture2D tex, Color c)
    {
        var oColor = GUI.color;

        GUI.color = c;
        GUI.DrawTexture(r, tex);
        GUI.color = oColor;

        if (r.xLMB_isDown().noModifier)
        {
            EditorGUIUtility.DrawColorSwatch(r.dy(20f).w(200), c);
        }
    }
        void ColorSettings()
        {
            using (new GUILayout.VerticalScope("Box"))
            {
                GUILayout.Label("Node color:", "BoldLabel");
                EditorGUILayout.HelpBox("custom colors can be defined in the settings window of FlowReactor", MessageType.Info);

                if (GUILayout.Button("Settings"))
                {
                    EditorApplication.ExecuteMenuItem("Edit/Preferences...");
                }

                if (availableColors == null || !availableColors.ContainsKey(nodeColor))
                {
                    GetAvailableColors();
                }

                var _lastRect = GUILayoutUtility.GetLastRect();
                _lastRect = new Rect(_lastRect.x, _lastRect.y + 25, _lastRect.width, _lastRect.height);
                EditorGUIUtility.DrawColorSwatch(_lastRect, availableColors[nodeColor]);

                GUILayout.Space(25);

                using (var scrollView = new GUILayout.ScrollViewScope(colorScrollPos, GUILayout.Height(60)))
                {
                    colorScrollPos = scrollView.scrollPosition;


                    using (new GUILayout.HorizontalScope("Box"))
                    {
                        foreach (var c in availableColors.Keys)
                        {
                            GUI.contentColor = availableColors[c];
                            if (GUILayout.Button(new GUIContent("", whiteBox), GUILayout.Width(30), GUILayout.Height(30)))
                            {
                                nodeColor = c;
                            }
                            GUI.contentColor = Color.white;
                        }

                        GUILayout.FlexibleSpace();
                    }
                }


                GUILayout.FlexibleSpace();
            }
        }
Beispiel #11
0
        /// <summary>
        /// Draws swatches for the list of colors.
        /// </summary>
        /// <param name="colorList">The color list.</param>
        /// <param name="position">The position where to draw the swatches.</param>
        /// <param name="columns">The number of columns.</param>
        /// <param name="maxColors">The maximum number of colors to draw.</param>
        /// <param name="widthOffset">The width offset.</param>
        /// <param name="heightOffset">The height offset.</param>
        public static void DrawColors(
            Color[] colorList,
            Rect position,
            int columns        = 2,
            int maxColors      = 100,
            float widthOffset  = -2.0f,
            float heightOffset = -2.0f)
        {
            var colorCount = colorList.Length;

            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();

            var x      = position.x;
            var width  = position.width / columns;
            var height = position.height;
            var y      = position.y;

            if (columns > 0)
            {
                var indentLevel = EditorGUI.indentLevel;

                EditorGUI.indentLevel = 0;

                for (int i = 0; i < Mathf.Min(maxColors, colorCount); i++)
                {
                    //Makes a new row
                    if (i != 0 && i % columns == 0)
                    {
                        x  = position.x;
                        y += height;
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                    }

                    var color = colorList[i];

                    EditorGUIUtility.DrawColorSwatch(new Rect(x, y, width + widthOffset, height + heightOffset), color);
                    x += width;
                }

                EditorGUI.indentLevel = indentLevel;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
        }
Beispiel #12
0
        internal static bool DrawColorPaletteColorPicker(object key, ColorPalette colorPalette, ref Color color, bool drawAlpha, bool stretchPalette, float width = 20, float height = 20, float margin = 0)
        {
            bool result = false;

            var rect = SirenixEditorGUI.BeginHorizontalAutoScrollBox(key, GUILayoutOptions.ExpandWidth(true).ExpandHeight(false));

            {
                if (stretchPalette)
                {
                    rect.width -= margin * colorPalette.Colors.Count - margin;
                    width       = Mathf.Max(width, rect.width / colorPalette.Colors.Count);
                }

                bool  isMouseDown = Event.current.type == EventType.MouseDown;
                var   innerRect   = GUILayoutUtility.GetRect((width + margin) * colorPalette.Colors.Count, height, GUIStyle.none);
                float spacing     = width + margin;
                var   cellRect    = innerRect;
                cellRect.width = width;

                for (int i = 0; i < colorPalette.Colors.Count; i++)
                {
                    cellRect.x = spacing * i;

                    if (drawAlpha)
                    {
                        EditorGUIUtility.DrawColorSwatch(cellRect, colorPalette.Colors[i]);
                    }
                    else
                    {
                        var c = colorPalette.Colors[i];
                        c.a = 1;
                        SirenixEditorGUI.DrawSolidRect(cellRect, c);
                    }

                    if (isMouseDown && cellRect.Contains(Event.current.mousePosition))
                    {
                        color       = colorPalette.Colors[i];
                        result      = true;
                        GUI.changed = true;
                        Event.current.Use();
                    }
                }
            }
            SirenixEditorGUI.EndHorizontalAutoScrollBox();
            return(result);
        }
        /// <summary>
        /// General utilities used for editor code.
        /// </summary>
        public static void DrawColors(SerializedProperty colorsProp, Rect position)
        {
            int colorCount = colorsProp.arraySize;

            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();

            int columns = (int)(position.width / 16);

            float x      = position.x;
            float width  = 16;
            float height = 16;
            float y      = position.y;

            if (columns > 0)
            {
                var indentLevel = EditorGUI.indentLevel;

                EditorGUI.indentLevel = 0;

                for (int i = 0; i < Mathf.Min(100, colorCount); i++)
                {
                    if (i != 0 && i % columns == 0)
                    {
                        x  = position.x;
                        y += height;
                        //EditorGUILayout.EndHorizontal();
                        //EditorGUILayout.BeginHorizontal();
                    }

                    var colorProp = colorsProp.GetArrayElementAtIndex(i);
                    var color     = colorProp.colorValue;

                    //var rect = EditorGUILayout.GetControlRect(false, 16, GUILayout.Width(16));

                    //EditorGUI.DrawRect(rect, color);
                    EditorGUIUtility.DrawColorSwatch(new Rect(x, y, width - 2, height - 2), color);
                    x += width;
                }

                EditorGUI.indentLevel = indentLevel;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
        }
    void WindowCallback(int id)
    {
        var  cell    = cellMap[id];
        var  sSwitch = surfaceSwitches[id];
        Rect r       = EditorGUILayout.GetControlRect(false);

        EditorGUIUtility.DrawColorSwatch(r, cell.surface.color.baseColor);
        GUI.DragWindow();

        EditorGUILayout.BeginVertical();
        {
            EditorGUILayout.LabelField("Height min: " + sSwitch.minHeight + ", max: " + sSwitch.maxHeight);
            EditorGUILayout.LabelField("Slope min: " + sSwitch.minSlope + ", max: " + sSwitch.maxSlope);
            EditorGUILayout.LabelField("Param min: " + sSwitch.minParam + ", max: " + sSwitch.maxParam);
            EditorGUILayout.LabelField("Weight: " + cell.weight);
        }
        EditorGUILayout.EndVertical();
    }
Beispiel #15
0
    public override void OnInspectorGUI()
    {
        AddColorControl(primaryColorProperty, primaryColorFieldLabel);
        AddColorControl(secondaryColorProperty, secondaryColorFieldLabel);

        GUILayout.Space(20);

        Rect labelRect = GUILayoutUtility.GetRect(10, 15);

        EditorGUI.DropShadowLabel(labelRect, colorMixLabel);

        GUILayout.Space(2);

        Rect colorMixSwatchRect = GUILayoutUtility.GetRect(10, 10);

        colorMixSwatchRect.width *= 0.67f;
        colorMixSwatchRect.x     += (colorMixSwatchRect.width / 0.67f) * (0.33f * 0.5f);
        EditorGUIUtility.DrawColorSwatch(colorMixSwatchRect, (primaryColorProperty.colorValue + secondaryColorProperty.colorValue) * 0.5f);

        GUILayout.Space(2);
    }
    protected virtual void OnGUI()
    {
        var style = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).button;

        style.margin        = new RectOffset(2, 2, 1, 2);
        style.border.left   = 3;
        style.border.right  = 3;
        style.border.bottom = 2;
        style.border.top    = 1;
        interactionTreeList.OnGUI(new Rect(0, 32, position.width / 3, position.height - 10));
        interactionTreeListR.OnGUI(new Rect(position.width * 0.6667f, 32, position.width / 3, position.height));
        EditorGUIUtility.DrawColorSwatch(new Rect(position.width / 3, 32, position.width * 0.333333f, position.height), colour);
        switch (GUILayout.Toolbar(-1, new GUIContent[]
        {
            EditorGUIUtility.TrTextContent("<=", "Und davos Left af"),
            new GUIContent("Cancel", "Und davos annuleren."),
            new GUIContent(RowDataHelpers <R> .RowIcon(typeof(IConsequence)), ""),
            GUIContent.none,
            new GUIContent("AddComponent", "Und davos toevoegen ee"),
            new GUIContent("Couple", "Und davos linken weer"),
            EditorGUIUtility.TrTextContent("=>", "Und davos Right af"),
        }, new bool[] { false, true, true, false, false, true, false },
                                  style,
                                  new GUILayoutOption[] { GUILayout.Height(30), GUILayout.ExpandHeight(false) }))
        {
        case 1:
            OnEnable();
            break;

        case 5:
            linktionary.Link <T, R>();
            break;

        default:
            //nothing
            break;
        }
        inspector.OnGUI(new Rect(12 + position.width / 3, 44, -24 + position.width / 3, -56 + position.height), selected);
    }
        /// <summary>
        /// Draws a Preview Tool to assist with setting up the color modifier when not in play mode.
        /// Added because we can just use a color swatch to set the colors because they be be set to 'Adjust' and in that case the value can be negative
        /// </summary>
        private void DrawPreviewTool(Rect previewToolsRect, SerializedProperty property, SerializedProperty previewProp)
        {
            var prevIndent = EditorGUI.indentLevel;
            var toolsRect  = EditorGUI.IndentedRect(previewToolsRect);

            EditorGUI.indentLevel = 0;
            if (Event.current.type == EventType.Repaint)             //draw the background
            {
                var bgRect = new Rect(toolsRect.xMin - 3f, previewToolsRect.yMax, toolsRect.width + 6f, ((EditorGUIUtility.singleLineHeight + (EditorGUIUtility.standardVerticalSpacing * 2f)) * 3f) + 3f);
                GUI.skin.box.Draw(bgRect, GUIContent.none, 0);
            }
            var previewColorRect = new Rect(toolsRect.xMin + 3f, previewToolsRect.yMax + (EditorGUIUtility.standardVerticalSpacing) + 3f, toolsRect.width - 6f, EditorGUIUtility.singleLineHeight);
            var dummyDNARect     = new Rect(toolsRect.xMin + 3f, previewColorRect.yMax + (EditorGUIUtility.standardVerticalSpacing), toolsRect.width - 6f, EditorGUIUtility.singleLineHeight);
            var resultColorRect  = new Rect(toolsRect.xMin + 3f, dummyDNARect.yMax + (EditorGUIUtility.standardVerticalSpacing), toolsRect.width - 6f, EditorGUIUtility.singleLineHeight);

            _previewColor          = EditorGUI.ColorField(previewColorRect, new GUIContent("Preview Color", "Set a color that you would like to see changed by the settings above"), _previewColor);
            previewProp.floatValue = EditorGUI.Slider(dummyDNARect, new GUIContent("Test Evaluated DNA", "An evaluated dna result to test"), previewProp.floatValue, -1f, 1f);
            var swatchRect = EditorGUI.PrefixLabel(resultColorRect, new GUIContent("Resulting Color", "The resulting color you would get if the modifications above were applied to the preview color with the given dna result"));

            _resultingColor = EvaluatePreviewAdjustments(property, previewProp.floatValue, 1f, _previewColor);
            EditorGUIUtility.DrawColorSwatch(swatchRect, _resultingColor);
            EditorGUI.indentLevel = prevIndent;
        }
    public void DrawGUI(ref Color color)
    {
        var rect = GUILayoutUtility.GetRect(width, height);

        var mainRect = rect;

        mainRect.width  = mainTexture.width;
        mainRect.height = mainTexture.height;

        var sideRect = rect;

        sideRect.width  = 20;
        sideRect.height = sidebarTexture.height;
        sideRect.x     += mainRect.width + 4;

        var alphaRect = rect;

        alphaRect.width  = alphaTexture.width;
        alphaRect.height = 16;
        alphaRect.x     += 40;
        alphaRect.y      = mainRect.y + mainRect.height + 4;

        GUI.DrawTexture(mainRect, mainTexture);
        GUI.DrawTexture(sideRect, sidebarTexture);
        GUI.DrawTexture(alphaRect, alphaTexture);

        GUI.Label(new Rect(rect.x, alphaRect.y, 40, 16), "Alpha:");

        var bottomRect = rect;

        bottomRect.y      = mainRect.y + mainRect.height + 24;
        bottomRect.height = 80 - 4;


        //Channels
        var channelRect = bottomRect;

        channelRect.width  /= 3;
        channelRect.height /= 4;
        EditorGUIUtility.LookLikeControls(20, channelRect.width - 20);

        color.r        = Mathf.Clamp01(EditorGUI.FloatField(channelRect, "R:", (color.r * 255f)) / 255f);
        channelRect.y += channelRect.height;
        color.g        = Mathf.Clamp01(EditorGUI.FloatField(channelRect, "G:", (color.g * 255f)) / 255f);
        channelRect.y += channelRect.height;
        color.b        = Mathf.Clamp01(EditorGUI.FloatField(channelRect, "B:", (color.b * 255f)) / 255f);
        channelRect.y += channelRect.height;
        color.a        = Mathf.Clamp01(EditorGUI.FloatField(channelRect, "A:", (color.a * 255f)) / 255f);


        //Hex
        var hexRect = bottomRect;

        hexRect.width  /= 3;
        hexRect.height /= 4;
        hexRect.x      += hexRect.width * 2;
        hexRect.y      += hexRect.height * 3;
        hexRect.width  -= 6;
        EditorGUIUtility.LookLikeControls(15, hexRect.width - 15);

        float cr = Mathf.Clamp(color.r * 255f, 0, 255);
        float cg = Mathf.Clamp(color.g * 255f, 0, 255);
        float cb = Mathf.Clamp(color.b * 255f, 0, 255);

        string alpha = "0123456789ABCDEF";
        string hex   = "" +
                       alpha[Mathf.Clamp(Mathf.FloorToInt(cr / 16), 0, 15)] + alpha[Mathf.Clamp(Mathf.RoundToInt(cr % 16), 0, 15)]
                       + alpha[Mathf.Clamp(Mathf.FloorToInt(cg / 16), 0, 15)] + alpha[Mathf.Clamp(Mathf.RoundToInt(cg % 16), 0, 15)]
                       + alpha[Mathf.Clamp(Mathf.FloorToInt(cb / 16), 0, 15)] + alpha[Mathf.Clamp(Mathf.RoundToInt(cb % 16), 0, 15)];

        string newHex = EditorGUI.TextField(hexRect, "#", hex);

        if (newHex != hex && newHex.Length == 6)
        {
            color.r = (alpha.IndexOf(newHex[0]) * 16 + alpha.IndexOf(newHex[1])) / 255f;
            color.g = (alpha.IndexOf(newHex[2]) * 16 + alpha.IndexOf(newHex[3])) / 255f;
            color.b = (alpha.IndexOf(newHex[4]) * 16 + alpha.IndexOf(newHex[5])) / 255f;
        }

        //Swatch
        var swatchRect = bottomRect;

        swatchRect.x       = hexRect.x;
        swatchRect.width   = hexRect.width;
        swatchRect.height -= hexRect.height;
        EditorGUIUtility.DrawColorSwatch(swatchRect, color);

        //HSB
        EditorGUIUtility.LookLikeControls(20, channelRect.width - 40);

        var hsbRect = bottomRect;

        hsbRect.width  /= 3;
        hsbRect.height /= 4;
        hsbRect.x      += hsbRect.width;
        hsbRect.width  -= 30;

        var hsbSelectRect = hsbRect;

        hsbSelectRect.width = 30;
        hsbSelectRect.x    += 6;

        hsbRect.x += 24;

        EditorGUI.BeginChangeCheck();
        _hsb.h = Mathf.Repeat(EditorGUI.FloatField(hsbRect, "H:", _hsb.h * 360f), 360f) / 360f;
        if (EditorGUI.Toggle(hsbSelectRect, mode == Mode.Hue))
        {
            mode = Mode.Hue;
        }

        hsbRect.y       += hsbRect.height;
        hsbSelectRect.y += hsbRect.height;
        _hsb.s           = Mathf.Clamp01(EditorGUI.FloatField(hsbRect, "S:", _hsb.s * 255f) / 255f);
        if (EditorGUI.Toggle(hsbSelectRect, mode == Mode.Saturation))
        {
            mode = Mode.Saturation;
        }

        hsbRect.y       += hsbRect.height;
        hsbSelectRect.y += hsbRect.height;
        _hsb.b           = Mathf.Clamp01(EditorGUI.FloatField(hsbRect, "B:", _hsb.b * 255f) / 255f);
        if (EditorGUI.Toggle(hsbSelectRect, mode == Mode.Brightness))
        {
            mode = Mode.Brightness;
        }

        if (EditorGUI.EndChangeCheck())
        {
            color = _hsb.ToColor();
        }

        EditorGUIUtility.LookLikeControls();

        if (
            (Event.current.type == EventType.MouseDown || (Event.current.type == EventType.MouseDrag)) &&
            Event.current.button == 0
            )
        {
            var mp = Event.current.mousePosition;

            if (!sideDown && !alphaDown && (mainRect.Contains(Event.current.mousePosition) || mainDown))
            {
                var mainInterp = new Vector2(
                    Mathf.Clamp01((mp.x - mainRect.x) / mainRect.width),
                    Mathf.Clamp01((mp.y - mainRect.y) / mainRect.height)
                    );

                switch (mode)
                {
                default:
                case Mode.Hue:
                    _hsb.s = mainInterp.x;
                    _hsb.b = 1 - mainInterp.y;
                    break;

                case Mode.Saturation:
                    _hsb.h = mainInterp.x;
                    _hsb.b = 1 - mainInterp.y;
                    break;

                case Mode.Brightness:
                    _hsb.h = mainInterp.x;
                    _hsb.s = 1 - mainInterp.y;
                    break;
                }
                color = _hsb.ToColor();

                Event.current.Use();

                mainDown = true;
            }

            if (!mainDown && !alphaDown && (sideRect.Contains(Event.current.mousePosition) || sideDown))
            {
                var sideInterp = Mathf.Clamp01((mp.y - sideRect.y) / sideRect.height);

                switch (mode)
                {
                default:
                case Mode.Hue:
                    _hsb.h = 1 - sideInterp;
                    break;

                case Mode.Saturation:
                    _hsb.s = 1 - sideInterp;
                    break;

                case Mode.Brightness:
                    _hsb.b = 1 - sideInterp;
                    break;
                }
                color = _hsb.ToColor();

                Event.current.Use();

                sideDown = true;
            }

            if (!mainDown && !sideDown && (alphaRect.Contains(Event.current.mousePosition) || alphaDown))
            {
                var alphaInterp = Mathf.Clamp01((mp.x - alphaRect.x) / alphaRect.width);
                color.a = alphaInterp;

                Event.current.Use();
                alphaDown = true;
            }
        }

        if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
        {
            sideDown  = false;
            mainDown  = false;
            alphaDown = false;
        }

        var pickerTexture = InlineColorPickerResources.pickerTexture;

        var pickerRect = new Rect(mainRect);

        pickerRect.width  = pickerTexture.width;
        pickerRect.height = pickerTexture.height;

        Vector2 pickerPosition;
        float   sidePickerPosition;

        switch (mode)
        {
        default:
        case Mode.Hue:
            pickerPosition.x   = _hsb.s;
            pickerPosition.y   = 1 - _hsb.b;
            sidePickerPosition = 1 - _hsb.h;
            break;

        case Mode.Saturation:
            pickerPosition.x   = _hsb.h;
            pickerPosition.y   = 1 - _hsb.b;
            sidePickerPosition = 1 - _hsb.s;
            break;

        case Mode.Brightness:
            pickerPosition.x   = _hsb.h;
            pickerPosition.y   = 1 - _hsb.s;
            sidePickerPosition = 1 - _hsb.b;
            break;
        }

        pickerRect.x += pickerPosition.x * mainTexture.width;
        pickerRect.y += pickerPosition.y * mainTexture.height;

        pickerRect.x -= pickerRect.width / 2;
        pickerRect.y -= pickerRect.height / 2;
        GUI.DrawTexture(pickerRect, pickerTexture);

        // Draw setting picker
        var sidePickerTexture = InlineColorPickerResources.arrow_horizontal;

        var sidePickerRect = sideRect;

        sidePickerRect.width  = sidePickerTexture.width;
        sidePickerRect.height = sidePickerTexture.height;

        sidePickerRect.y += sidePickerPosition * sidebarTexture.height;
        sidePickerRect.y -= sidePickerTexture.height / 2;
        GUI.DrawTexture(sidePickerRect, sidePickerTexture);

        sidePickerRect.x    += sideRect.width;
        sidePickerRect.width = -sidePickerRect.width;
        GUI.DrawTexture(sidePickerRect, sidePickerTexture);

        // Draw alpha picker
        var alphaPickerTexture = InlineColorPickerResources.arrow_vertical;

        var alphaPickerRect = alphaRect;

        alphaPickerRect.width  = alphaPickerTexture.width;
        alphaPickerRect.height = alphaPickerTexture.height;

        alphaPickerRect.x += alphaRect.width;
        alphaPickerRect.x -= (1 - _hsb.a) * alphaTexture.width;
        alphaPickerRect.x -= alphaPickerRect.width / 2;
        GUI.DrawTexture(alphaPickerRect, alphaPickerTexture);

        alphaPickerRect.y     += alphaRect.height;
        alphaPickerRect.height = -alphaPickerRect.height;
        GUI.DrawTexture(alphaPickerRect, alphaPickerTexture);

//		GUI.Box(channelRect, GUIContent.none);


//		float buttonWidth = (bottomRect.width-8) / 3;
//		bottomRect.width = buttonWidth;
//		bottomRect.x -= bottomRect.width;
//		bottomRect.x -= 4;
//		Func<string, bool, bool> bottomButton = (name, state)=>{
//			bottomRect.x += buttonWidth + 4;
//
//			GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
//			boxStyle.normal.textColor = Color.white;
//
//			GUI.Box(bottomRect, name, boxStyle);
//			if(state) GUI.Box(bottomRect, name, boxStyle);
//			if(Event.current.type == EventType.MouseDown && Event.current.button == 0 && bottomRect.Contains(Event.current.mousePosition))
//			{
//				state = true;
//			}
//			else
//			{
//				EditorGUIUtility.AddCursorRect(bottomRect, MouseCursor.Link);
//			}
//			return state;
//		};
//
//		if(bottomButton("Hue", mode == Mode.Hue))
//		{
//			mode = Mode.Hue;
//		}
//		if(bottomButton("Saturation", mode == Mode.Saturation))
//		{
//			mode = Mode.Saturation;
//		}
//		if(bottomButton("Brightness", mode == Mode.Brightness))
//		{
//			mode = Mode.Brightness;
//		}
//
//		_hsb.h = Mathf.Clamp01(_hsb.h);
//		_hsb.s = Mathf.Clamp01(_hsb.s);
//		_hsb.b = Mathf.Clamp01(_hsb.b);

        UpdateColor(color);
    }
Beispiel #19
0
 public static void DrawColorSwatch(Rect position, Color color)
 {
     EditorGUIUtility.DrawColorSwatch(position, color);
 }
Beispiel #20
0
    void DrawBottomMenuRect(Rect baseRect)
    {
        GUI.Box(baseRect, "");

        Rect imageRect = baseRect;

        imageRect.width = m_nOriginalBottomHeight - 1;
        Rect rightRect = baseRect;

        rightRect.x     += imageRect.width;
        rightRect.width -= imageRect.width;
        rightRect        = FXMakerLayout.GetOffsetRect(rightRect, 5, 3, -5, -3);

        Rect buttonRect   = FXMakerLayout.GetInnerVerticalRect(rightRect, 12, 0, 5);
        int  nButtonWidht = 70;

        buttonRect.width = nButtonWidht / 2;

        if (m_SelectedMaterial != null && m_SelObjectContent != null)
        {
            // image
            if (GUI.Button(imageRect, new GUIContent("", m_SelObjectContent.image, m_SelObjectContent.tooltip), GUI.skin.GetStyle("PopupBottom_ImageButton")))
            {
                if (Input.GetMouseButtonUp(0))
                {
                    if (0 <= m_nNewShaderMaterialIndex)
                    {
                        FXMakerAsset.SetPingObject(m_SelectedTransform.gameObject);
                    }
                    else
                    {
                        FXMakerAsset.SetPingObject(m_SelectedMaterial);
                    }
                    FXMakerMain.inst.CreateCurrentInstanceEffect(true);
                }
                if (Input.GetMouseButtonUp(1))
                {
                    FXMakerAsset.SetPingObject(m_SelObjectContent.image);
                }
            }

            // Current Color
            Color matColor  = NgMaterial.GetMaterialColor(m_SelectedMaterial);
            Rect  colorRect = FXMakerLayout.GetOffsetRect(FXMakerLayout.GetInnerVerticalRect(rightRect, 12, 5, 7), 0, 2, 0, 0);
            colorRect.width = nButtonWidht / 2;
            if (NgMaterial.IsMaterialColor(m_SelectedMaterial))
            {
                EditorGUIUtility.DrawColorSwatch(colorRect, matColor);
            }

            // text
            rightRect.x     += colorRect.width;
            rightRect.width -= colorRect.width;
            GUI.Label(FXMakerLayout.GetInnerVerticalRect(rightRect, 12, 5, 3), m_SelObjectContent.text);
            GUI.Label(FXMakerLayout.GetInnerVerticalRect(rightRect, 12, 7, 5), (m_SelectedMaterial.shader != null ? m_SelectedMaterial.shader.name : "[Not Selected]"));


            bool bChange = (NgMaterial.IsSameMaterial(m_SelectedMaterial, m_OriMaterial, true) == false);
            // Undo
            if (FXMakerLayout.GUIButton(buttonRect, GetHelpContent("Undo"), bChange))
            {
                UndoObject();
                return;
            }

            // UniqueSave
            buttonRect.x    += buttonRect.width + 5;
            buttonRect.width = nButtonWidht;
            if (FXMakerLayout.GUIButton(buttonRect, GetHelpContent("UniqueSave"), bChange))
            {
                m_bUniqueSave = true;
                ClosePopup(true);
                return;
            }
        }

        // close
        buttonRect.x    += buttonRect.width + 5;
        buttonRect.width = baseRect.width - buttonRect.x;
        if (GUI.Button(buttonRect, GetHelpContent("Close")))
        {
            ClosePopup(true);
        }

        // ���õȰ�, ������, ��ġ, ȸ��, ����, �ݱ�, ���
    }
Beispiel #21
0
        public void drawInspector()
        {
            if (GUIUtils.DrawHeader("Create palette"))
            {
                GUIUtils.BeginContents();
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        m_selectedAlgorithm = (Algorithm)EditorGUILayout.EnumPopup(m_selectedAlgorithm);
                        if (GUILayout.Button("Generate", EditorStyles.miniButton))
                        {
                            GUI.FocusControl(null);
                            generatePalette();
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    m_colorCount = EditorGUILayout.IntSlider("Number of colors", m_colorCount, 1, 25);

                    if (m_selectedAlgorithm == Algorithm.RANDOM_FROM_COLOR)
                    {
                        m_colorReference = EditorGUILayout.ColorField("Base color", m_colorReference);
                        m_colorOffset    = EditorGUILayout.FloatField("Color offset", m_colorOffset);
                    }
                    else if (m_selectedAlgorithm == Algorithm.RANDOM_GOLDEN_RATIO)
                    {
                        m_saturation = EditorGUILayout.Slider("Saturation", m_saturation, 0.0f, 1.0f);
                    }
                    else if (m_selectedAlgorithm == Algorithm.GRADIENT)
                    {
                        m_colorGradient1 = EditorGUILayout.ColorField("From color", m_colorGradient1);
                        m_colorGradient2 = EditorGUILayout.ColorField("To color", m_colorGradient2);
                    }

                    if (m_generatedColorPalette != null)
                    {
                        if (GUI.changed)
                        {
                            generatePalette();
                        }

                        GUILayout.Space(3f);

                        EditorGUILayout.BeginHorizontal();
                        {
                            for (int j = 0; j < m_generatedColorPalette.colorInfoList.Count; j++)
                            {
                                Rect rect = EditorGUILayout.GetControlRect(false, 20f, EditorStyles.colorField, GUILayout.Width(20f));
                                EditorGUIUtility.DrawColorSwatch(rect, m_generatedColorPalette.colorInfoList[j].color);
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        GUILayout.Space(3f);

                        if (GUILayout.Button("Add to my palettes"))
                        {
                            m_paletteData.colorPaletteList.Add(m_generatedColorPalette);
                            m_generatedColorPalette = null;

                            PaletteUtils.SavePalettes(m_paletteData);
                        }
                    }
                }
                GUIUtils.EndContents();
            }
        }
    // ==========================================================================================================
    void winPopup(int id)
    {
        Rect baseRect = GetPopupRect();
        Rect buttonRect;
        Rect lineRect;

        if (UnfocusClose(baseRect, -10, 0, 0, 0))
        {
            return;
        }

        baseRect = FXMakerLayout.GetChildVerticalRect(baseRect, 0, 1, 0, 1);

        Transform transOriginalRoot = FXMakerMain.inst.GetOriginalEffectObject().transform;
        int       nButtonCount      = m_nButtonCount * 2;
        int       nDrawCount        = 0;
        bool      bEnable           = false;

        // Copy
        if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Copy"), true))
        {
            FXMakerClipboard.inst.SetClipboardObject(m_SelectedObject);
            ClosePopup(true);
            return;
        }
        nDrawCount += 2;

        // Cut
        switch (m_SelObjectType)
        {
        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_GAMEOBJECT:    bEnable = (m_SelectedTransform != transOriginalRoot);  break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_TRANSFORM:             bEnable = false;        break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_EASYEFFECT:    bEnable = true;         break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_UNITYENGINE:   bEnable = true;         break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_OTHER:                 bEnable = true;         break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_MATERIAL:              bEnable = false;        break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_ANICLIP:               bEnable = false;        break;

        default: Debug.LogWarning("not declare");      break;
        }
        if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Cut"), bEnable))
        {
            FXMakerClipboard.inst.SetClipboardObject(m_SelectedObject);
            FXMakerHierarchy.inst.DeleteHierarchyObject(m_SelectedTransform, m_SelectedObject, m_nSelectedIndex);
            ClosePopup(true);
            return;
        }
        nDrawCount += 2;

        // Paste
        switch (m_SelObjectType)
        {
        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_GAMEOBJECT:
        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_TRANSFORM:
        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_EASYEFFECT:
        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_UNITYENGINE:
        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_OTHER:                 bEnable = FXMakerClipboard.inst.IsObject();     break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_MATERIAL:              bEnable = false;        break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_ANICLIP:               bEnable = false;        break;

        default: Debug.LogWarning("not declare");      break;
        }
        if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Paste", FXMakerClipboard.inst.GetName()), bEnable))
        {
            Object tarObj = FXMakerClipboard.inst.PasteClipboardObject(m_SelectedTransform.gameObject, m_SelectedObject, m_nSelectedIndex);
            if (tarObj is GameObject)
            {
                SetAddObject((tarObj as GameObject), tarObj);
            }
            else
            {
                SetAddObject(null, tarObj);
            }
            ClosePopup(true);
            return;
        }
        nDrawCount += 2;

        // Overwrite
        switch (m_SelObjectType)
        {
        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_GAMEOBJECT:            bEnable = false;        break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_TRANSFORM:             bEnable = FXMakerClipboard.inst.IsTransform() && FXMakerClipboard.inst.GetObject().GetType() == m_SelectedObject.GetType();             break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_EASYEFFECT:
        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_UNITYENGINE:
        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_OTHER:                 bEnable = FXMakerClipboard.inst.IsComponent() && FXMakerClipboard.inst.GetObject().GetType() == m_SelectedObject.GetType();             break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_MATERIAL:              bEnable = FXMakerClipboard.inst.IsMaterial() && FXMakerClipboard.inst.GetObject().GetType() == m_SelectedObject.GetType();              break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_ANICLIP:               bEnable = FXMakerClipboard.inst.IsAnimationClip() && FXMakerClipboard.inst.GetObject().GetType() == m_SelectedObject.GetType(); break;

        default: Debug.LogWarning("not declare"); break;
        }
        if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Overwrite", FXMakerClipboard.inst.GetName()), bEnable))
        {
            FXMakerClipboard.inst.OverwriteClipboardObject(m_SelectedTransform.gameObject, m_SelectedObject, m_nSelectedIndex);
            ClosePopup(true);
            return;
        }
        nDrawCount += 2;

        // Draw line
        lineRect = FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 1);
        NgGUIDraw.DrawHorizontalLine(new Vector2(lineRect.x, lineRect.y + lineRect.height / 2), (int)lineRect.width, Color.gray, 2, false);
        nDrawCount += 1;

        // Duplicate
        switch (m_SelObjectType)
        {
        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_GAMEOBJECT:    bEnable = (m_SelectedTransform != transOriginalRoot);   break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_TRANSFORM:             bEnable = false;        break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_EASYEFFECT:    bEnable = true;         break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_UNITYENGINE:   bEnable = true;         break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_OTHER:                 bEnable = true;         break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_MATERIAL:              bEnable = false;        break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_ANICLIP:               bEnable = false;        break;

        default: Debug.LogWarning("not declare"); break;
        }
        if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Duplicate"), bEnable))
        {
            switch (m_SelObjectType)
            {
            case FXMakerHierarchy.OBJECT_TYPE.OBJECT_GAMEOBJECT:    SetAddObject(FXMakerHierarchy.inst.AddGameObject(m_SelectedTransform.transform.parent.gameObject, m_SelectedTransform.gameObject), null);               break;

            case FXMakerHierarchy.OBJECT_TYPE.OBJECT_TRANSFORM:             break;

            case FXMakerHierarchy.OBJECT_TYPE.OBJECT_EASYEFFECT:
            case FXMakerHierarchy.OBJECT_TYPE.OBJECT_UNITYENGINE:
            case FXMakerHierarchy.OBJECT_TYPE.OBJECT_OTHER:                 m_AddComObject = NgSerialized.CloneComponent(m_SelectedObject as Component, (m_SelectedObject as Component).gameObject, false); break;

            case FXMakerHierarchy.OBJECT_TYPE.OBJECT_MATERIAL:              break;

            case FXMakerHierarchy.OBJECT_TYPE.OBJECT_ANICLIP:               break;

            default: Debug.LogWarning("not declare"); break;
            }
            ClosePopup(true);
            return;
        }
        nDrawCount += 2;

        // Disable
        if (m_SelObjectType == FXMakerHierarchy.OBJECT_TYPE.OBJECT_GAMEOBJECT)
        {
            bool bObjEnable = (m_SelectedTransform.gameObject.GetComponent <NcDontActive>() == null);
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), (bObjEnable ? GetHelpContent("Disable") : GetHelpContent("Enable")), (m_SelectedTransform != transOriginalRoot)))
            {
                FXMakerHierarchy.inst.SetEnableGameObject(m_SelectedTransform.gameObject, !bObjEnable);
                ClosePopup(true);
                return;
            }
        }
        else
        {
            buttonRect = FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2);
            if (m_SelectedObject is Component)
            {
                int nObjEnable = EditorUtility.GetObjectEnabled(m_SelectedObject);
                if (0 <= nObjEnable)
                {
                    if (0 < nObjEnable)
                    {
                        if (GUI.Button(buttonRect, GetHelpContent("Disable")))
                        {
                            EditorUtility.SetObjectEnabled(m_SelectedObject, false);
                            ClosePopup(true);
                            return;
                        }
                    }
                    else
                    {
                        if (GUI.Button(buttonRect, GetHelpContent("Enable")))
                        {
                            EditorUtility.SetObjectEnabled(m_SelectedObject, true);
                            ClosePopup(true);
                            return;
                        }
                    }
                }
                else
                {
                    FXMakerLayout.GUIButton(buttonRect, GetHelpContent("Disable"), false);
                }
            }
            else
            {
                FXMakerLayout.GUIButton(buttonRect, GetHelpContent("Disable"), false);
            }
        }
        nDrawCount += 2;


        // Delete
        switch (m_SelObjectType)
        {
        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_GAMEOBJECT:    bEnable = (m_SelectedTransform != transOriginalRoot);  break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_TRANSFORM:             bEnable = false;        break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_EASYEFFECT:    bEnable = true;         break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_UNITYENGINE:   bEnable = true;         break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_OTHER:                 bEnable = true;         break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_MATERIAL:              bEnable = true;         break;

        case FXMakerHierarchy.OBJECT_TYPE.OBJECT_ANICLIP:               bEnable = true;         break;

        default: Debug.LogWarning("not declare"); break;
        }
        if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Delete"), bEnable))
        {
            FXMakerHierarchy.inst.DeleteHierarchyObject(m_SelectedTransform, m_SelectedObject, m_nSelectedIndex);
            ClosePopup(true);
            return;
        }
        nDrawCount += 2;

        // Draw line
        lineRect = FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 1);
        NgGUIDraw.DrawHorizontalLine(new Vector2(lineRect.x, lineRect.y + lineRect.height / 2), (int)lineRect.width, Color.gray, 2, false);
        nDrawCount += 1;

        // -------------------------------------------------------------------------------------
        if (m_SelectedObject is NcCurveAnimation)
        {
            // NcCurveAnimation
            NcCurveAnimation curveCom = m_SelectedObject as NcCurveAnimation;
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("SaveCurves"), 0 < curveCom.GetCurveInfoCount()))
            {
                ClosePopup(true);
                FxmPopupManager.inst.ShowNcCurveAnimationPopup(curveCom, true);
                return;
            }
            nDrawCount += 2;
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("LoadCurves"), true))
            {
                ClosePopup(true);
                FxmPopupManager.inst.ShowNcCurveAnimationPopup(curveCom, false);
                return;
            }
            nDrawCount += 2;
        }
        // -------------------------------------------------------------------------------------
        if (m_SelObjectType == FXMakerHierarchy.OBJECT_TYPE.OBJECT_GAMEOBJECT)
        {
            // Add Child
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Add Child"), true))
            {
//              GameObject	newChild	= new GameObject("GameObject");
//              newChild.transform.parent = m_SelectedTransform;
//              FXMakerHierarchy.inst.OnAddGameObject(newChild);
//              SetAddObject(newChild, null);
//              ClosePopup(true);

                FXMakerHierarchy.inst.ShowAddObjectRightPopup();
                ClosePopup(false);

                return;
            }
            nDrawCount += 2;

            // Add Parent
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Add Parent"), true))
            {
                GameObject newParent = new GameObject("GameObject");
                newParent.transform.parent = m_SelectedTransform.parent;
                m_SelectedTransform.parent = newParent.transform;
                m_SelectedTransform.name   = m_SelectedTransform.name.Replace("(Original)", "");
                if (m_SelectedTransform == transOriginalRoot)
                {
                    FXMakerMain.inst.ChangeRoot_OriginalEffectObject(newParent);
                }
                FXMakerHierarchy.inst.OnAddGameObject(newParent);
                SetAddObject(newParent, null);
                ClosePopup(true);
                return;
            }
            nDrawCount += 2;

            // MoveToParent
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("MoveToParent"), (m_SelectedTransform != transOriginalRoot && (m_SelectedTransform.parent != transOriginalRoot) || (m_SelectedTransform.parent == transOriginalRoot && transOriginalRoot.childCount == 1))))
            {
                if (m_SelectedTransform.parent == transOriginalRoot && transOriginalRoot.childCount == 1)
                {
                    FXMakerMain.inst.SaveTool("");
                    m_SelectedTransform = FXMakerMain.inst.GetOriginalEffectObject().transform;
                    // root swap
                    Transform toolRoot  = m_SelectedTransform.parent;
                    Transform newParent = m_SelectedTransform.GetChild(0);
                    Transform newChild  = m_SelectedTransform;
                    newChild.parent     = null;
                    newParent.parent    = null;
                    newChild.parent     = newParent;
                    newParent.parent    = toolRoot;
                    m_SelectedTransform = newParent;
                    FXMakerMain.inst.ChangeRoot_OriginalEffectObject(m_SelectedTransform.gameObject);
                    SetAddObject(null, null);
                }
                else
                {
                    m_SelectedTransform.parent = m_SelectedTransform.parent.parent;
                }
                ClosePopup(true);
                return;
            }
            nDrawCount += 2;

            // Add Component
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Add Component"), true))
            {
                ClosePopup(true);
                FxmPopupManager.inst.ShowHierarchyObjectPopup("FxmPopup_GameObject", m_SelectedTransform.gameObject);
                return;
            }
            nDrawCount += 2;

            // Add Prefab
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Add Prefab"), true))
            {
                FxmPopupManager.inst.ShowAddPrefabPopup(m_SelectedTransform);
                ClosePopup(true);
                return;
            }
            nDrawCount += 2;

            // Save Prefab
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Save Prefab"), true))
            {
                ClosePopup(true);
                FxmPopupManager.inst.ShowSavePrefabPopup(m_SelectedTransform);
                return;
            }
            nDrawCount += 2;
        }
        // -------------------------------------------------------------------------------------
        if (m_SelObjectType == FXMakerHierarchy.OBJECT_TYPE.OBJECT_MATERIAL)
        {
            bEnable = NgMaterial.IsMaterialColor(m_SelectedObject as Material);

            // Copy Color
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Copy Color"), bEnable))
            {
                FXMakerClipboard.inst.SetClipboardColor(NgMaterial.GetMaterialColor(m_SelectedObject as Material));
                ClosePopup(true);
                return;
            }
            if (bEnable)
            {
                Rect colorRect = FXMakerLayout.GetOffsetRect(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), -5);
                colorRect.width = colorRect.height;
                EditorGUIUtility.DrawColorSwatch(colorRect, NgMaterial.GetMaterialColor(m_SelectedObject as Material));
            }
            nDrawCount += 2;

            // Paste Color
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), GetHelpContent("Paste Color"), bEnable))
            {
                FXMakerClipboard.inst.PasteClipboardColor(m_SelectedTransform, m_nSelectedIndex, m_SelectedObject as Material);
                ClosePopup(true);
                return;
            }
            {
                Rect colorRect = FXMakerLayout.GetOffsetRect(FXMakerLayout.GetInnerVerticalRect(baseRect, nButtonCount, nDrawCount, 2), -5);
                colorRect.width = colorRect.height;
                EditorGUIUtility.DrawColorSwatch(colorRect, FXMakerClipboard.inst.m_CopyColor);
            }
            nDrawCount += 2;
        }

        m_nButtonCount = nDrawCount / 2;
        FXMakerMain.inst.SaveTooltip();
    }
    protected virtual PaletteData drawColorPalette(PaletteData data, bool showHexValues = false)
    {
        // palette height silder
        //height = EditorGUILayout.Slider ("Height", height, 100, 200);

        GUILayout.Space(10);

        //paletteHeight = height;
        EditorGUILayout.BeginHorizontal();

        data.name = EditorGUILayout.TextField("Palette name: ", data.name);

        EditorGUILayout.EndHorizontal();

        GUILayout.Space(10);

        Rect paletteRect;

        if (showHexValues)
        {
            paletteRect = GUILayoutUtility.GetRect(Screen.width, paletteHeight + paletteTopMargin);
        }
        else
        {
            paletteRect = GUILayoutUtility.GetRect(Screen.width, paletteHeight);
        }


        if (data.colors != null)
        {
            // show the palette
            float start = 20;

            for (int i = 0; i < data.colors.Length; i++)
            {
                Color col      = data.colors [i];
                float colWidth = data.percentages [i] * (Screen.width - 35);

                //Debug.Log (i + " starts " + start + " width " + colWidth);
                float yPos = paletteRect.position.y;

                if (showHexValues)
                {
                    yPos = paletteRect.position.y + paletteTopMargin;
                }

                Rect colRect = new Rect(start, yPos, colWidth,
                                        paletteHeight - paletteBotMargin);

                EditorGUIUtility.DrawColorSwatch(colRect, col);

                Rect lableRect = colRect;
                lableRect.width  = 60;
                lableRect.height = 15;

                lableRect.y -= paletteTopMargin * 0.5f;

                if (i % 2 == 0)
                {
                    lableRect.y -= 15;
                }

                if (showHexValues)
                {
                    string hexString    = JSONPersistor.ColorToHex(col);
                    Rect   labelHexRect = new Rect(lableRect);
                    labelHexRect.width = hexFieldWidth;


                    string newHex = EditorGUI.TextField(labelHexRect, hexString);

                    if (!newHex.Equals(JSONPersistor.ColorToHex(col)))
                    {
                        data.colors [i] = JSONPersistor.HexToColor(newHex);
                    }
                }


                start += colWidth;
            }
        }

        return(data);
    }
Beispiel #24
0
        public void ColorPicker(GUIContent prefix, Rect rect, ref Color color, bool displayColorPreview = true, bool previewOnIcon = false)
        {
            var   e           = Event.current;
            Rect  iconRect    = rect;
            int   icColorSize = 18;
            Color localColor  = color;

            var fieldSettings = GetGUISettingData(() => {
                PWGUISettings colorSettings = new PWGUISettings();

                colorSettings.c = (SerializableColor)localColor;

                return(colorSettings);
            });

            if (fieldSettings.active)
            {
                int colorPickerWidth  = 170;
                int colorPickerHeight = 270;

                GUI.changed = true;
                PWPopup.AddToRender(fieldSettings, "Color picker", () =>
                {
                    if (e.type == EventType.KeyDown)
                    {
                        if (e.keyCode == KeyCode.Return || e.keyCode == KeyCode.KeypadEnter)
                        {
                            fieldSettings.InActive();
                            e.Use();
                        }
                        if (e.keyCode == KeyCode.Escape)
                        {
                            fieldSettings.c = (SerializableColor)(Color)fieldSettings.InActive();
                            e.Use();
                        }
                    }

                    //draw the color picker window
                    colorPickerStyle = GUI.skin.FindStyle("ColorPicker");
                    {
                        Rect localColorPickerRect = new Rect(Vector2.zero, new Vector2(colorPickerWidth, colorPickerHeight));
                        GUILayout.Label(colorPickerTexture, GUILayout.Width(150), GUILayout.Height(150));

                        Vector2 colorPickerMousePosition = e.mousePosition - new Vector2(colorPickerStyle.padding.left + 1, colorPickerStyle.padding.top + 5);

                        if (colorPickerMousePosition.x >= 0 && colorPickerMousePosition.y >= 0 && colorPickerMousePosition.x <= 150 && colorPickerMousePosition.y <= 150)
                        {
                            if (e.type == EventType.MouseDown || e.type == EventType.MouseDrag)
                            {
                                Vector2 textureCoord        = colorPickerMousePosition * (colorPickerTexture.width / 150f);
                                textureCoord.y              = colorPickerTexture.height - textureCoord.y;
                                fieldSettings.c             = (SerializableColor)colorPickerTexture.GetPixel((int)textureCoord.x, (int)textureCoord.y);
                                fieldSettings.thumbPosition = colorPickerMousePosition + new Vector2(6, 9);
                            }
                        }

                        Rect colorPickerThumbRect = new Rect(fieldSettings.thumbPosition, new Vector2(8, 8));
                        GUI.DrawTexture(colorPickerThumbRect, colorPickerThumb);

                        byte r, g, b, a;
                        PWColorPalette.ColorToByte(fieldSettings.c, out r, out g, out b, out a);
                        EditorGUIUtility.labelWidth = 20;
                        r = (byte)EditorGUILayout.IntSlider("R", r, 0, 255);
                        g = (byte)EditorGUILayout.IntSlider("G", g, 0, 255);
                        b = (byte)EditorGUILayout.IntSlider("B", b, 0, 255);
                        a = (byte)EditorGUILayout.IntSlider("A", a, 0, 255);
                        fieldSettings.c             = (SerializableColor)PWColorPalette.ByteToColor(r, g, b, a);
                        EditorGUIUtility.labelWidth = 0;

                        EditorGUILayout.Space();

                        //hex field
                        int hex = PWColorPalette.ColorToHex(fieldSettings.c, false);                         //get color without alpha
                        EditorGUIUtility.labelWidth = 80;
                        EditorGUI.BeginChangeCheck();
                        string hexColor = EditorGUILayout.TextField("Hex color", hex.ToString("X6"));
                        if (EditorGUI.EndChangeCheck())
                        {
                            a = 255;
                        }
                        EditorGUIUtility.labelWidth = 0;
                        Regex reg = new Regex(@"[^A-F0-9 -]");
                        hexColor  = reg.Replace(hexColor, "");
                        hexColor  = hexColor.Substring(0, Mathf.Min(hexColor.Length, 6));
                        if (hexColor == "")
                        {
                            hexColor = "0";
                        }
                        hex             = int.Parse(a.ToString("X2") + hexColor, System.Globalization.NumberStyles.HexNumber);
                        fieldSettings.c = (SerializableColor)PWColorPalette.HexToColor(hex, false);

                        if (e.isMouse && localColorPickerRect.Contains(e.mousePosition))
                        {
                            e.Use();
                        }
                    }
                }, colorPickerWidth);
            }

            color = fieldSettings.c;

            //draw the icon
            Rect colorPreviewRect = iconRect;

            if (displayColorPreview)
            {
                int width = (int)rect.width;
                int colorPreviewPadding = 5;

                Vector2 prefixSize = Vector2.zero;
                if (prefix != null && !String.IsNullOrEmpty(prefix.text))
                {
                    prefixSize    = GUI.skin.label.CalcSize(prefix);
                    prefixSize.x += 5;                     //padding of 5 pixels
                    colorPreviewRect.position += new Vector2(prefixSize.x, 0);
                    Rect prefixRect = new Rect(iconRect.position, prefixSize);
                    GUI.Label(prefixRect, prefix);
                }
                colorPreviewRect.size = new Vector2(width - icColorSize - prefixSize.x - colorPreviewPadding, 16);
                iconRect.position    += new Vector2(colorPreviewRect.width + prefixSize.x + colorPreviewPadding, 0);
                iconRect.size         = new Vector2(icColorSize, icColorSize);
                EditorGUIUtility.DrawColorSwatch(colorPreviewRect, color);
            }

            //actions if clicked on/outside of the icon
            if (previewOnIcon)
            {
                GUI.color = color;
            }
            GUI.DrawTexture(iconRect, ic_color);
            GUI.color = Color.white;
            if (e.type == EventType.MouseDown && e.button == 0)
            {
                if (iconRect.Contains(e.mousePosition) || colorPreviewRect.Contains(e.mousePosition))
                {
                    fieldSettings.Active(color);
                    e.Use();
                }
                else if (fieldSettings.active)
                {
                    fieldSettings.InActive();
                    e.Use();
                }
            }
        }