예제 #1
0
    public static Texture DrawTextureFieldWithLabel(Rect rect, string label, int labelWidth, Texture field, bool required = false)
    {
        if (CanDraw == true)
        {
            if (required == true)
            {
                if (field == null)
                {
                    if (CanDraw == true)
                    {
                        var redRect = new Rect(rect);
                        redRect = SGT_RectHelper.ExpandPx(redRect, 1.0f, 1.0f, 1.0f, 1.0f);
                        GUI.DrawTexture(redRect, SGT_Helper.RedTexture);
                    }
                }
            }

            var labelRect = SGT_RectHelper.GetLeftPx(ref rect, labelWidth);

            EditorGUI.LabelField(labelRect, new GUIContent(label, string.Empty), EditorStyles.label);

            var newField = (Texture)EditorGUI.ObjectField(rect, field, typeof(Texture), false);

            FieldModified |= newField != field;
            field          = newField;
        }

        return(field);
    }
    public static SGT_ColourGradient Field(string handle, string tooltip, SGT_ColourGradient field, bool isField = true)
    {
        if (CanDraw == true && field != null)
        {
            var borderRect   = ReserveField(handle, tooltip);
            var gradientRect = SGT_RectHelper.RemovePx(borderRect, 3.0f);
            var borderStyle  = EditorStyles.objectFieldThumb;
            var overlayStyle = (GUIStyle)(EditorStyles.objectFieldThumb.name + "Overlay2");

            gradientRect.xMax -= 4.0f;

            var colours = field.CalculateColours(0.0f, 1.0f, 256);
            var texture = SGT_ColourGradient.AllocateTexture(256);

            for (var x = 0; x < 256; x++)
            {
                texture.SetPixel(x, 0, colours[x]);
            }

            texture.Apply();

            GUI.Box(borderRect, string.Empty, borderStyle);
            DrawTiledTexture(gradientRect, SGT_Helper.CheckerTexture);
            GUI.DrawTexture(gradientRect, texture);

            SGT_Helper.DestroyObject(texture);

            if (GUI.Button(borderRect, "Edit", overlayStyle) == true)
            {
                SGT_AuxWindow_ColourGradient.Create(field, isField);
            }
        }

        return(field);
    }
예제 #3
0
    private static SGT_MultiMesh MultiMeshFieldWithLabel(Rect rect, string label, int labelWidth, SGT_MultiMesh field, bool required = false)
    {
        if (CanDraw == true && field != null)
        {
            if (required == true)
            {
                if (field.ContainsSomething == false)
                {
                    var redRect = new Rect(rect);
                    redRect = SGT_RectHelper.ExpandPx(redRect, 1.0f, 1.0f, 1.0f, 1.0f);
                    GUI.DrawTexture(redRect, SGT_Helper.RedTexture);
                }
            }

            var labelRect = SGT_RectHelper.GetLeftPx(ref rect, labelWidth);

            EditorGUI.LabelField(labelRect, new GUIContent(label, string.Empty), EditorStyles.label);

            var curMesh = field.GetSharedMesh(0);
            var newMesh = (Mesh)EditorGUI.ObjectField(rect, curMesh, typeof(Mesh), false);

            if (curMesh != newMesh)
            {
                field.ReplaceAll(newMesh);
            }
        }

        return(field);
    }
 public static void DrawError(Rect r, bool error = true)
 {
     if (CanDraw == true && error == true)
     {
         var redRect = SGT_RectHelper.ExpandPx(r, 2.0f, 2.0f, 2.0f, 2.0f);
         GUI.DrawTexture(redRect, SGT_Helper.RedTexture);
     }
 }
예제 #5
0
    public static Vector2 DrawEditableVector2(Rect r, Vector2 o, bool isField = false)
    {
        var s = SGT_RectHelper.HorizontalSlice(r, 2, 2);
        var n = default(Vector2);

        n.x = EditorGUI.FloatField(s[0], o.x);
        n.y = EditorGUI.FloatField(s[1], o.y);

        MarkModified(n != o, isField); return(n);
    }
