Пример #1
0
    public IEnumerator LoadTest3()
    {
        //参照カウントが切れた際にアンロードされる
        yield return(Init());

        BundleContainerRef containerRef = null;

        ABLoader.LoadContainer("materials/testmaterial", (c) => c.Dispose(), ex => throw ex);
        ABLoader.LoadContainer("materials/testmaterial", (c) => containerRef = c, ex => throw ex);
        yield return(new WaitWhile(() => containerRef == null));

        Debug.Assert(containerRef.LoadAsset <Material>("TestMaterial") != null);
        LoadedTest("materials/testmaterial", true);
        containerRef.Dispose();
        LoadedTest("materials/testmaterial", false);

        //何度Disposeを実行しても有効なのは1度だけ
        containerRef = null;
        ABLoader.LoadContainer("materials/testmaterial", (c) => containerRef = c, ex => throw ex);
        ABLoader.LoadContainer("materials/testmaterial", (c) => { c.Dispose(); c.Dispose(); c.Dispose(); }, ex => throw ex);
        yield return(new WaitWhile(() => containerRef == null));

        LoadedTest("materials/testmaterial", true);
        containerRef.Dispose();
        LoadedTest("materials/testmaterial", false);
    }
Пример #2
0
    public IEnumerator LoadTest1()
    {
        //ロードテスト
        yield return(Init());

        BundleContainerRef containerRef = null;

        System.Exception exception = null;
        ABLoader.LoadContainer("prefabs", (c) => containerRef = c, e => exception = e);
        yield return(new WaitWhile(() => containerRef == null && exception == null));

        Debug.Assert(containerRef != null);
        Debug.Assert(exception == null, exception);
        Debug.Assert(containerRef.LoadAsset <GameObject>("Cube") != null);
        Debug.Assert(containerRef.LoadAsset <GameObject>("Cylinder") != null);
        Debug.Assert(containerRef.LoadAsset <GameObject>("Dummy") == null);
        containerRef?.Dispose();

        //キャッシュテスト
        yield return(Init(false));

        //ダウンロードさせない
        ABLoader.MaxDownloadCount = 0;
        //キャッシュがある場合はダウンロードしない
        containerRef = null;
        exception    = null;
        ABLoader.LoadContainer("prefabs", (c) => containerRef = c, e => exception = e);
        yield return(new WaitWhile(() => containerRef == null && exception == null));

        Debug.Assert(containerRef != null);
        Debug.Assert(exception == null, exception);
        Debug.Assert(containerRef.LoadAsset <GameObject>("Cube") != null);
    }
Пример #3
0
    public IEnumerator LoadTest2()
    {
        //成功コールバック内でDisposeしても正常にリファレスカウントが正常に動く
        yield return(Init());

        ABLoader.LoadContainer("prefabs", (c) => c.Dispose(), ex => throw ex);
        ABLoader.LoadContainer("prefabs", (c) => c.Dispose(), ex => throw ex);
        ABLoader.LoadContainer("prefabs", (c) => c.Dispose(), ex => throw ex);
        BundleContainerRef containerRef = null;

        ABLoader.LoadContainer("prefabs", (c) => containerRef = c, ex => throw ex);
        yield return(new WaitWhile(() => containerRef == null));

        Debug.Assert(containerRef.LoadAsset <GameObject>("Cube") != null);

        //ロード済みの際は即コールバックが実行される
        bool loaded = false;

        ABLoader.LoadContainer("prefabs", (c) => { c.Dispose(); loaded = true; }, ex => throw ex);
        Assert.IsTrue(loaded);

        containerRef.Dispose();
    }
Пример #4
0
    public IEnumerator LoadTest4()
    {
        //ロードのコールバックで例外が出た際は内部でDisposeが実行される
        yield return(Init());

        //ログの無効化
        ABLog.Enabled = false;

        //単発だと即時解放
        ABLoader.LoadContainer("materials/testmaterial", (c) => throw new System.Exception("test error"), ex => throw ex);
        LoadedTest("materials/testmaterial", false);

        //複数のコールバックでも正常に動く
        BundleContainerRef containerRef = null;

        ABLoader.LoadContainer("materials/testmaterial", (c) => containerRef = c, ex => throw ex);
        ABLoader.LoadContainer("materials/testmaterial", (c) => throw new System.Exception("test error"), ex => throw ex);
        yield return(new WaitWhile(() => containerRef == null));

        Debug.Assert(containerRef.LoadAsset <Material>("TestMaterial") != null);
        LoadedTest("materials/testmaterial", true);
        containerRef.Dispose();
        LoadedTest("materials/testmaterial", false);
    }
