Beispiel #1
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);
    }
Beispiel #2
0
        public void Start(
            string downloadRoot,
            AssetFileDatabase database,
            int parallelDownloadCount     = 16,
            int downloadRetryCount        = 3,
            int timeoutSeconds            = 30,
            int fileWriteBufferSize       = 16 * 1024 * 1024,
            int downloadHandlerBufferSize = 16 * 1024)
        {
            if (IsStarted())
            {
                Debug.LogWarning("Kayac.Loader.Start() called twice.");
                return;
            }
            _storageCache.Start(database);
            _fileWriter = new FileWriter(
                _storageCache.root,
                StorageCache.temporaryFilePostfix,
                fileWriteBufferSize);

            _downloadRetryCount    = downloadRetryCount;
            _parallelDownloadCount = parallelDownloadCount;
            _timeoutSeconds        = timeoutSeconds;
            _database     = database;
            _downloadRoot = downloadRoot + "/";

            _downloadHandlerBuffers = new byte[_parallelDownloadCount][];
            for (int i = 0; i < _parallelDownloadCount; i++)
            {
                _downloadHandlerBuffers[i] = new byte[downloadHandlerBufferSize];
            }

            _assetHandles             = new Dictionary <string, AssetHandle>();
            _watchingAssetHandles     = new List <AssetHandle>();
            _memoryCachedAssetHandles = new LinkedList <AssetHandle>();

            _downloadHandles        = new Dictionary <string, DownloadHandle>();
            _waitingDownloadHandles = new LinkedList <DownloadHandle>();
            _goingDownloadHandles   = new DownloadHandle[_parallelDownloadCount];           // 固定的に取り、バッファとの対応を固定化する

            _fileHandles               = new Dictionary <string, FileHandle>();
            _watchingFileHandles       = new List <FileHandle>();
            _watchingFileHandleAddList = new List <FileHandle>();
        }