AssetDatabaseABDataSource.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using UnityEngine;
  3. using UnityEditor;
  4. using UnityEngine.Assertions;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using UnityEditor.IMGUI.Controls;
  8. namespace AssetBundleBrowser.AssetBundleDataSource
  9. {
  10. internal class AssetDatabaseABDataSource : ABDataSource
  11. {
  12. public static List<ABDataSource> CreateDataSources()
  13. {
  14. var op = new AssetDatabaseABDataSource();
  15. var retList = new List<ABDataSource>();
  16. retList.Add(op);
  17. return retList;
  18. }
  19. public string Name {
  20. get {
  21. return "Default";
  22. }
  23. }
  24. public string ProviderName {
  25. get {
  26. return "Built-in";
  27. }
  28. }
  29. public string[] GetAssetPathsFromAssetBundle (string assetBundleName) {
  30. return AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
  31. }
  32. public string GetAssetBundleName(string assetPath) {
  33. var importer = AssetImporter.GetAtPath(assetPath);
  34. if (importer == null) {
  35. return string.Empty;
  36. }
  37. var bundleName = importer.assetBundleName;
  38. if (importer.assetBundleVariant.Length > 0) {
  39. bundleName = bundleName + "." + importer.assetBundleVariant;
  40. }
  41. return bundleName;
  42. }
  43. public string GetImplicitAssetBundleName(string assetPath) {
  44. return AssetDatabase.GetImplicitAssetBundleName (assetPath);
  45. }
  46. public string[] GetAllAssetBundleNames() {
  47. return AssetDatabase.GetAllAssetBundleNames ();
  48. }
  49. public bool IsReadOnly() {
  50. return false;
  51. }
  52. public void SetAssetBundleNameAndVariant (string assetPath, string bundleName, string variantName) {
  53. AssetImporter.GetAtPath(assetPath).SetAssetBundleNameAndVariant(bundleName, variantName);
  54. }
  55. public void RemoveUnusedAssetBundleNames() {
  56. AssetDatabase.RemoveUnusedAssetBundleNames ();
  57. }
  58. public bool CanSpecifyBuildTarget {
  59. get { return true; }
  60. }
  61. public bool CanSpecifyBuildOutputDirectory {
  62. get { return true; }
  63. }
  64. public bool CanSpecifyBuildOptions {
  65. get { return true; }
  66. }
  67. public bool BuildAssetBundles (ABBuildInfo info) {
  68. if(info == null)
  69. {
  70. Debug.Log("Error in build");
  71. return false;
  72. }
  73. var buildManifest = BuildPipeline.BuildAssetBundles(info.outputDirectory, info.options, info.buildTarget);
  74. if (buildManifest == null)
  75. {
  76. Debug.Log("Error in build");
  77. return false;
  78. }
  79. foreach(var assetBundleName in buildManifest.GetAllAssetBundles())
  80. {
  81. if (info.onBuild != null)
  82. {
  83. info.onBuild(assetBundleName);
  84. }
  85. }
  86. return true;
  87. }
  88. }
  89. }