NodeCanvas Forums › General Discussion › Feature Suggestion – Find Task and Condition Usage
Hi,
we heavily use NodeCanvas in our game (shameless plug: http://www.emerge-game.com) and it’s sometimes hard to find where a specific Task or Condition has been used in all the different FSMs.
It would be great if it was possible to search for a specific Task or Condition and see exactly where it is used.
I hacked togehter a search function to find Tasks and highlight the nodes which use it but it has several limitations (doesn’t work for Conditions, can’t easily open the FSM where the task was found if it isn’t open already etc.)
It would be great if you could properly integrate something similar (but hopefully far better :D) into nodecanvas directly.
Feel free to use my code as a starting point.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
using NodeCanvas.Framework; using System.Diagnostics; using System.IO; using UnityEditor; using UnityEngine; using System.Linq; using NodeCanvas.StateMachines; using NodeCanvas.Editor; using System.Collections.Generic; using System; using ParadoxNotion.Design; public class SearchNodeCanvasGraph { [MenuItem("PZG/SearchNode")] static void SearchGraph() { Action<Type> TaskTypeSelected = (t) => { foreach (NodeCanvas.Framework.Graph item in GameObject.FindObjectsOfType<NodeCanvas.Framework.Graph>()) { HighlightStates(t, item); foreach (var subGraph in GetSubGraphs(item)) { HighlightStates(t, subGraph); } } }; Func<GenericMenu> GetMenu = () => { var menu = EditorUtils.GetTypeSelectionMenu(typeof(ActionTask), TaskTypeSelected); //if (Task.copiedTask != null && baseType.IsAssignableFrom(Task.copiedTask.GetType())) // menu.AddItem(new GUIContent(string.Format("Paste ({0})", Task.copiedTask.name)), false, () => { callback(Task.copiedTask.Duplicate(ownerSystem)); }); return menu; }; var label = "Search Action Tasks"; var m = GetMenu(); if (NodeCanvas.Editor.NCPrefs.useBrowser) { CompleteContextMenu.Show(GetMenu(), new Vector2(Screen.width / 2, Screen.height / 2), label, typeof(Task)); } else { m.ShowAsContext(); } } private static IEnumerable<Node> GetNodes(Graph graph) { var actionStates = graph.allNodes.Where(x => x is ActionState).ToList(); foreach (var subGraph in graph.allNodes.Where(x => x is NestedFSMState)) { actionStates.AddRange(GetNodes(((NestedFSMState)subGraph).nestedFSM)); } return actionStates; } private static IEnumerable<Graph> GetSubGraphs(Graph graph) { List<Graph> subGraphs = (graph.allNodes.Where(x => x is NestedFSMState).Select((x) => ((NestedFSMState)x).nestedFSM)).Cast<Graph>().ToList(); List<Graph> newSubGraphs = new List<Graph>(); foreach (var subGraph in subGraphs) newSubGraphs.AddRange(GetSubGraphs(subGraph)); subGraphs.AddRange(newSubGraphs); return subGraphs; } private static void HighlightStates(Type t, NodeCanvas.Framework.Graph item) { var actionStates = GetNodes(item);//item.allNodes.Where(x => x is ActionState); List<Node> nodes = actionStates.Where(y => ((ActionState)y).actionList.actions.Any(z => z.GetType() == t)).ToList(); if (nodes != null && nodes.Count > 0) { if (item == GraphEditor.currentGraph) Graph.multiSelection = nodes.Cast<object>().ToList(); foreach (var n in nodes) { UnityEngine.Debug.Log("Graph: " + item.name + " Node: " + n.name); } } } } |
Hey!
I’m very glad to know that you use NodeCanvas in your game 🙂
I’ve just added your request to the roadmap, in which by the way there are some other search capabilities as well.
Thanks a lot for your suggestion as well as your initial code.
I will try to implement this as soon as possible.
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh
Sorry if it was a duplicate request.
Where can I find the roadmap?
I meant in the personal roadmap 🙂 It’s not public (at least right now).
Your request was not duplicate. Nothing to be sorry about!
Join us on Discord: https://discord.gg/97q2Rjh