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.

ExportAssetsPopup.cs 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. namespace UnityEditor.U2D.Aseprite
  4. {
  5. internal class ExportAssetsPopup : EditorWindow
  6. {
  7. static class Content
  8. {
  9. public static readonly string titleText = L10n.Tr("Export Animation Assets");
  10. public static readonly string bodyText = L10n.Tr("Select which assets should be exported");
  11. public static readonly string controllerText = L10n.Tr("Animator Controller");
  12. public static readonly string clipsText = L10n.Tr("Animation Clips");
  13. public static readonly string exportText = L10n.Tr("Export");
  14. public static readonly string cancelText = L10n.Tr("Cancel");
  15. }
  16. const string k_SubElementUssClass = "SubElement";
  17. const string k_ControllerToggleId = "ControllerToggle";
  18. const string k_ClipsToggleId = "ClipsToggle";
  19. AsepriteImporterEditor m_ImporterEditor;
  20. AsepriteImporter[] m_ImporterTargets;
  21. Toggle m_ControllerToggle;
  22. Toggle m_ClipsToggle;
  23. void Awake()
  24. {
  25. titleContent = new GUIContent(Content.titleText);
  26. var size = new Vector2(300f, 110f);
  27. maxSize = size;
  28. minSize = size;
  29. }
  30. void OnSelectionChange()
  31. {
  32. Close();
  33. }
  34. public void ShowExportPopup(AsepriteImporterEditor importerEditor, AsepriteImporter[] importerTargets)
  35. {
  36. m_ImporterEditor = importerEditor;
  37. m_ImporterTargets = importerTargets;
  38. ShowPopup();
  39. }
  40. void CreateGUI()
  41. {
  42. var styleSheet = EditorGUIUtility.Load("packages/com.unity.2d.aseprite/Editor/Assets/UI/ExportAnimAssetsStyleSheet.uss") as StyleSheet;
  43. rootVisualElement.styleSheets.Add(styleSheet);
  44. var headerLabel = new Label(Content.bodyText)
  45. {
  46. name = "Header"
  47. };
  48. rootVisualElement.Add(headerLabel);
  49. m_ControllerToggle = new Toggle(Content.controllerText)
  50. {
  51. value = GetEditorPrefsBool(k_ControllerToggleId, true)
  52. };
  53. m_ControllerToggle.RegisterValueChangedCallback(x =>
  54. {
  55. SetEditorPrefsBool(k_ControllerToggleId, m_ControllerToggle.value);
  56. });
  57. m_ControllerToggle.AddToClassList(k_SubElementUssClass);
  58. rootVisualElement.Add(m_ControllerToggle);
  59. m_ClipsToggle = new Toggle(Content.clipsText)
  60. {
  61. value = GetEditorPrefsBool(k_ClipsToggleId, false)
  62. };
  63. m_ClipsToggle.RegisterValueChangedCallback(x =>
  64. {
  65. SetEditorPrefsBool(k_ClipsToggleId, m_ClipsToggle.value);
  66. });
  67. m_ClipsToggle.AddToClassList(k_SubElementUssClass);
  68. rootVisualElement.Add(m_ClipsToggle);
  69. var buttonArea = new VisualElement()
  70. {
  71. name = "ButtonArea"
  72. };
  73. rootVisualElement.Add(buttonArea);
  74. var cancelButton = new Button()
  75. {
  76. text = Content.cancelText
  77. };
  78. cancelButton.clicked += Close;
  79. buttonArea.Add(cancelButton);
  80. var exportButton = new Button()
  81. {
  82. text = Content.exportText
  83. };
  84. exportButton.clicked += () =>
  85. {
  86. var exportClips = m_ClipsToggle.value;
  87. var exportController = m_ControllerToggle.value;
  88. ImportUtilities.ExportAnimationAssets(m_ImporterTargets, exportClips, exportController);
  89. m_ImporterEditor.SaveChanges();
  90. Close();
  91. };
  92. buttonArea.Add(exportButton);
  93. }
  94. bool GetEditorPrefsBool(string id, bool defaultValue) => EditorPrefs.GetBool(GetType().Name + id, defaultValue);
  95. void SetEditorPrefsBool(string id, bool newValue) => EditorPrefs.SetBool(GetType().Name + id, newValue);
  96. }
  97. }