예제 #6
0
    public static Rect DrawHorizontalSliderThumb(Rect rect, float position)
    {
        rect        = SGT_RectHelper.RemoveRightPx(rect, 8.0f);
        rect.xMin  += rect.width * position;
        rect.width  = 16.0f;
        rect.height = 16.0f;

        GUI.Box(rect, string.Empty, GUI.skin.horizontalSliderThumb);

        return(rect);
    }
    public static Rect Reserve(float height = fieldHeight, bool indent = true)
    {
        var rect = EditorGUILayout.BeginVertical();

        {
            EditorGUILayout.LabelField(string.Empty, GUILayout.Height(height));
        }
        EditorGUILayout.EndVertical();

        rect = SGT_RectHelper.ExpandPx(rect, -5, -5, 0, 0);

        return(indent == true?Indent(rect) : rect);
    }
    public static void ReserveFieldRaw(out Rect left, out Rect right, float height = fieldHeight)
    {
        var rect = Reserve(height, false);

        left  = Indent(rect);
        right = SGT_RectHelper.RemoveLeftPx(rect, Mathf.Min(handleWidth, rect.width / 2 - 5));

        if (markError == true)
        {
            markError = false;

            DrawError(left);
        }
    }
    public static bool BeginToggleGroup(string handle, string tooltip, bool toggle)
    {
        if (CanDraw == true)
        {
            var handleRect = Reserve(fieldHeight);
            var toggleRect = SGT_RectHelper.GetLeftPx(ref handleRect, toggleWidth);

            EditorGUI.LabelField(handleRect, new GUIContent(handle, tooltip), EditorStyles.boldLabel);

            var newToggle = EditorGUI.Toggle(toggleRect, toggle);

            FieldModified |= newToggle != toggle;
            toggle         = newToggle;
        }

        BeginIndent(toggle);

        return(toggle);
    }
예제 #10
0
    public static SGT_SurfaceTexture Field(string handle, string tooltip, SGT_SurfaceTexture field, bool required = false)
    {
        if (CanDraw == true)
        {
            switch (field.Configuration)
            {
            case SGT_SurfaceConfiguration.Sphere:
            {
                field.SetTexture(ObjectField(handle, tooltip, field.GetTexture(0), required), 0);
            }
            break;

            case SGT_SurfaceConfiguration.Cube:
            {
                var rectP = ReserveField(handle, tooltip);
                var rectN = ReserveField();

                var pX = SGT_RectHelper.HorizontalSlice(rectP, 0.0f / 3.0f, 1.0f / 3.0f);
                var pY = SGT_RectHelper.HorizontalSlice(rectP, 1.0f / 3.0f, 2.0f / 3.0f);
                var pZ = SGT_RectHelper.HorizontalSlice(rectP, 2.0f / 3.0f, 3.0f / 3.0f);

                var nX = SGT_RectHelper.HorizontalSlice(rectN, 0.0f / 3.0f, 1.0f / 3.0f);
                var nY = SGT_RectHelper.HorizontalSlice(rectN, 1.0f / 3.0f, 2.0f / 3.0f);
                var nZ = SGT_RectHelper.HorizontalSlice(rectN, 2.0f / 3.0f, 3.0f / 3.0f);

                field.SetTexture(DrawTextureFieldWithLabel(pX, "X+", 25, field.GetTexture(CubemapFace.PositiveX), required), CubemapFace.PositiveX);
                field.SetTexture(DrawTextureFieldWithLabel(pY, "Y+", 25, field.GetTexture(CubemapFace.PositiveY), required), CubemapFace.PositiveY);
                field.SetTexture(DrawTextureFieldWithLabel(pZ, "Z+", 25, field.GetTexture(CubemapFace.PositiveZ), required), CubemapFace.PositiveZ);

                field.SetTexture(DrawTextureFieldWithLabel(nX, "X-", 25, field.GetTexture(CubemapFace.NegativeX), required), CubemapFace.NegativeX);
                field.SetTexture(DrawTextureFieldWithLabel(nY, "Y-", 25, field.GetTexture(CubemapFace.NegativeY), required), CubemapFace.NegativeY);
                field.SetTexture(DrawTextureFieldWithLabel(nZ, "Z-", 25, field.GetTexture(CubemapFace.NegativeZ), required), CubemapFace.NegativeZ);
            }
            break;
            }
        }

        return(field);
    }
