Пример #1
0
    private List <Rect> GetConnectionPointsRects(ConversationAction conversationAction)
    {
        List <Rect> rects = new List <Rect>();

        if (conversationAction.GetConnectionCount() > 0)
        {
            SerializedObject nodeSO = new SerializedObject(conversationAction);

            for (int i = 0; i < conversationAction.GetConnectionCount(); i++)
            {
                Rect rect = GetNodeRect(conversationAction);
                rect.x  = rect.max.x;
                rect.y += i * 25;
                rect.y += 5;

                if (conversationAction.GetConnectionCount() == 1)
                {
                    rect.y += 7;
                }

                rect.size = new Vector2(15, 15);
                rects.Add(rect);
            }
        }

        return(rects);
    }
Пример #2
0
    private Rect GetNodeRect(ConversationAction conversationAction)
    {
        SerializedObject   nodeSO           = new SerializedObject(conversationAction);
        SerializedProperty positionProperty = nodeSO.FindProperty("_uiPosition");

        int height = 40;

        if (conversationAction.GetConnectionCount() > 1)
        {
            height = conversationAction.GetConnectionCount() * 25;
        }

        return(new Rect(positionProperty.vector2Value.x + _scrollPosition.x, positionProperty.vector2Value.y + _scrollPosition.y, 160, height));
    }
Пример #3
0
    private void DrawNode(ConversationAction conversationAction)
    {
        if (conversationAction.GetConnectionCount() > 0)
        {
            SerializedObject nodeSO = new SerializedObject(conversationAction);
            List <Rect>      connectionPointRects = GetConnectionPointsRects(conversationAction);

            for (int i = 0; i < conversationAction.GetConnectionCount(); i++)
            {
                SerializedProperty connectionProperty = nodeSO.FindProperty(string.Format("_connections.Array.data[{0}]", i));
                SerializedProperty idProperty         = connectionProperty.FindPropertyRelative("id");
                SerializedProperty actionProperty     = connectionProperty.FindPropertyRelative("connectedConversation");

                Rect connectionPointRect = connectionPointRects[i];

                connectionPointRect.x     -= 5;
                connectionPointRect.width += 5;

                GUI.color = new Color(0.6f, 0.6f, 0.6f);
                GUI.Box(connectionPointRect, "", _nodeStyle);

                if (actionProperty.objectReferenceValue != null && _allActions.Contains((ConversationAction)(actionProperty.objectReferenceValue)))
                {
                    ConversationAction otherAction = (ConversationAction)(actionProperty.objectReferenceValue);
                    Rect startRect = connectionPointRects[i];
                    Rect otherRect = GetNodeRect(otherAction);

                    startRect.width = 0;
                    startRect.x    += 15;
                    otherRect.width = 0;

                    Vector2 offset = new Vector2(Vector2.Distance(startRect.center, otherRect.center) / 2f,
                                                 (otherRect.center.y - startRect.center.y) / 2f);

                    Color bezierColor = new Color(0, 0, 0, 0.333f);
                    float bezierWidth = 3;

                    if (_selectedActions.Contains(conversationAction))
                    {
                        bezierColor = new Color(1, 1, 0, 1f);
                        bezierWidth = 5;
                    }
                    else if (_selectedActions.Contains(otherAction))
                    {
                        bezierColor = new Color(1, 1, 0, 1f);
                        bezierWidth = 5;
                    }

                    Handles.DrawBezier
                    (
                        startRect.center,
                        otherRect.center,
                        startRect.center + offset,
                        otherRect.center - offset,
                        bezierColor,
                        null,
                        bezierWidth
                    );

                    Rect breakNoodleRect = new Rect();
                    breakNoodleRect.size   = new Vector2(10, 10);
                    breakNoodleRect.center = (startRect.center + otherRect.center) / 2f;
                    GUI.color = new Color(1, 0, 0, 0.666f);

                    if (GUI.Button(breakNoodleRect, "", _nodeStyle))
                    {
                        if (Event.current.button == 0)
                        {
                            actionProperty.objectReferenceValue = null;
                            nodeSO.ApplyModifiedProperties();
                        }
                    }
                }

                GUI.color = conversationAction.GetTitleColor();
                Rect labelRect = connectionPointRects[i];
                labelRect.x    += 20;
                labelRect.width = 200;
                GUI.Label(labelRect, idProperty.stringValue);
            }
        }

        if (_selectedActions.Contains(conversationAction))
        {
            Color newColor = conversationAction.GetNodeColor();
            newColor.r -= 0.25f;
            newColor.g -= 0.25f;
            newColor.b -= 0.25f;
            GUI.color   = newColor;
        }
        else
        {
            GUI.color = conversationAction.GetNodeColor();
        }

        GUI.Box(GetNodeRect(conversationAction), conversationAction.name, _nodeStyle);
    }