EditorBundle.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. using System.Collections;
  5. [CustomEditor(typeof(Bundle))]
  6. public class EditorBundle : Editor
  7. {
  8. #region 变量
  9. public static Bundle Script;
  10. #endregion
  11. public void OnEnable()
  12. {
  13. Script = (Bundle) target;
  14. Bundle.Instance = Script;
  15. }
  16. public override void OnInspectorGUI()
  17. {
  18. base.OnInspectorGUI();
  19. if (GUILayout.Button("ClearTexture"))
  20. {
  21. for (int i = 0; i < Script.UiList.Count; i++)
  22. {
  23. Sprite sprite = Script.UiList[i] as Sprite;
  24. if (sprite == null)
  25. {
  26. Texture2D texture = Script.UiList[i] as Texture2D;
  27. if (texture != null)
  28. {
  29. Script.UiList.RemoveAt(i--);
  30. }
  31. }
  32. }
  33. for (int i = 0; i < Script.SceneList.Count; i++)
  34. {
  35. Sprite sprite = Script.SceneList[i] as Sprite;
  36. if (sprite == null)
  37. {
  38. Texture2D texture = Script.SceneList[i] as Texture2D;
  39. if (texture != null)
  40. {
  41. Script.SceneList.RemoveAt(i--);
  42. }
  43. }
  44. }
  45. }
  46. }
  47. public static void Tag()
  48. {
  49. string path;
  50. Bundle bundle;
  51. AssetImporter assetImporter;
  52. bundle = AssetDatabase.LoadAssetAtPath<Bundle>("Assets/Resource/DebugMode.prefab");
  53. for (int i = 0; i < bundle.UiList.Count; i++)
  54. {
  55. path = AssetDatabase.GetAssetPath(bundle.UiList[i]);
  56. assetImporter = AssetImporter.GetAtPath(path);
  57. assetImporter.assetBundleName = "ui";
  58. }
  59. for (int i = 0; i < bundle.AtlasList.Count; i++)
  60. {
  61. path = AssetDatabase.GetAssetPath(bundle.AtlasList[i]);
  62. assetImporter = AssetImporter.GetAtPath(path);
  63. assetImporter.assetBundleName = "atlas";
  64. }
  65. for (int i = 0; i < bundle.EffectList.Count; i++)
  66. {
  67. path = AssetDatabase.GetAssetPath(bundle.EffectList[i]);
  68. assetImporter = AssetImporter.GetAtPath(path);
  69. assetImporter.assetBundleName = "effect";
  70. }
  71. for (int i = 0; i < bundle.AudioList.Count; i++)
  72. {
  73. path = AssetDatabase.GetAssetPath(bundle.AudioList[i]);
  74. assetImporter = AssetImporter.GetAtPath(path);
  75. assetImporter.assetBundleName = "audio";
  76. }
  77. for (int i = 0; i < bundle.SceneList.Count; i++)
  78. {
  79. path = AssetDatabase.GetAssetPath(bundle.SceneList[i]);
  80. assetImporter = AssetImporter.GetAtPath(path);
  81. assetImporter.assetBundleName = "scene";
  82. }
  83. for (int i = 0; i < bundle.ConfigList.Count; i++)
  84. {
  85. path = AssetDatabase.GetAssetPath(bundle.ConfigList[i]);
  86. assetImporter = AssetImporter.GetAtPath(path);
  87. assetImporter.assetBundleName = "config";
  88. }
  89. }
  90. [MenuItem("DashGame/Bundle/PackAndroid")]
  91. public static void PackAndroid()
  92. {
  93. Tag();
  94. BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath + "/Bundle/Android", BuildAssetBundleOptions.None, BuildTarget.Android);
  95. }
  96. [MenuItem("DashGame/Bundle/PackIOS")]
  97. public static void PackIOS()
  98. {
  99. Tag();
  100. BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath + "/Bundle/IOS", BuildAssetBundleOptions.None, BuildTarget.iOS);
  101. }
  102. [MenuItem("DashGame/Bundle/PackWindows")]
  103. public static void PackWindows()
  104. {
  105. Tag();
  106. BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath + "/Bundle/Windows", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
  107. }
  108. }