No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AssemblyOptionsSettings.cs 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace Unity.VisualScripting
  4. {
  5. public class AssemblyOptionsSettings
  6. {
  7. private const string CompleteLabel = "Regenerate Nodes";
  8. private readonly PluginConfigurationItemMetadata _assemblyOptionsMetadata;
  9. private bool _showAssembly = false;
  10. private const string TitleAssembly = "Node Library";
  11. private const string DescriptionAssembly = "Choose the assemblies in which you want to look for nodes.\n"
  12. + "By default, all project and Unity assemblies are included.\n"
  13. + "Unless you use a third-party plugin distributed as a DLL, you shouldn't need to change this.";
  14. private ProjectAssemblyOptionsListInspector _assemblyOptionsInspector;
  15. public AssemblyOptionsSettings(BoltCoreConfiguration coreConfig)
  16. {
  17. _assemblyOptionsMetadata = coreConfig.GetMetadata(nameof(coreConfig.assemblyOptions));
  18. _assemblyOptionsInspector = new ProjectAssemblyOptionsListInspector(_assemblyOptionsMetadata);
  19. }
  20. private static class Styles
  21. {
  22. public static readonly GUIStyle background;
  23. public static readonly GUIStyle defaultsButton;
  24. public const float OptionsWidth = 250;
  25. static Styles()
  26. {
  27. background = new GUIStyle(LudiqStyles.windowBackground);
  28. background.padding = new RectOffset(20, 20, 20, 20);
  29. defaultsButton = new GUIStyle("Button");
  30. defaultsButton.padding = new RectOffset(10, 10, 4, 4);
  31. }
  32. }
  33. public void OnGUI()
  34. {
  35. _showAssembly = EditorGUILayout.Foldout(_showAssembly, new GUIContent(TitleAssembly, DescriptionAssembly));
  36. if (_showAssembly)
  37. {
  38. GUILayout.BeginVertical(Styles.background, GUILayout.ExpandHeight(true));
  39. var height = _assemblyOptionsInspector.GetCachedHeight(Styles.OptionsWidth, GUIContent.none, null);
  40. EditorGUI.BeginChangeCheck();
  41. var position = GUILayoutUtility.GetRect(Styles.OptionsWidth, height);
  42. _assemblyOptionsInspector.Draw(position, GUIContent.none);
  43. if (EditorGUI.EndChangeCheck())
  44. {
  45. _assemblyOptionsMetadata.SaveImmediately(true);
  46. Codebase.UpdateSettings();
  47. }
  48. if (GUILayout.Button("Reset to Defaults", Styles.defaultsButton) && EditorUtility.DisplayDialog("Reset the Node Library", "Reset the Node Library to its default state?", "Reset to Default", "Cancel"))
  49. {
  50. _assemblyOptionsMetadata.Reset(true);
  51. _assemblyOptionsMetadata.SaveImmediately(true);
  52. }
  53. LudiqGUI.EndVertical();
  54. }
  55. if (GUILayout.Button(CompleteLabel, Styles.defaultsButton))
  56. {
  57. UnitBase.Rebuild();
  58. EditorUtility.DisplayDialog("Visual Script", "Regenerate Nodes completed", "OK");
  59. }
  60. }
  61. }
  62. }