DrawBezierLine() публичный статический Метод

public static DrawBezierLine ( Vector2 start, Vector2 startTangent, Vector2 end, Vector2 endTangent, Color color, float width, bool antiAlias, int segments ) : void
start Vector2
startTangent Vector2
end Vector2
endTangent Vector2
color Color
width float
antiAlias bool
segments int
Результат void
    void DrawLineBetweenNodes(Node n1, Node n2, Color?color = null)
    {
        var n1Rect       = CalculateAbsoluteRectForNode(n1);
        var n2Rect       = CalculateAbsoluteRectForNode(n2);
        var isOnSameLine = Mathf.Abs(n2Rect.x - n1Rect.x) < 40f;
        var side         = Mathf.Sign(n2Rect.x - n1Rect.x);

        var n1Point = n1Rect.center + Vector2.right * n1Rect.width * 0.5f * side;
        var n2Point = n2Rect.center - Vector2.right * n2Rect.width * 0.5f * side;

        if (isOnSameLine)
        {
            n2Point = n2Rect.center + Vector2.right * n2Rect.width * 0.5f * side;
        }

        Vector2 startHandle = n1Point;

        startHandle.x = n2Point.x;
        Vector2 endHandle = n2Point;

        endHandle.x = n1Point.x;

        Drawing.DrawBezierLine(n1Point, startHandle, n2Point, endHandle, Color.black * 0.5f, 3.0f, true, 12);
        Drawing.DrawLine(n2Point, n2Point + Vector2.left * 5f * side + Vector2.up * 3f, Color.black * 0.5f, 2.0f, true);
        Drawing.DrawLine(n2Point, n2Point + Vector2.left * 5f * side - Vector2.up * 3f, Color.black * 0.5f, 2.0f, true);


        Drawing.DrawBezierLine(n1Point, startHandle, n2Point, endHandle, color == null ? Color.white : color.Value, 1.0f, true, 24);
        Drawing.DrawLine(n2Point, n2Point + Vector2.left * 5f * side + Vector2.up * 3f, color == null ? Color.white : color.Value, 1.0f, true);
        Drawing.DrawLine(n2Point, n2Point + Vector2.left * 5f * side - Vector2.up * 3f, color == null ? Color.white : color.Value, 1.0f, true);
    }
Пример #2
0
        private void DrawCurveAuto(Vector2 begin, Vector2 end, Color color)
        {
            var segments = 24;
            var r        = Rect.MinMaxRect(begin.x, begin.y, end.x, end.y);
            var x_mid    = r.xMin + 0.5f * r.width;
            var p0       = new Vector2(r.xMin, r.yMin);
            var a0       = new Vector2(x_mid, r.yMin);
            var a1       = new Vector2(x_mid, r.yMax);
            var p1       = new Vector2(r.xMax, r.yMax);

            Drawing.DrawBezierLine(p0, a0, p1, a1, Color.black, 3.0f, true, segments);
            Drawing.DrawBezierLine(p0, a0, p1, a1, Color.black, 3.0f, true, segments);
            Drawing.DrawBezierLine(p0, a0, p1, a1, Color.black, 3.0f, true, segments);
            Drawing.DrawBezierLine(p0, a0, p1, a1, color, 2.0f, true, segments);
            Drawing.DrawBezierLine(p0, a0, p1, a1, color, 2.0f, true, segments);
            Drawing.DrawBezierLine(p0, a0, p1, a1, color, 2.0f, true, segments);
        }
Пример #3
0
 // mask == 1: foreground, mask == 2: background, mask == 3: both
 public static void curveFromTo(Rect wr, Rect wr2, Color color, Color shadow, int mask = 3)
 {
     if ((mask & 0x2) != 0)
     {
         Drawing.DrawBezierLine(
             new Vector2(wr.x + wr.width, wr.y + 3 + wr.height / 2),
             new Vector2(wr.x + wr.width + Mathf.Abs(wr2.x - (wr.x + wr.width)) / 2, wr.y + 3 + wr.height / 2),
             new Vector2(wr2.x, wr2.y + 3 + wr2.height / 2),
             new Vector2(wr2.x - Mathf.Abs(wr2.x - (wr.x + wr.width)) / 2, wr2.y + 3 + wr2.height / 2), shadow, 5, true, 20);
     }
     if ((mask & 0x1) != 0)
     {
         Drawing.DrawBezierLine(
             new Vector2(wr.x + wr.width, wr.y + wr.height / 2),
             new Vector2(wr.x + wr.width + Mathf.Abs(wr2.x - (wr.x + wr.width)) / 2, wr.y + wr.height / 2),
             new Vector2(wr2.x, wr2.y + wr2.height / 2),
             new Vector2(wr2.x - Mathf.Abs(wr2.x - (wr.x + wr.width)) / 2, wr2.y + wr2.height / 2), color, 2, true, 20);
     }
 }
