The editor currently isn't showing the curves

i had the same kind of issue with the nodes not showing up and restarting fixed that however for the curves that is not the case here is the editor script

public class DialogueEditor : EditorWindow
{
    Dialogue selectedDialogue = null;
    GUIStyle nodeStyle;
    DialogueNode draggingNode = null;
    Vector2 draggingOffset;

    [MenuItem("Window/Dialogue Editor")]
    public static void ShowEditorWindow()
    {
        GetWindow(typeof(DialogueEditor), false, "Dialogue Editor");
    }

    [OnOpenAsset(1)]
    public static bool OnOpenAsset(int instanceID, int line)
    {
        Dialogue dialogue = EditorUtility.InstanceIDToObject(instanceID) as Dialogue;
        if (dialogue != null)
        {
            ShowEditorWindow();
            return true;
        }
        return false;
    }

    private void OnEnable()
    {
        Selection.selectionChanged += OnSelectionChanged;

        nodeStyle = new GUIStyle();
        nodeStyle.normal.background = EditorGUIUtility.Load("node0") as Texture2D;
        nodeStyle.normal.textColor = Color.white;
        nodeStyle.padding = new RectOffset(20, 20, 20, 20);
        nodeStyle.border = new RectOffset(12, 12, 12, 12);
    }

    private void OnSelectionChanged()
    {
        Dialogue newDialogue = Selection.activeObject as Dialogue;
        if (newDialogue != null)
        {
            selectedDialogue = newDialogue;
            Repaint();
        }
    }

    private void OnGUI()
    {
        if (selectedDialogue == null)
        {
            EditorGUILayout.LabelField("Hello World");
        }
        else
        {
            ProcessEvents();
            foreach (DialogueNode node in selectedDialogue.GetAllNodes())
            {
                DrawNode(node);
                DrawConnections(node);
            }
        }
    }

    private void ProcessEvents()
    {
        if (Event.current.type == EventType.MouseDown && draggingNode == null)
        {
            draggingNode = GetNodeAtPoint(Event.current.mousePosition);
            if (draggingNode != null)
            {
                draggingOffset = draggingNode.rect.position - Event.current.mousePosition;
            }
        }
        else if (Event.current.type == EventType.MouseDrag && draggingNode != null)
        {
            Undo.RecordObject(selectedDialogue, "Move Dialogue Node");
            draggingNode.rect.position = Event.current.mousePosition + draggingOffset;
            GUI.changed = true;
        }
        else if (Event.current.type == EventType.MouseUp && draggingNode != null)
        {
            draggingNode = null;
        }
    }

    private void DrawNode(DialogueNode node)
    {
        GUILayout.BeginArea(node.rect, nodeStyle);
        EditorGUI.BeginChangeCheck();

        EditorGUILayout.LabelField("Node:", EditorStyles.whiteLabel);
        string newText = EditorGUILayout.TextField(node.text);
        string newUniqueID = EditorGUILayout.TextField(node.uniqueID);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(selectedDialogue, "Update Dialogue Text");

            node.text = newText;
            node.uniqueID = newUniqueID;
        }


        GUILayout.EndArea();
    }

    private void DrawConnections(DialogueNode node)
    {
        Vector3 startPosition = new Vector2(node.rect.xMax, node.rect.center.y);
        foreach (DialogueNode childNode in selectedDialogue.GetAllChildren(node))
        {
            Vector3 endPosition = new Vector2(childNode.rect.xMin, childNode.rect.center.y);
            Vector3 controlPointOffset = new Vector2(100, 0);
            Handles.DrawBezier(startPosition, endPosition, startPosition + controlPointOffset, endPosition - controlPointOffset, Color.white, null, 4f);
        }
    }

    private DialogueNode GetNodeAtPoint(Vector2 point)
    {
        DialogueNode foundNode = null;
        foreach (DialogueNode node in selectedDialogue.GetAllNodes())
        {
            if (node.rect.Contains(point))
            {
                foundNode = node;
            }
        }
        return foundNode;
    }
}

Are there any error messages popping up?

I ended up fixing it I don’t remember what I did

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms