123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using System;
- using UnityEngine;
- using UnityEditor;
- using UnityEngine.Assertions;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEditor.IMGUI.Controls;
- namespace AssetBundleBrowser.AssetBundleDataSource
- {
- internal class AssetDatabaseABDataSource : ABDataSource
- {
- public static List<ABDataSource> CreateDataSources()
- {
- var op = new AssetDatabaseABDataSource();
- var retList = new List<ABDataSource>();
- retList.Add(op);
- return retList;
- }
- public string Name {
- get {
- return "Default";
- }
- }
- public string ProviderName {
- get {
- return "Built-in";
- }
- }
- public string[] GetAssetPathsFromAssetBundle (string assetBundleName) {
- return AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
- }
- public string GetAssetBundleName(string assetPath) {
- var importer = AssetImporter.GetAtPath(assetPath);
- if (importer == null) {
- return string.Empty;
- }
- var bundleName = importer.assetBundleName;
- if (importer.assetBundleVariant.Length > 0) {
- bundleName = bundleName + "." + importer.assetBundleVariant;
- }
- return bundleName;
- }
- public string GetImplicitAssetBundleName(string assetPath) {
- return AssetDatabase.GetImplicitAssetBundleName (assetPath);
- }
- public string[] GetAllAssetBundleNames() {
- return AssetDatabase.GetAllAssetBundleNames ();
- }
- public bool IsReadOnly() {
- return false;
- }
- public void SetAssetBundleNameAndVariant (string assetPath, string bundleName, string variantName) {
- AssetImporter.GetAtPath(assetPath).SetAssetBundleNameAndVariant(bundleName, variantName);
- }
- public void RemoveUnusedAssetBundleNames() {
- AssetDatabase.RemoveUnusedAssetBundleNames ();
- }
- public bool CanSpecifyBuildTarget {
- get { return true; }
- }
- public bool CanSpecifyBuildOutputDirectory {
- get { return true; }
- }
- public bool CanSpecifyBuildOptions {
- get { return true; }
- }
- public bool BuildAssetBundles (ABBuildInfo info) {
- if(info == null)
- {
- Debug.Log("Error in build");
- return false;
- }
- var buildManifest = BuildPipeline.BuildAssetBundles(info.outputDirectory, info.options, info.buildTarget);
- if (buildManifest == null)
- {
- Debug.Log("Error in build");
- return false;
- }
- foreach(var assetBundleName in buildManifest.GetAllAssetBundles())
- {
- if (info.onBuild != null)
- {
- info.onBuild(assetBundleName);
- }
- }
- return true;
- }
- }
- }
|