Пример #4
0
    void OnGUILayoutLabel()
    {
        GUIStyle g = new GUIStyle(EditorStyles.textArea);

        //GUISkin gg = new GUISkin ();
        //GUI.skin.settings.selectionColor = Color.red;
        //
        GUI.skin.textArea.active.background = Texture2D.blackTexture;
        GUILayout.TextArea("TESTING", g);
        GUILayout.Box("BOX");

        //GUILayout.TextField(
        //EditorGUI.TextField(
        GUILayout.BeginHorizontal();
        GUIStyle gg = new GUIStyle(EditorStyles.whiteLabel);

        GUILayout.Label("Label F**K", gg, GUILayout.Width(Screen.width / 4));
        string firstname = GUILayout.TextField("Haha");

        GUILayout.EndHorizontal();

        EditorGUILayout.TextField("TEXTFIELD", "Text in field", GUILayout.Height(25));
        GUILayout.BeginVertical("Helpbox");
        GUILayout.BeginVertical("Box");
        GUILayout.Label("BoldLabel", EditorStyles.boldLabel);
        GUILayout.Label("CenteredGreyMiniLabel", EditorStyles.centeredGreyMiniLabel);
        GUILayout.Label("ColorField", EditorStyles.colorField);
        GUILayout.Label("Foldout", EditorStyles.foldout);
        GUILayout.Label("Foldoutpredrop", EditorStyles.foldoutPreDrop);
        GUILayout.Label("Label", EditorStyles.label);
        GUILayout.Label("Helpbox", EditorStyles.helpBox);
        GUILayout.Label("inspectordefaultmargins", EditorStyles.inspectorDefaultMargins);
        GUILayout.Label("Fullwidthmargins", EditorStyles.inspectorFullWidthMargins);
        GUILayout.Label("Largelabel", EditorStyles.largeLabel);
        GUILayout.Label("Layermaskfield", EditorStyles.layerMaskField);
        GUILayout.Label("minibuttonleft", EditorStyles.miniButtonLeft);
        GUILayout.Label("miniboldlabel", EditorStyles.miniBoldLabel);
        GUILayout.Label("minibutton", EditorStyles.miniButton);
        GUILayout.Label("minibuttonmid", EditorStyles.miniButtonMid);
        GUILayout.Label("minibuttonright", EditorStyles.miniButtonRight);
        GUILayout.Label("minilabel", EditorStyles.miniLabel);
        GUILayout.Label("minitextfield", EditorStyles.miniTextField);
        GUILayout.Label("numberfield", EditorStyles.numberField);
        GUILayout.Label("ObjectField", EditorStyles.objectField);
        GUILayout.Label("ObjectMiniThumb", EditorStyles.objectFieldMiniThumb);
        GUILayout.Label("ObjectFieldThumb", EditorStyles.objectFieldThumb);
        GUILayout.Label("Radio", EditorStyles.radioButton);
        GUILayout.Label("TextArea", EditorStyles.textArea);
        GUILayout.Label("TextField", EditorStyles.textField);
        GUILayout.Label("Toggle", EditorStyles.toggle);
        GUILayout.Label("ToggleGroup", EditorStyles.toggleGroup);
        GUILayout.Label("PopUP", EditorStyles.popup);
        GUILayout.Label("Toolbar", EditorStyles.toolbar);
        GUILayout.Label("ToolbarButton", EditorStyles.toolbarButton);
        GUILayout.Label("ToolbarDrop Down", EditorStyles.toolbarDropDown);
        GUILayout.Label("ToolbarPopUp", EditorStyles.toolbarPopup);
        GUILayout.Label("ToolbarTextField", EditorStyles.toolbarTextField);
        GUILayout.Label("WhiteBoldLabel", EditorStyles.whiteBoldLabel);
        GUILayout.Label("WhiteLabel", EditorStyles.whiteLabel);
        GUILayout.Label("WhiteLargeLabel", EditorStyles.whiteLargeLabel);
        GUILayout.Label("WhiteMiniLabel", EditorStyles.whiteMiniLabel);
        GUILayout.Label("WordWrappedLabel", EditorStyles.wordWrappedLabel);
        //GUILayout.Button ("Test", EditorStyles.miniButtonLeft, true);
        if (GUILayout.Button("Button Text", EditorStyles.miniButtonLeft))
        {
            Debug.Log("Yay");
        }
        GUILayout.EndVertical();
        GUILayout.EndVertical();
        Drawing.DrawCircle(new Vector2(200f, 200f), 100, Color.black, 5, true, 36, 1.0f);
        Drawing.DrawLine(Vector2.zero, new Vector2(400, 400), Color.red, 5, true, 1.0f);
        Drawing.DrawBezierLine(Vector2.zero, new Vector2(400, 150), new Vector2(600, 800), new Vector2(200, 500), Color.blue, 10, true, 24, 2.0f);
    }