Пример #5
0
    public IEnumerator LoadTest14()
    {
        //オートアンロードテスト
        yield return(Init());

        ABLoader.UnloadMode      = UnloadMode.Auto;
        AutoUnloader.UnloadCycle = 0;
        BundleContainerRef containerRef = null;

        ABLoader.LoadContainer("materials/testmaterial", (c) => c.Dispose(), ex => throw ex);
        ABLoader.LoadContainer("materials/testmaterial", (c) => containerRef = c, ex => throw ex);
        yield return(new WaitWhile(() => containerRef == null));

        Debug.Assert(containerRef.LoadAsset <Material>("TestMaterial") != null);
        LoadedTest("materials/testmaterial", true);
        containerRef.Dispose();
        //オートモードでは即時解放されない
        LoadedTest("materials/testmaterial", true);
        yield return(null);

        yield return(null);

        //次のフレームで解放される
        LoadedTest("materials/testmaterial", false);

        //Unloaderを一旦無効にする
        AutoUnloader.Pause = true;
        System.WeakReference reference = null;
        //GCで回収される
        ABLoader.LoadContainer("materials/testmaterial", (c) => reference = new System.WeakReference(c), ex => throw ex);
        yield return(new WaitWhile(() => reference == null));

        LoadedTest("materials/testmaterial", true);
        while (reference.IsAlive)
        {
            yield return(null);

            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            yield return(null);
        }
        LoadedTest("materials/testmaterial", true);
        //手動で解放する
        ABLoader.Unload();
        LoadedTest("materials/testmaterial", false);


        reference = null;

        //GCで解放した後、再ダウンロードしても正常に動く
        ABLoader.LoadContainer("materials/testmaterial", (c) => reference = new System.WeakReference(c), ex => throw ex);
        yield return(new WaitWhile(() => reference == null));

        LoadedTest("materials/testmaterial", true);
        while (reference.IsAlive)
        {
            yield return(null);

            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            yield return(null);
        }
        LoadedTest("materials/testmaterial", true);
        yield return(null);

        //実際にはアンロードされていないので即時ロードされる
        ABLoader.LoadContainer("materials/testmaterial", (c) => containerRef = c, ex => throw ex);
        Assert.IsNotNull(containerRef);

        //解放されない
        ABLoader.Unload();
        LoadedTest("materials/testmaterial", true);
        //アンロード
        containerRef.Dispose();
        ABLoader.Unload();
        LoadedTest("materials/testmaterial", false);
    }
Пример #6
0
    public IEnumerator LoadTest9()
    {
        if (IsEditorTest())
        {
            yield break;
        }
        //unloadAllフラグを立てるとアセットもアンロードされる
        yield return(Init());

        BundleContainerRef containerRef = null;
        Material           mat          = null;

        ABLoader.LoadAsset <Material>("materials/testmaterial", "TestMaterial", (x) => mat = x, ex => throw ex);
        ABLoader.LoadContainer("materials/testmaterial", (c) => containerRef = c, ex => throw ex);
        yield return(new WaitWhile(() => containerRef == null));

        Assert.IsNotNull(mat);
        containerRef.SetUnloadAll(true);
        containerRef.Dispose();
        Assert.IsNull(mat);

        //依存関係も設定した場合
        containerRef = null;
        mat          = null;
        ABLoader.LoadAsset <Material>("materials/testmaterial", "TestMaterial", (x) => mat = x, ex => throw ex);
        ABLoader.LoadContainer("prefabs", (c) => containerRef = c, ex => throw ex);
        yield return(new WaitWhile(() => containerRef == null));

        Assert.IsNotNull(mat);
        containerRef.SetUnloadAll(true, true);
        containerRef.Dispose();
        Assert.IsNull(mat);


        //停止処理でアンロードされた場合
        containerRef = null;
        mat          = null;
        ABLoader.LoadAsset <Material>("materials/testmaterial", "TestMaterial", (x) => mat = x, ex => throw ex);
        ABLoader.LoadContainer("prefabs", (c) => containerRef = c, ex => throw ex);
        yield return(new WaitWhile(() => containerRef == null));

        Assert.IsNotNull(mat);
        containerRef.SetUnloadAll(true, true);

        //Disposeしていないコンテナを確保
        var nonDisposeRef = containerRef;

        yield return(ABLoader.Stop());

        Assert.IsNull(mat);

        yield return(Init());

        //後で設定したほうが優先される
        containerRef = null;
        mat          = null;
        ABLoader.LoadAsset <Material>("materials/testmaterial", "TestMaterial", (x) => mat = x, ex => throw ex);
        ABLoader.LoadContainer("prefabs", (c) => containerRef = c, ex => throw ex);
        yield return(new WaitWhile(() => containerRef == null));

        Assert.IsNotNull(mat);
        containerRef.SetUnloadAll(true, true);
        containerRef.SetUnloadAll(false, true);
        containerRef.Dispose();
        Assert.IsNotNull(mat);

        //コンテナの有効期間テスト
        containerRef = null;
        mat          = null;
        ABLoader.LoadAsset <Material>("materials/testmaterial", "TestMaterial", (x) => mat = x, ex => throw ex);
        ABLoader.LoadContainer("prefabs", (c) => containerRef = c, ex => throw ex);
        yield return(new WaitWhile(() => containerRef == null));

        Assert.IsNotNull(mat);
        Assert.IsFalse(nonDisposeRef.Disposed);
        nonDisposeRef.SetUnloadAll(true);
        nonDisposeRef.Dispose();

        //停止前のコンテナが無効化されている
        LoadedTest("prefabs", true);
        containerRef.Dispose();
        LoadedTest("prefabs", false);
        Assert.IsNotNull(mat);
    }