private void Print(FluentNode node, TreeItemState treeItemState, bool isRoot = false)
    {
        if (node.HasChildren)
        {
            if (isRoot)
            {
                EditorGUILayout.BeginHorizontal();
                treeItemState.Expanded = EditorGUILayout.Foldout(treeItemState.Expanded, "Root", headerStyle) || pinAlwaysOpen;
                newPinAlwaysOpen       = EditorGUILayout.Toggle(pinAlwaysOpen);
                if (pinAlwaysOpen != newPinAlwaysOpen)
                {
                    pinAlwaysOpen = newPinAlwaysOpen;
                }
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                bool newExpandedState = EditorGUILayout.Foldout(treeItemState.Expanded, node.StringInEditor(), headerStyle) || pinAlwaysOpen;

                if (!newExpandedState)
                {
                    pinAlwaysOpen = false;
                }

                if (treeItemState.Expanded != newExpandedState)
                {
                    treeItemState.Expanded = newExpandedState;
                }
            }

            if (!treeItemState.Expanded)
            {
                return;
            }

            // Make sure the TreeItemState has enough children
            while (treeItemState.Children.Count < node.Children.Count)
            {
                treeItemState.Children.Add(new TreeItemState());
            }

            // Print all the children
            EditorGUILayout.BeginVertical();
            for (int iChild = 0; iChild < node.Children.Count; iChild++)
            {
                FluentNode    childNode  = node.Children[iChild];
                TreeItemState childState = treeItemState.Children[iChild];
                EditorGUI.indentLevel++;
                Print(childNode, childState);
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndVertical();
        }
        else
        {
            EditorGUILayout.LabelField(node.StringInEditor(), richTextStyle);
        }
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        headerStyle           = new GUIStyle(EditorStyles.foldout);
        headerStyle.fontStyle = FontStyle.Bold;
        headerStyle.richText  = true;

        keywordStyle = new GUIStyle(EditorStyles.label);
        keywordStyle.normal.textColor = Color.blue;

        errorStyle = new GUIStyle(EditorStyles.foldout);
        errorStyle.normal.textColor = Color.red;

        richTextStyle          = new GUIStyle(GUI.skin.label);
        richTextStyle.richText = true;

        FluentNode root = null;

        try
        {
            root = ((FluentScript)target).SequentialNode(((FluentScript)target).Create());
        }
        catch (Exception ex)
        {
            DisplayException("There was an exception creating dialogue tree in editor mode",
                             "This is expected if you have runtime dependant code in your FluentScript" + Environment.NewLine + Environment.NewLine,
                             ex);
            return;
        }

        // Print the tree
        try
        {
            if (rootTreeItemState == null || lastFluentScript != target)
            {
                rootTreeItemState = new TreeItemState();
                lastFluentScript  = (FluentScript)target;
            }

            Print(root, rootTreeItemState, true);
        }
        catch (Exception ex)
        {
            DisplayException("There was an exception trying to show you the tree, please report this", "", ex);
        }
    }
Beispiel #3
0
        private static void AddNode(Graph graph, FluentNode node)
        {
            var n = graph.AddNode(node.Id);

            n.LabelText = (((FluentUINode)node).Type == "method") ? ((FluentUINode)node).Name : (node.Id.Split('.').Last() + " Stage");
        }