Пример #5
0
    public void DrawZoomArea()
    {
        AIManager manager = AIManager.s_instance;

        // Start zoomed drawing using the dimensions of the menu section as bounds.
        EditorZoomArea.Begin(manager.m_zoom, new Rect(0.0f, manager.m_buttonBarHeight, position.width, position.height));

        // Mouse-down scrolling
        if (Event.current.type == EventType.mouseDown && Event.current.button == 2)
        {
            m_scrollStart = Event.current.mousePosition;
        }

        // These checks fire when I've bodged data during development
        if (manager.selectedTaskIndex == -1)
        {
            return;
        }
        if (manager.selectedTaskIndex >= manager.m_tasks.Count)
        {
            return;
        }


        AITask currentTask = manager.m_tasks[manager.selectedTaskIndex];

        //return;
        // Draw the temporary line when the user is making links

        /*
         *  if(manager.m_dragStart != null)
         *  {
         *      AIAction source = manager.m_dragStart;
         *
         *      Vector2 start = new Vector2(source.m_editorPosition.x + source.m_windowWidth + stateHandleSize.x / 2.0f + m_scrollOffset.x, source.m_editorPosition.y + source.m_lastBounds.y + m_scrollOffset.y + stateHandleSize.y / 2.0f);
         *      Vector2 end = Event.current.mousePosition;
         *
         *      Drawing.bezierLine(start, start + (Vector2.right * lineCurveScale), end, end + (new Vector2(-1.0f, 0.0f) * lineCurveScale), Color.red, 1.0f, true, 20);
         *  }
         */
        // TODO: Loads of these loops can be removed with decent layering
        // TODO: Only redraw when moved or connections changed!
        // Draw connections

        foreach (var action in currentTask.Actions)
        {
            float delta      = 1.0f / action.Outputs.Count;
            float currentVal = 0.0f;
            float expansion  = 30.0f;
            for (int index = 0; index < action.Outputs.Count; index++)
            {
                AIAction linkedAction = action.GetOutput(index);
                if (linkedAction != null)
                {
                    Vector2 start = new Vector2(action.m_editorPosition.x + action.Outputs[index].outputRect.x + action.Outputs[index].outputRect.width + 10, action.m_editorPosition.y + action.Outputs[index].outputRect.y + 10);
                    Vector2 end   = new Vector2(linkedAction.m_editorPosition.x - 5, linkedAction.m_editorPosition.y + linkedAction.m_lastBounds.height / 2.0f);

                    start.x += m_scrollOffset.x;
                    start.y += m_scrollOffset.y;

                    end.x += m_scrollOffset.x;
                    end.y += m_scrollOffset.y;

                    if (action == linkedAction)
                    {
                        Vector2 right    = start + (new Vector2(10.0f + (expansion * currentVal), 0.0f));
                        Vector2 rightTop = right;
                        rightTop.y = action.m_editorPosition.y + m_scrollOffset.y - 50 - (expansion * currentVal);

                        Vector2 leftTop = rightTop;
                        leftTop.x = end.x - 10.0f - (expansion * currentVal);

                        Vector2 left = leftTop;
                        left.y = end.y;

                        Drawing.DrawLine(start, right, Color.red, 1.0f, true);
                        Drawing.DrawLine(right, rightTop, Color.red, 1.0f, true);
                        Drawing.DrawLine(rightTop, leftTop, Color.red, 1.0f, true);
                        Drawing.DrawLine(leftTop, left, Color.red, 1.0f, true);
                        Drawing.DrawLine(left, end, Color.red, 1.0f, true);
                    }
                    else
                    {
                        Drawing.DrawBezierLine(start, start + (Vector2.right * lineCurveScale), end, end + (new Vector2(-1.0f, 0.0f) * lineCurveScale), Color.yellow, 1.0f, true, 20);
                    }
                }
                currentVal += delta;
            }
        }

        // input button checks
        foreach (var action in currentTask.Actions)
        {
            if (GUI.Button(new Rect(action.m_editorPosition.x - 10 + m_scrollOffset.x, action.m_editorPosition.y + action.m_lastBounds.height / 2.0f + m_scrollOffset.y - 5, 10, 10), "x"))
            {
                if (manager.m_dragAction != null)
                {
                    manager.m_dragAction.SetOutput(manager.m_dragAction.Outputs[manager.m_dragActionOutput].linkName, action);
                }
            }
        }
        //Debug.Log(currentTask.m_actiontest);
        // Clear drag events on left-mouse click
        if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
        {
            manager.m_dragAction = null;
        }

        // Show behaviour link output buttons
        foreach (var action in currentTask.Actions)
        {
            int index = 0;
            foreach (var output in action.Outputs)
            {
                GUI.depth = -1;
                if (GUI.Button(new Rect(action.m_editorPosition.x + action.Outputs[index].outputRect.x + action.Outputs[index].outputRect.width + m_scrollOffset.x + 5, action.m_editorPosition.y + action.Outputs[index].outputRect.y + m_scrollOffset.y + 5, 10, 10), "x"))
                {
                    action.SetOutput(output.linkName, null);
                    manager.m_dragAction       = action;
                    manager.m_dragActionOutput = index;
                }
                index++;
            }
        }

        GUI.depth = 1;


        // Draw nodes
        BeginWindows();

        for (int i = 0; i < currentTask.Actions.Count; i++)
        {
            Rect currentPos = currentTask.Actions[i].m_editorPosition;
            currentPos.x += m_scrollOffset.x;
            currentPos.y += m_scrollOffset.y;

            string name = currentTask.Actions[i].Name;

            Rect thing = GUILayout.Window(i, currentPos, DrawActionWindow, name);

            currentTask.Actions[i].m_editorPosition = thing;

            currentTask.Actions[i].m_editorPosition.x -= m_scrollOffset.x;
            currentTask.Actions[i].m_editorPosition.y -= m_scrollOffset.y;

            if (Event.current.type == EventType.repaint)
            {
                currentTask.Actions[i].m_windowWidth = thing.width;
                currentTask.Actions[i].m_lastBounds  = thing;
            }
        }

        EndWindows();

        // I have no idea why, but this nukes drag-scrolling if it's near the top of the function
        if (Event.current.type == EventType.mouseDrag)
        {
            if (Event.current.button == 2)
            {
                m_scrollOffset += (Event.current.mousePosition - m_scrollStart) / 2.0f;
                m_scrollStart   = Event.current.mousePosition;
            }
        }

        if (Event.current.type == EventType.ScrollWheel)
        {
            manager.m_zoom -= ((float)Event.current.delta.y * 0.01f);

            manager.m_zoom = Mathf.Max(0.5f, manager.m_zoom);
            manager.m_zoom = Mathf.Min(1.0f, manager.m_zoom);
        }

        // This is pretty shonky, but keeps things smooth.
        // Disable if performance gets choppy and work out something better
        Repaint();

        EditorZoomArea.End();
    }