SceneManifestController.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using XGame.Editor.Asset;
  2. using XGame.Framework.Asset;
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace XGame.Editor.Build.AssetBundles
  7. {
  8. internal class SceneManifestController
  9. {
  10. private SceneBundleCollector _sceneCollector;
  11. public SceneManifestController(SceneBundleCollector sceneCollector)
  12. {
  13. //_context = context;
  14. _sceneCollector = sceneCollector;
  15. }
  16. public bool GenerateManifest()
  17. {
  18. string sceneAssetBundleManifestPath = PathDefine.SceneAssetBundleManifestPath;//"Assets/KCAssetBundlesData/KCSceneAssetBundleManifest.asset";
  19. var sceneInfosSo = AssetDatabase.LoadAssetAtPath<SceneInfosSo>(sceneAssetBundleManifestPath);
  20. if (sceneInfosSo == null)
  21. {
  22. sceneInfosSo = ScriptableObject.CreateInstance<SceneInfosSo>();
  23. AssetDatabase.CreateAsset(sceneInfosSo, sceneAssetBundleManifestPath);
  24. }
  25. //bundle信息
  26. var sceneInfos = new List<SceneAssetInfo>();
  27. if (_sceneCollector.bundleBuildMap.Count > 0)
  28. {
  29. foreach (var keyValue in _sceneCollector.bundleBuildMap)
  30. {
  31. foreach (var assetName in keyValue.Value.assetNames)
  32. {
  33. var assetInfo = new SceneAssetInfo()
  34. {
  35. sceneName = System.IO.Path.GetFileNameWithoutExtension(assetName).ToLower(),
  36. assetName = assetName
  37. };
  38. sceneInfos.Add(assetInfo);
  39. }
  40. }
  41. //排序
  42. sceneInfos.Sort((a, b) => { return string.CompareOrdinal(a.assetName, b.assetName); });
  43. }
  44. //保存
  45. sceneInfosSo.sceneInfos = sceneInfos.ToArray();
  46. EditorUtility.SetDirty(sceneInfosSo);
  47. AssetDatabase.SaveAssets();
  48. BuildLog.Log("Save SceneBundleManifest.");
  49. AssetDatabase.Refresh();
  50. return true;
  51. }
  52. }
  53. }