AssemblyDefinitionsPage.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using UnityEditor;
  8. using UnityEngine;
  9. namespace TheraBytes.BetterUi.Editor
  10. {
  11. public class AssemblyDefinitionsPage : WizardPage
  12. {
  13. static readonly string[] ASMDEF_FILES =
  14. {
  15. "TheraBytes/BetterUI/Runtime/TheraBytes.BetterUi.Runtime.asmdef",
  16. "TheraBytes/BetterUI/Editor/TheraBytes.BetterUi.Editor.asmdef",
  17. "TheraBytes/BetterUI_TextMeshPro/Runtime/TheraBytes.BetterUi.asmref",
  18. "TheraBytes/BetterUI_TextMeshPro/Editor/TheraBytes.BetterUi.Editor.asmref",
  19. };
  20. const string TEXTMESH_PRO_PATH = "TheraBytes/BetterUI_TextMeshPro";
  21. const string PACKAGE_PATH_INCL_TMP = "TheraBytes/BetterUI/packages/asmdef_incl_TextMeshPro.unitypackage";
  22. const string PACKAGE_PATH_EXCL_TMP = "TheraBytes/BetterUI/packages/asmdef_excl_TextMeshPro.unitypackage";
  23. const string PERSISTENT_KEY = "asmdef";
  24. public override string NameId { get { return "AssemblyDefinitionsPage"; } }
  25. public AssemblyDefinitionsPage(IWizard wizard)
  26. : base(wizard)
  27. {
  28. }
  29. protected override void OnInitialize()
  30. {
  31. Add(new InfoWizardPageElement("Assembly Definition Files installation", InfoType.Header));
  32. // TextMesh Pro
  33. Add(new SeparatorWizardPageElement());
  34. Add(new InfoWizardPageElement("You can install Assembly Definition Files for Better UI here. " +
  35. "If you don't know what this is, you most likely don't want to install it."));
  36. Add(new SeparatorWizardPageElement());
  37. string mainAsmdefFilePath = Path.Combine(Application.dataPath, ASMDEF_FILES[0]);
  38. if (File.Exists(mainAsmdefFilePath))
  39. {
  40. // DELETE
  41. Add(new InfoWizardPageElement("Assembly Definition Files are already installed."));
  42. Add(new ValueWizardPageElement<string>(PERSISTENT_KEY,
  43. (o, v) =>
  44. {
  45. if(GUILayout.Button("Remove Assembly Definition Files"))
  46. {
  47. wizard.DoReloadOperation(this, () =>
  48. {
  49. foreach (string subPath in ASMDEF_FILES)
  50. {
  51. string filePath = Path.Combine(Application.dataPath, subPath);
  52. if (File.Exists(filePath))
  53. {
  54. File.Delete(filePath);
  55. }
  56. }
  57. AssetDatabase.Refresh();
  58. v = null;
  59. });
  60. }
  61. return v;
  62. }).MarkComplete());
  63. }
  64. else
  65. {
  66. // INSTALL
  67. Add(new ValueWizardPageElement<string>(PERSISTENT_KEY,
  68. (o, v) =>
  69. {
  70. if (GUILayout.Button("Install AssemblyDefinitions"))
  71. {
  72. string tmpPath = Path.Combine(Application.dataPath, TEXTMESH_PRO_PATH);
  73. string packageName = (Directory.Exists(tmpPath))
  74. ? PACKAGE_PATH_INCL_TMP
  75. : PACKAGE_PATH_EXCL_TMP;
  76. wizard.DoReloadOperation(this, () =>
  77. {
  78. AssetDatabase.ImportPackage(Path.Combine(Application.dataPath, packageName), false);
  79. v = packageName;
  80. });
  81. }
  82. return v;
  83. }).MarkComplete());
  84. }
  85. }
  86. }
  87. }