ConditionalProcessorView.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor.Experimental.GraphView;
  5. using UnityEditor.UIElements;
  6. using UnityEngine.UIElements;
  7. using GraphProcessor;
  8. using NodeGraphProcessor.Examples;
  9. public class ConditionalProcessorView : PinnedElementView
  10. {
  11. ConditionalProcessor processor;
  12. BaseGraphView graphView;
  13. public ConditionalProcessorView() => title = "Conditional Processor";
  14. protected override void Initialize(BaseGraphView graphView)
  15. {
  16. processor = new ConditionalProcessor(graphView.graph);
  17. this.graphView = graphView;
  18. graphView.computeOrderUpdated += processor.UpdateComputeOrder;
  19. Button runButton = new Button(OnPlay) { name = "ActionButton", text = "Run" };
  20. Button stepButton = new Button(OnStep) { name = "ActionButton", text = "Step" };
  21. content.Add(runButton);
  22. content.Add(stepButton);
  23. }
  24. void OnPlay() => processor.Run();
  25. void OnStep()
  26. {
  27. BaseNodeView view;
  28. if (processor.currentGraphExecution != null)
  29. {
  30. // Unhighlight the last executed node
  31. view = graphView.nodeViews.Find(v => v.nodeTarget == processor.currentGraphExecution.Current);
  32. view.UnHighlight();
  33. }
  34. processor.Step();
  35. // Display debug infos, currentGraphExecution is modified in the Step() function above
  36. if (processor.currentGraphExecution != null)
  37. {
  38. view = graphView.nodeViews.Find(v => v.nodeTarget == processor.currentGraphExecution.Current);
  39. view.Highlight();
  40. }
  41. }
  42. }