暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FlowGraphUnitUISample.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #if VISUAL_SCRIPT_INTERNAL
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Unity.VisualScripting;
  7. using UnityEditor;
  8. using UnityEngine;
  9. public class FlowGraphUnitUISample : RuntimeFlowGraph
  10. {
  11. [MenuItem("Tools/Visual Scripting/Internal/Create Node UI Samples", priority = LudiqProduct.DeveloperToolsMenuPriority + 403)]
  12. public static void CreateUnitUISamples()
  13. {
  14. (new FlowGraphUnitUISample()).CreateGraphUISample();
  15. }
  16. private void CreateGraphUISample()
  17. {
  18. CreateGraph();
  19. IEnumerable<Type> GetEventUnitTypes() => AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes().Where(t => typeof(IUnit).IsAssignableFrom(t))).Where(t => t.IsClass && !t.IsAbstract);
  20. Vector2 position = Vector2.zero;
  21. int index = 0;
  22. foreach (var unitType in GetEventUnitTypes())
  23. {
  24. try
  25. {
  26. string name = unitType.Assembly.GetName().Name;
  27. string space = unitType.FullName;
  28. var unit = Activator.CreateInstance(name, space);
  29. IUnit b = (IUnit)unit.Unwrap();
  30. b.position = position;
  31. if (index % 10 == 0)
  32. {
  33. position.x = 0;
  34. position.y += 180;
  35. }
  36. position.x += 180;
  37. AddUnit(b, position);
  38. index++;
  39. }
  40. catch (Exception e)
  41. {
  42. Debug.LogException(e);
  43. }
  44. }
  45. }
  46. }
  47. #endif