예제 #11
0
    public static float GetHorizontalSliderAcross(Rect rect, float x)
    {
        rect = SGT_RectHelper.RemoveRightPx(rect, 8.0f);

        return(Mathf.Clamp01((x - rect.x - 4.0f) / rect.width));
    }
    public override void OnInspector()
    {
        var dragRect      = SGT_RectHelper.RemovePx(SGT_EditorGUI.Reserve(0.0f), 20.0f, 20.0f, 0.0f, 0.0f);
        var mousePosition = SGT_EditorGUI.GetHorizontalSliderAcross(dragRect, Event.current.mousePosition.x);

        // Draw alpha stuff
        if (Target.HasAlpha == true)
        {
            // Space for slider
            SGT_EditorGUI.Reserve(16.0f);

            var alphaNodes = Target.AlphaNodes;
            var alphaRect  = SGT_EditorGUI.Reserve(16.0f);
            var alphaRect2 = SGT_RectHelper.ExpandPx(alphaRect, 20.0f);

            alphaRect = SGT_RectHelper.RemovePx(alphaRect, 20.0f, 20.0f, 0.0f, 0.0f);

            SGT_EditorGUI.DrawHorizontalSlider(alphaRect);

            // Draw alpha nodes
            foreach (var node in alphaNodes)
            {
                bool selected = node == selectedAlphaNode;
                Rect thumb;

                if (selected == false || removeAlphaNode == false)
                {
                    SGT_EditorGUI.BeginFrozen(selected);
                    {
                        thumb = SGT_EditorGUI.DrawHorizontalSliderThumb(alphaRect, node.Position);
                    }
                    SGT_EditorGUI.EndFrozen();

                    if (selected == true)
                    {
                        var sliderRect = new Rect(0.0f, 0.0f, 40.0f, 16.0f);
                        sliderRect.center = new Vector2(thumb.x, thumb.yMin - 13.0f);

                        var oldAlpha = node.Alpha;

                        node.SetAlpha(Target, GUI.HorizontalSlider(sliderRect, node.Alpha, 0.0f, 1.0f));

                        SGT_EditorGUI.MarkModified(Mathf.Approximately(oldAlpha, node.Alpha) == false, IsField);
                    }
                }
            }

            // Handle event specific stuff
            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (alphaRect.Contains(Event.current.mousePosition) == true)
                {
                    selectedAlphaNode = Target.FindClosestAlphaNode(mousePosition);
                    removeAlphaNode   = false;

                    if (selectedAlphaNode != null)
                    {
                        var distance   = Mathf.Abs(selectedAlphaNode.Position - mousePosition);
                        var distancePx = distance * alphaRect.width;

                        if (distancePx > 20.0f)
                        {
                            selectedAlphaNode = Target.AddAlphaNode(1.0f, mousePosition);

                            SGT_EditorGUI.MarkModified(true, IsField);
                        }
                    }
                    else
                    {
                        selectedAlphaNode = Target.AddAlphaNode(1.0f, mousePosition);

                        SGT_EditorGUI.MarkModified(true, IsField);
                    }

                    if (selectedAlphaNode.Locked == true)
                    {
                        draggingAlphaNode = false;
                        selectedAlphaNode = null;
                    }
                    else
                    {
                        draggingAlphaNode = true;
                    }

                    Repaint();
                }
                break;

            case EventType.MouseUp:
                if (selectedAlphaNode != null && draggingAlphaNode == true && removeAlphaNode == true)
                {
                    Target.RemoveAlphaNode(selectedAlphaNode);

                    SGT_EditorGUI.MarkModified(true, IsField);
                }

                draggingAlphaNode = false;
                removeAlphaNode   = false;
                break;

            case EventType.MouseDrag:
                if (selectedAlphaNode != null && draggingAlphaNode == true)
                {
                    var oldPosition = selectedAlphaNode.Position;

                    selectedAlphaNode.SetPosition(Target, mousePosition);

                    SGT_EditorGUI.MarkModified(Mathf.Approximately(oldPosition, selectedAlphaNode.Position) == false, IsField);

                    // Dragged out?
                    removeAlphaNode = alphaRect2.Contains(Event.current.mousePosition) == false;

                    Repaint();
                }
                break;
            }
        }

        // Draw gradient
        {
            var gradientRect = SGT_EditorGUI.Reserve(50.0f);

            gradientRect = SGT_RectHelper.RemovePx(gradientRect, 20.0f, 20.0f, 0.0f, 0.0f);

            var colours = Target.CalculateColours(0.0f, 1.0f, 256);
            var texture = SGT_ColourGradient.AllocateTexture(256);

            for (var x = 0; x < 256; x++)
            {
                texture.SetPixel(x, 0, colours[x]);
            }

            texture.Apply();

            SGT_EditorGUI.DrawTiledTexture(gradientRect, SGT_Helper.CheckerTexture);
            GUI.DrawTexture(gradientRect, texture);

            SGT_Helper.DestroyObject(texture);
        }

        // Draw colour stuff
        {
            var colourNodes = Target.ColourNodes;
            var colourRect  = SGT_EditorGUI.Reserve(16.0f);
            var colourRect2 = SGT_RectHelper.ExpandPx(colourRect, 20.0f);

            colourRect = SGT_RectHelper.RemovePx(colourRect, 20.0f, 20.0f, 0.0f, 0.0f);

            SGT_EditorGUI.DrawHorizontalSlider(colourRect);

            // Draw colour keys
            foreach (var node in colourNodes)
            {
                bool selected = node == selectedColourNode;
                Rect thumb;

                if (selected == false || removeColourNode == false)
                {
                    SGT_EditorGUI.BeginFrozen(selected);
                    {
                        thumb = SGT_EditorGUI.DrawHorizontalSliderThumb(colourRect, node.Position);
                    }
                    SGT_EditorGUI.EndFrozen();

                    if (selected == true)
                    {
                        var pickerRect = new Rect(0.0f, 0.0f, 40.0f, 20.0f);
                        pickerRect.center = new Vector2(thumb.x, thumb.yMax + 15.0f);

                        var oldColour = node.Colour;

                        node.SetColour(Target, SGT_EditorGUI.DrawColourPicker(pickerRect, node.Colour));

                        SGT_EditorGUI.MarkModified(SGT_Helper.Approximately(oldColour, node.Colour) == false, IsField);
                    }
                }
            }

            // Handle clicking and dragging for the colour nodes
            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (colourRect.Contains(Event.current.mousePosition) == true)
                {
                    selectedColourNode = Target.FindClosestColourNode(mousePosition);

                    if (selectedColourNode != null)
                    {
                        var distance   = Mathf.Abs(selectedColourNode.Position - mousePosition);
                        var distancePx = distance * colourRect.width;

                        if (distancePx > 20.0f)
                        {
                            selectedColourNode = Target.AddColourNode(Color.white, mousePosition);

                            SGT_EditorGUI.MarkModified(true, IsField);
                        }
                    }
                    else
                    {
                        selectedColourNode = Target.AddColourNode(Color.white, mousePosition);

                        SGT_EditorGUI.MarkModified(true, IsField);
                    }

                    if (selectedColourNode.Locked == true)
                    {
                        draggingColourNode = false;
                    }
                    else
                    {
                        draggingColourNode = true;
                    }

                    Repaint();
                }
                break;

            case EventType.MouseUp:
                if (selectedColourNode != null && draggingColourNode == true && removeColourNode == true)
                {
                    Target.RemoveColourNode(selectedColourNode);

                    SGT_EditorGUI.MarkModified(true, IsField);
                }

                draggingColourNode = false;
                removeColourNode   = false;

                Repaint();
                break;

            case EventType.MouseDrag:
                if (selectedColourNode != null && draggingColourNode == true)
                {
                    var oldPosition = selectedColourNode.Position;

                    selectedColourNode.SetPosition(Target, mousePosition);

                    SGT_EditorGUI.MarkModified(Mathf.Approximately(oldPosition, selectedColourNode.Position) == false, IsField);

                    // Dragged out?
                    removeColourNode = colourRect2.Contains(Event.current.mousePosition) == false;

                    Repaint();
                }
                break;
            }
        }
    }