EditorBundle.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. [CustomEditor(typeof(Bundle))]
  8. public class EditorBundle : Editor
  9. {
  10. #region 变量
  11. public static Bundle Script;
  12. #endregion
  13. public void OnEnable()
  14. {
  15. Script = (Bundle) target;
  16. Bundle.Instance = Script;
  17. }
  18. public override void OnInspectorGUI()
  19. {
  20. base.OnInspectorGUI();
  21. if (GUILayout.Button("ClearTexture"))
  22. {
  23. for (int i = 0; i < Script.UiList.Count; i++)
  24. {
  25. Sprite sprite = Script.UiList[i] as Sprite;
  26. if (sprite == null)
  27. {
  28. Texture2D texture = Script.UiList[i] as Texture2D;
  29. if (texture != null)
  30. {
  31. Script.UiList.RemoveAt(i--);
  32. }
  33. }
  34. }
  35. for (int i = 0; i < Script.SceneList.Count; i++)
  36. {
  37. Sprite sprite = Script.SceneList[i] as Sprite;
  38. if (sprite == null)
  39. {
  40. Texture2D texture = Script.SceneList[i] as Texture2D;
  41. if (texture != null)
  42. {
  43. Script.SceneList.RemoveAt(i--);
  44. }
  45. }
  46. }
  47. }
  48. }
  49. public static void Tag()
  50. {
  51. //string path;
  52. //Bundle bundle;
  53. //AssetImporter assetImporter;
  54. //bundle = AssetDatabase.LoadAssetAtPath<Bundle>("Assets/Resource/Prefab/Object/DebugMode.prefab");
  55. //for (int i = 0; i < bundle.UiList.Count; i++)
  56. //{
  57. // path = AssetDatabase.GetAssetPath(bundle.UiList[i]);
  58. // assetImporter = AssetImporter.GetAtPath(path);
  59. // assetImporter.assetBundleName = "ui";
  60. //}
  61. //for (int i = 0; i < bundle.AtlasList.Count; i++)
  62. //{
  63. // path = AssetDatabase.GetAssetPath(bundle.AtlasList[i]);
  64. // assetImporter = AssetImporter.GetAtPath(path);
  65. // assetImporter.assetBundleName = "atlas";
  66. //}
  67. //for (int i = 0; i < bundle.EffectList.Count; i++)
  68. //{
  69. // path = AssetDatabase.GetAssetPath(bundle.EffectList[i]);
  70. // assetImporter = AssetImporter.GetAtPath(path);
  71. // assetImporter.assetBundleName = "effect";
  72. //}
  73. //for (int i = 0; i < bundle.AudioList.Count; i++)
  74. //{
  75. // path = AssetDatabase.GetAssetPath(bundle.AudioList[i]);
  76. // assetImporter = AssetImporter.GetAtPath(path);
  77. // assetImporter.assetBundleName = "audio";
  78. //}
  79. //for (int i = 0; i < bundle.SceneList.Count; i++)
  80. //{
  81. // path = AssetDatabase.GetAssetPath(bundle.SceneList[i]);
  82. // assetImporter = AssetImporter.GetAtPath(path);
  83. // assetImporter.assetBundleName = "scene";
  84. //}
  85. //for (int i = 0; i < bundle.ConfigList.Count; i++)
  86. //{
  87. // path = AssetDatabase.GetAssetPath(bundle.ConfigList[i]);
  88. // assetImporter = AssetImporter.GetAtPath(path);
  89. // assetImporter.assetBundleName = "config";
  90. //}
  91. //for (int i = 0; i < bundle.DiscardList.Count; i++)
  92. //{
  93. // path = AssetDatabase.GetAssetPath(bundle.DiscardList[i]);
  94. // assetImporter = AssetImporter.GetAtPath(path);
  95. // assetImporter.assetBundleName = "config";
  96. //}
  97. }
  98. [MenuItem("DashGame/Bundle/PackAndroid")]
  99. public static void PackAndroid()
  100. {
  101. Tag();
  102. string prefix = Application.streamingAssetsPath + "/Bundle/Android";
  103. BuildPipeline.BuildAssetBundles(prefix, BuildAssetBundleOptions.ForceRebuildAssetBundle, BuildTarget.Android);
  104. Move(prefix, BuildTarget.Android);
  105. }
  106. [MenuItem("DashGame/Bundle/PackIOS")]
  107. public static void PackIOS()
  108. {
  109. Tag();
  110. string prefix = Application.streamingAssetsPath + "/Bundle/IOS";
  111. BuildPipeline.BuildAssetBundles(prefix, BuildAssetBundleOptions.ForceRebuildAssetBundle, BuildTarget.iOS);
  112. Move(prefix, BuildTarget.iOS);
  113. }
  114. [MenuItem("DashGame/Bundle/PackWindows")]
  115. public static void PackWindows()
  116. {
  117. Tag();
  118. string prefix = Application.streamingAssetsPath + "/Bundle/Windows";
  119. BuildPipeline.BuildAssetBundles(prefix, BuildAssetBundleOptions.ForceRebuildAssetBundle, BuildTarget.StandaloneWindows64);
  120. Move(prefix, BuildTarget.StandaloneWindows64);
  121. }
  122. private static void Move(string prefix, BuildTarget buildTarget)
  123. {
  124. List<string> names = new List<string>
  125. {
  126. "new_dress_tex",
  127. "new_dress_ske",
  128. "new_dress_config",
  129. "new_language_config",
  130. "new_flower_config",
  131. "new_flower_tex",
  132. };
  133. foreach (var name in names)
  134. {
  135. File.Delete($"{prefix}/HotUpdate/{name}");
  136. File.Delete($"{prefix}/HotUpdate/{name}.meta");
  137. File.Delete($"{prefix}/HotUpdate/{name}.manifest");
  138. File.Delete($"{prefix}/HotUpdate/{name}.manifest.meta");
  139. File.Move($"{prefix}/{name}", $"{prefix}/HotUpdate/{name}");
  140. File.Move($"{prefix}/{name}.manifest", $"{prefix}/HotUpdate/{name}.manifest");
  141. if (File.Exists($"{prefix}/{name}.meta"))
  142. {
  143. File.Move($"{prefix}/{name}.meta", $"{prefix}/HotUpdate/{name}.meta");
  144. }
  145. if (File.Exists($"{prefix}/{name}.manifest.meta"))
  146. {
  147. File.Move($"{prefix}/{name}.manifest.meta", $"{prefix}/HotUpdate/{name}.manifest.meta");
  148. }
  149. }
  150. string hotUpdateFolder = null;
  151. if (buildTarget == BuildTarget.Android)
  152. {
  153. hotUpdateFolder = Application.dataPath + "/HotUpdate/Android";
  154. }
  155. else if (buildTarget == BuildTarget.iOS)
  156. {
  157. hotUpdateFolder = Application.dataPath + "/HotUpdate/IOS";
  158. }
  159. else if (buildTarget == BuildTarget.StandaloneWindows64)
  160. {
  161. hotUpdateFolder = Application.dataPath + "/HotUpdate/Windows";
  162. }
  163. if (!string.IsNullOrEmpty(hotUpdateFolder))
  164. {
  165. foreach (var name in names)
  166. {
  167. byte[] bytes = File.ReadAllBytes($"{prefix}/HotUpdate/{name}");
  168. File.WriteAllBytes(hotUpdateFolder + "/" + name, bytes);
  169. }
  170. }
  171. AssetDatabase.Refresh();
  172. }
  173. }