ETPackageCreateModule.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #if ODIN_INSPECTOR
  2. using System;
  3. using Sirenix.OdinInspector;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace ET.PackageManager.Editor
  7. {
  8. /// <summary>
  9. /// 一键生成属于自己的Package
  10. /// </summary>
  11. [ETPackageMenu("创建")]
  12. public class ETPackageCreateModule : BasePackageToolModule
  13. {
  14. [Button("文档", 30, Icon = SdfIconType.Link45deg, IconAlignment = IconAlignment.LeftOfText)]
  15. [PropertyOrder(-999)]
  16. public void OpenDocument()
  17. {
  18. ETPackageDocumentModule.ETPackageCreate();
  19. }
  20. public override void Initialize()
  21. {
  22. }
  23. public override void OnDestroy()
  24. {
  25. }
  26. [BoxGroup("生成类型", centerLabel: true)]
  27. [EnumToggleButtons]
  28. [HideLabel]
  29. public EPackageCreateType PackageCreateType = EPackageCreateType.All;
  30. [BoxGroup("Runtime引用类型", centerLabel: true)]
  31. [EnumToggleButtons]
  32. [HideLabel]
  33. [ShowIf("OnRuntimeRefTypeShowIf")]
  34. public EPackageRuntimeRefType RuntimeRefType = EPackageRuntimeRefType.All;
  35. private bool OnRuntimeRefTypeShowIf()
  36. {
  37. return PackageCreateType.HasFlag(EPackageCreateType.Runtime);
  38. }
  39. [BoxGroup("CodeMode类型", centerLabel: true)]
  40. [EnumToggleButtons]
  41. [HideLabel]
  42. [ShowIf("OnFolderTypeShowIf")]
  43. public EPackageCreateFolderType FolderType = EPackageCreateFolderType.All;
  44. private bool OnFolderTypeShowIf()
  45. {
  46. return PackageCreateType.HasFlag(EPackageCreateType.Hotfix) || PackageCreateType.HasFlag(EPackageCreateType.Model);
  47. }
  48. [Required]
  49. [LabelText("作者")]
  50. public string PackageAuthor;
  51. [Required]
  52. [LabelText("模块名称 cn.etetet.{0}")]
  53. public string PackageName;
  54. [InfoBox("模块ID 用于区分模块 1000以下为ET官方保有ID 其他ID请向ET官方申请")]
  55. [LabelText("模块ID")]
  56. public int PackageId;
  57. [Required]
  58. [InfoBox("推荐ET.{0} 也可以自定义")]
  59. [LabelText("显示名称")]
  60. public string DisplayName;
  61. [Required]
  62. [LabelText("程序集名称")]
  63. [ShowIf("OnRuntimeRefTypeShowIf")]
  64. public string AssemblyName;
  65. [LabelText("描述")]
  66. public string Description;
  67. [LabelText("强制创建")]
  68. public bool ForceCreate;
  69. private string PackagePath;
  70. [Button("创建", 50)]
  71. [GUIColor(0f, 1f, 0f)]
  72. [PropertyOrder(-999)]
  73. public void CreatePackage()
  74. {
  75. if ((int)PackageCreateType == 0)
  76. {
  77. UnityTipsHelper.Show("必须选择生成类型");
  78. return;
  79. }
  80. if (string.IsNullOrEmpty(PackageAuthor))
  81. {
  82. UnityTipsHelper.Show("必须输入 作者名称");
  83. return;
  84. }
  85. if (OnRuntimeRefTypeShowIf() && string.IsNullOrEmpty(AssemblyName))
  86. {
  87. UnityTipsHelper.Show("必须输入 程序集名称");
  88. return;
  89. }
  90. if (string.IsNullOrEmpty(DisplayName))
  91. {
  92. UnityTipsHelper.Show("必须输入 显示名称");
  93. return;
  94. }
  95. if (string.IsNullOrEmpty(PackageName))
  96. {
  97. UnityTipsHelper.Show("必须输入 模块名称");
  98. return;
  99. }
  100. PackagePath = ETPackageCreateHelper.GetPackagePath(ref PackageName);
  101. var projPath = EditorHelper.GetProjPath(PackagePath);
  102. if (!ETPackageCreateHelper.CreateDirectory(projPath, ForceCreate))
  103. {
  104. UnityTipsHelper.Show($"模块[ {PackageName} ] 已存在 请勿重复创建");
  105. return;
  106. }
  107. ETPackageCreateHelper.CreatePackage(
  108. new ETPackageCreateData
  109. {
  110. PackageAuthor = this.PackageAuthor,
  111. PackagePath = this.PackagePath,
  112. PackageId = this.PackageId,
  113. PackageName = this.PackageName,
  114. AssemblyName = this.AssemblyName,
  115. DisplayName = this.DisplayName,
  116. Description = this.Description,
  117. PackageCreateType = this.PackageCreateType,
  118. RuntimeRefType = this.RuntimeRefType,
  119. FolderType = this.FolderType,
  120. });
  121. UnityTipsHelper.Show($"创建成功 [ {PackageName} ]");
  122. PackageExecuteMenuItemHelper.ETAll();
  123. ETPackageAutoTool.CloseWindowRefresh();
  124. }
  125. }
  126. }
  127. #endif