static void MakeMetaDataJson(AssetBundleManifest manifest, string buildDataRoot) { // 依存関係面倒くさいから扱わない。でもサイズは欲しいので足したデータを作ってjsonで吐く var container = new Kayac.AssetBundleMetaDataContainer(); var names = manifest.GetAllAssetBundles(); // 名前でソート Array.Sort(names); container.items = new Kayac.AssetBundleMetaData[names.Length]; for (int i = 0; i < names.Length; i++) { var name = names[i]; var item = new Kayac.AssetBundleMetaData(); item.name = name; item.hash = manifest.GetAssetBundleHash(name).ToString(); var info = new FileInfo(buildDataRoot + "/" + name); item.size = (int)info.Length; container.items[i] = item; } var json = JsonUtility.ToJson(container); File.WriteAllText(Application.streamingAssetsPath + "/assetbundle_metadata.json", json); }
void Start() { // 設定。環境に合わせていじっていい #if UNITY_EDITOR _cachePath = Application.dataPath + "/../AssetBundleCache"; #else _cachePath = Application.persistentDataPath + "/AssetBundleCache"; #endif var metaDataJson = File.ReadAllText(Application.streamingAssetsPath + "/assetbundle_metadata.json"); var metaDataContainer = JsonUtility.FromJson <Kayac.AssetBundleMetaDataContainer>(metaDataJson); _metaData = metaDataContainer.items; #if false // 単純FileIO。最速なので、書き込み側オーバーヘッドの測定に用いる。 _root = "file://" + appPath + "/../AssetBundleBuild/"; #elif true // ローカルからのダウンロード。一応httpを経由させたい範囲で速度が欲しい時、簡易的に用いる。 _root = "http://localhost/~hirayama-takashi/AssetBundlePerformanceTestData/"; #else // 遠隔からのダウンロード。準備が必要。 _root = "https://hiryma.github.io/AssetBundlePerformanceTestData/"; #endif // 落とすサーバとファイルリストを上書き try { var customListPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/asset_bundle_performance_list.txt"; if (System.IO.File.Exists(customListPath)) { _errorText.text += "list file exists. path:" + customListPath; var file = new StreamReader(customListPath); _root = file.ReadLine(); // 1行目がサーバ。例えばhttp://localhost/~hirayama-takashi/hoge/" var tmpList = new List <string>(); while (!file.EndOfStream) // 2行目以降がassetBundleファイル名 { var line = file.ReadLine(); if (!string.IsNullOrEmpty(line)) { tmpList.Add(line + ".unity3d"); // リストに拡張子がついてるなら、あるいは拡張子なしなら抜いてください } } _metaData = new Kayac.AssetBundleMetaData[tmpList.Count]; for (int i = 0; i < tmpList.Count; i++) { _metaData[i] = new Kayac.AssetBundleMetaData(); _metaData[i].name = tmpList[i]; _metaData[i].hash = null; _metaData[i].size = 0; // 不明 } } else { _errorText.text += "no list file. path:" + customListPath; } } catch (System.Exception e) { _errorText.text += "error1: " + e.GetType(); } try { _shuffledMetaData = new Kayac.AssetBundleMetaData[_metaData.Length]; Array.Copy(_metaData, _shuffledMetaData, _metaData.Length); Shuffle(_shuffledMetaData); _log = new Kayac.FileLogHandler("log.txt"); _appendLog = new Kayac.FileLogHandler("appendLog.txt", append: true); _modeDropdown.ClearOptions(); var modeNames = System.Enum.GetNames(typeof(Mode)); foreach (var mode in modeNames) { var option = new Dropdown.OptionData(); option.text = mode; _modeDropdown.options.Add(option); } _modeDropdown.value = 0; _modeDropdown.captionText.text = modeNames[0]; _frametimeWatcher = new Kayac.FrameTimeWatcher(); } catch (System.Exception e) { _errorText.text += "error2: " + e.GetType(); } }