Exemple #1
0
        public void Update(
            Mode mode,
            Kayac.FileLogHandler log,
            ref int doneBytes,
            ref int doneFileCount)             // サンプルじゃなかったらこんな雑なrefの用法はしない
        {
            if (req != null)
            {
                var currentBytes = (int)req.downloadedBytes;
                if (req.error != null)
                {
                    Debug.LogError("Error: " + req.url + " " + req.error);
                    req.Dispose();
                    req       = null;
                    prevBytes = 0;
                    doneFileCount++;
                }
                else if (req.isDone)
                {
//					DumpResponse(log);
//					log.Write("End: " + path + " " + currentBytes);
                    if (mode == Mode.UwrSyncWrite)
                    {
//						log.Write("Write: " + path);
                        System.IO.File.WriteAllBytes(cachePath + "/" + path, req.downloadHandler.data);
                    }
                    else if (mode == Mode.UnityWebRequestAssetBundle)
                    {
                        // 一回取り出してやる必要がある?ない?よくわからない
                        var ab = DownloadHandlerAssetBundle.GetContent(req);
                        if (ab != null)
                        {
                            ab.Unload(true);
                        }
                    }
                    doneBytes += (currentBytes - prevBytes);
                    req.Dispose();
                    req       = null;
                    prevBytes = 0;
                    doneFileCount++;
                }
                else
                {
                    doneBytes += (currentBytes - prevBytes);
                    prevBytes  = currentBytes;
                }
            }

            if (writerHandle != null)
            {
                if (writerHandle.done)
                {
//					log.Write("WriteDone: " + path);
                    writerHandle = null;
                }
            }
        }
Exemple #2
0
    void Start()
    {
        _log = new Kayac.FileLogHandler("log.txt");
#if UNITY_EDITOR
        var storageCacheRoot = Application.dataPath;
#else
        var storageCacheRoot = Application.persistentDataPath;
#endif
        storageCacheRoot += "/../AssetFileCache";
        // キャッシュのスキャンはできるだけ早く始めた方が良い
        _loader = new Kayac.Loader(storageCacheRoot, useHashInStorageCache: true);

        _sb     = new System.Text.StringBuilder();
        _images = new RawImage[HandleCount];
        int   sqrtHandleCount = Mathf.FloorToInt(Mathf.Sqrt((float)HandleCount));
        float imageSize       = DeferenceScreenHeight / sqrtHandleCount;
        for (int i = 0; i < HandleCount; i++)
        {
            var go = new GameObject(i.ToString());
            _images[i] = go.AddComponent <RawImage>();
            var rect = _images[i].rectTransform;
            rect.anchorMin        = Vector2.zero;
            rect.anchorMax        = Vector2.zero;
            rect.pivot            = Vector2.zero;
            rect.sizeDelta        = Vector2.one * imageSize;
            rect.anchoredPosition = new Vector2(imageSize * (i / sqrtHandleCount), imageSize * (i % sqrtHandleCount));
            rect.SetParent(canvas.transform, false);
        }

        _database = new AssetFileDatabase();

        string downloadRoot;
        _fileList = new List <string>();
        if (!ReadAssetFileList(out downloadRoot))
        {
            for (int i = 1; i < FileCount; i++)
            {
                var path = string.Format("stamp_{0}.png", i);
                _fileList.Add(path);
            }
            downloadRoot = "file://" + Application.dataPath + "/../AssetBuild";
        }
        UpdateHashMap();

        if (downloadParallelCount < 1)
        {
            downloadParallelCount = 1;
        }
        // Databaseの準備ができたらロード可能にするためにStartを呼ぶ
        _loader.Start(
            downloadRoot,
            _database,
            downloadParallelCount);
        _loader.SetMemoryCacheLimit(this.memoryCacheLimitMB * 1024 * 1024);
        _loader.SetLoadLimit(this.loadLimitMB * 1024 * 1024);
    }
Exemple #3
0
        void DumpResponse(Kayac.FileLogHandler log)
        {
            var sb = new System.Text.StringBuilder();

            sb.AppendFormat("[ResponseHeader] {0} length:{1}\n", req.url, req.downloadedBytes);
            foreach (var item in req.GetResponseHeaders())
            {
                sb.AppendFormat("\t{0}: {1}\n", item.Key, item.Value);
            }
            log.Write(sb.ToString());
        }
Exemple #4
0
    void Start()
    {
        var database = new AssetBundleDatabase();

        var downloadRoot = "file:///" + Application.streamingAssetsPath + "/";

#if !USE_HANDLE_HOLDER
        _handles = new Kayac.LoadHandle[HandleCount];
#endif

        _loader = new Kayac.Loader(downloadRoot, database);
        // ログファイルへ
        _log   = new Kayac.FileLogHandler("log.txt");
        _texts = new UnityEngine.UI.Text[HandleCount];
        for (int i = 0; i < HandleCount; i++)
        {
            _texts[i] = Instantiate(_textPrefab, _textRoot, false);
        }
    }
Exemple #5
0
    void Start()
    {
        // 設定。環境に合わせていじっていい
        _cachePath = Application.dataPath;
#if !UNITY_EDITOR && UNITY_STANDALONE_OSX
        _cachePath += "/../..";      //MACはContentsの外まで戻す
#else
        _cachePath += "/..";         //Assetの横でいい
#endif
        _cachePath += "/AssetBundleCache";

        var metaDataJson      = File.ReadAllText(Application.streamingAssetsPath + "/assetbundle_metadata.json");
        var metaDataContainer = JsonUtility.FromJson <Kayac.AssetBundleMetaDataContainer>(metaDataJson);
        _metaData         = metaDataContainer.items;
        _shuffledMetaData = new Kayac.AssetBundleMetaData[_metaData.Length];
        Array.Copy(_metaData, _shuffledMetaData, _metaData.Length);
        Shuffle(_shuffledMetaData);

#if false   // 単純FileIO。最速なので、書き込み側オーバーヘッドの測定に用いる。
        _root = "file://" + Application.dataPath + "/../AssetBundleBuild/";
#elif false // ローカルからのダウンロード。一応httpを経由させたい範囲で速度が欲しい時、簡易的に用いる。
        _root = "http://localhost/~hirayama-takashi/AssetBundlePerformanceTestData/";
#else // 遠隔からのダウンロード。準備が必要。
        _root = "https://hiryma.github.io/AssetBundlePerformanceTestData/";
#endif

        // 落とすサーバとファイルリストを上書き
        try
        {
            var customListPath = Application.streamingAssetsPath + "/list.txt";
            if (System.IO.File.Exists(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].name = tmpList[i];
                    _metaData[i].hash = null;
                    _metaData[i].size = 0;                     // 不明
                }
            }
        }
        catch
        {
        }

        // 以下は初期化実コード
        _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();
    }