EditorBundle.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. "config",
  127. "new_dress_tex",
  128. "new_dress_ske",
  129. //"new_dress_config",
  130. //"new_language_config",
  131. //"new_flower_config",
  132. "new_flower_tex",
  133. };
  134. foreach (var name in names)
  135. {
  136. File.Delete($"{prefix}/HotUpdate/{name}");
  137. File.Delete($"{prefix}/HotUpdate/{name}.meta");
  138. File.Delete($"{prefix}/HotUpdate/{name}.manifest");
  139. File.Delete($"{prefix}/HotUpdate/{name}.manifest.meta");
  140. File.Move($"{prefix}/{name}", $"{prefix}/HotUpdate/{name}");
  141. File.Move($"{prefix}/{name}.manifest", $"{prefix}/HotUpdate/{name}.manifest");
  142. if (File.Exists($"{prefix}/{name}.meta"))
  143. {
  144. File.Move($"{prefix}/{name}.meta", $"{prefix}/HotUpdate/{name}.meta");
  145. }
  146. if (File.Exists($"{prefix}/{name}.manifest.meta"))
  147. {
  148. File.Move($"{prefix}/{name}.manifest.meta", $"{prefix}/HotUpdate/{name}.manifest.meta");
  149. }
  150. }
  151. string hotUpdateFolder = null;
  152. if (buildTarget == BuildTarget.Android)
  153. {
  154. hotUpdateFolder = Application.dataPath + "/HotUpdate/Android";
  155. }
  156. else if (buildTarget == BuildTarget.iOS)
  157. {
  158. hotUpdateFolder = Application.dataPath + "/HotUpdate/IOS";
  159. }
  160. else if (buildTarget == BuildTarget.StandaloneWindows64)
  161. {
  162. hotUpdateFolder = Application.dataPath + "/HotUpdate/Windows";
  163. }
  164. if (!string.IsNullOrEmpty(hotUpdateFolder))
  165. {
  166. foreach (var name in names)
  167. {
  168. byte[] bytes = File.ReadAllBytes($"{prefix}/HotUpdate/{name}");
  169. File.WriteAllBytes(hotUpdateFolder + "/" + name, bytes);
  170. }
  171. }
  172. AssetDatabase.Refresh();
  173. }
  174. }