Last active
September 4, 2016 07:19
-
-
Save kou-yeung/c47ebc826a79f2e9279cb0889954ba00 to your computer and use it in GitHub Desktop.
EffekseerAssetBundleBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.IO; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class EffekseerAssetBundleBuilder | |
{ | |
#if UNITY_5 | |
// Bundles直下のディレクトリをAssetBundleとしてビルドする | |
[MenuItem("AssetBundles/Build by Effekseer")] | |
static void BuildAssetBundles() | |
{ | |
string bundleRoot = Application.dataPath + "/" + "Bundles"; | |
string[] bundlePaths = Directory.GetDirectories(bundleRoot, "*", SearchOption.TopDirectoryOnly); | |
var buildMap = new List<AssetBundleBuild>(); | |
foreach (var path in bundlePaths) | |
{ | |
var build = new AssetBundleBuild(); | |
build.assetBundleName = Path.GetFileName(path); | |
build.assetNames = (from asset in Directory.GetFiles(path, "*.*", SearchOption.AllDirectories) | |
where Path.GetExtension(asset) != ".meta" | |
select asset.Replace("\\", "/").Replace(Application.dataPath, "Assets") | |
).ToArray(); | |
buildMap.Add(build); | |
} | |
//AssetBundleを出力 | |
BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath, buildMap.ToArray(), BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); | |
} | |
#else | |
// Bundles直下のディレクトリをAssetBundleとしてビルドする | |
[MenuItem("AssetBundles/Build by Effekseer")] | |
static void BuildAssetBundles() | |
{ | |
string bundleRoot = Application.dataPath + "/" + "Bundles"; | |
string[] bundlePath = Directory.GetDirectories(bundleRoot, "*", SearchOption.TopDirectoryOnly); | |
AssetBundleBuild[] builds = new AssetBundleBuild[bundlePath.Length]; | |
for (int i = 0; i < bundlePath.Length; i++) | |
{ | |
builds[i] = new AssetBundleBuild(); | |
bundlePath[i] = bundlePath[i].Replace("\\", "/"); | |
string bundleName = Path.GetFileName(bundlePath[i]); | |
string[] assetPaths = Directory.GetFiles(bundlePath[i], "*.*", SearchOption.AllDirectories); | |
List<string> assetList = new List<string>(); | |
List<string> assetExtList = new List<string>(); | |
for (int j = 0; j < assetPaths.Length; j++) | |
{ | |
string path = assetPaths[j]; | |
if (Path.GetExtension(path) == ".meta") | |
{ | |
continue; | |
} | |
path = path.Replace("\\", "/"); | |
path = path.Replace(bundlePath[i] + "/", ""); | |
assetExtList.Add(Path.GetExtension(path)); | |
path = path.Substring(0, path.LastIndexOf(".")); | |
assetList.Add(path); | |
} | |
string[] assetNames = assetList.ToArray(); | |
string[] assetExts = assetExtList.ToArray(); | |
//Assetの配列を作成 | |
Object[] assets = new Object[assetNames.Length]; | |
for (int j = 0; j < assetNames.Length; j++) | |
{ | |
string path = "Assets/Bundles/" + bundleName + "/" + assetNames[j] + assetExts[j]; | |
assets[j] = AssetDatabase.LoadAssetAtPath( | |
path, typeof(UnityEngine.Object)); | |
Debug.Log(path); | |
} | |
//AssetBundleを出力 | |
string outputPath = Application.streamingAssetsPath + "/" + bundleName; | |
BuildPipeline.BuildAssetBundleExplicitAssetNames( | |
assets, assetNames, outputPath, | |
BuildAssetBundleOptions.ChunkBasedCompression); | |
} | |
} | |
#endif | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment