Пример #1
0
        private void OnDestroy()
        {
            // 销毁特效
            EffectContainers.ForEach(obj =>
            {
                if (obj != null)
                {
                    obj.Dispose();
                }
            });
            EffectContainers.Clear();
            foreach (var item in EffectDic)
            {
                if (item.Value != null)
                {
                    Queue <GameObject> queue = item.Value;
                    while (queue.Count > 0)
                    {
                        GameObject.Destroy(queue.Dequeue());
                    }
                }
            }
            EffectDic.Clear();

            // 资源释放
            foreach (var ab in ABDic)
            {
                ABLoader.UnLoadAB(ab.Value);
            }
            ABDic.Clear();
            ABDic = null;

            Disposables.Clear();
        }
Пример #2
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);
    }
Пример #3
0
        //private BundlesManager bundlesManager;

        /// <summary>
        /// 同步加载
        /// </summary>
        internal void Load()
        {
            if (this.LoadState == AssetLoadState.Loaded && this.AssetBundle != null)
            {
                return;
            }
            if (LoadState == AssetLoadState.Unloaded)
            {
                throw new VFSException("[TinaX.VFS] Error: Attempt to load an unloaded assetbundle :" + this.AssetBundleName);
            }


            LoadState = AssetLoadState.Loading; //其实这时候改没啥用
            if (LoadedPath.StartsWith("jar:file://", StringComparison.Ordinal))
            {
                this.AssetBundle = this.ABLoader.LoadAssetBundleFromAndroidStreamingAssets(this.LoadedPath, this.AssetBundleName, this.VirtualDiskPath);
            }
            else if (LoadedPath.StartsWith("http://", StringComparison.Ordinal) ||
                     LoadedPath.StartsWith("https://", StringComparison.Ordinal) ||
                     //LoadedPath.StartsWith("file://", StringComparison.Ordinal)||
                     LoadedPath.StartsWith("ftp://", StringComparison.Ordinal))
            {
                throw new VFSException("[TinaX.VFS] Error: Connot load from network sync");
            }
            else
            {
                this.AssetBundle = ABLoader.LoadAssetBundleFromFile(this.LoadedPath, this.AssetBundleName);
            }

            LoadState = AssetLoadState.Loaded;
        }
Пример #4
0
    IEnumerator Init(bool clearCache = true, bool useExManifet = false)
    {
        yield return(ABLoader.Stop());

#if UNITY_EDITOR
        ABLoader.UseEditorAsset = IsEditorTest();
#endif
        UseExManifest = useExManifet;
        //エラーのログを有効化
        ABLog.Level              = ABLog.LogLevel.Debug;
        ABLog.Enabled            = true;
        ABLog.EnabledAssert      = true;
        ABLoader.UnloadMode      = UnloadMode.Immediately;
        AutoUnloader.UnloadCycle = 2f;
        AutoUnloader.Pause       = false;

        ABLoader.MaxDownloadCount = 5;
        ABLoader.MaxLoadCount     = 10;

        var loadOperator = LoadOperator(useExManifet);
        if (UseCache() && clearCache && Directory.Exists(loadOperator.GetCacheRoot()))
        {
            Directory.Delete(loadOperator.GetCacheRoot(), true);
        }
        yield return(ABLoader.Initialize(loadOperator, null, (ex) => throw ex));
    }
Пример #5
0
    public static BaseLoaderElement CreateLoader(EnumResouceType type, string path)
    {
        BaseLoaderElement loader;

        switch (type)
        {
        case EnumResouceType.CACHE_BINARY:
            loader = new CacheBinaryLoader(path);
            break;

        case EnumResouceType.BINARY:
            loader = new BinaryLoader(path);
            break;

        case EnumResouceType.REMOTE_BINARY:
            loader = new RemoteBinaryLoader(path);
            break;

        case EnumResouceType.ASSETBUNDLE:
            loader = new ABLoader(path);
            break;

        default:
            loader = new BinaryLoader(path);
            break;
        }
        return(loader);
    }
Пример #6
0
    public IEnumerator LoadTest5()
    {
        //アセットを直接ロードする
        yield return(Init());

        GameObject asset = null;

        ABLoader.LoadAsset <GameObject>("prefabs", "Cube", (x) => asset = x, ex => throw ex);
        yield return(new WaitWhile(() => asset == null));

        Assert.IsNotNull(asset);
        //勝手にアンロードされる
        LoadedTest("materials/testmaterial", false);

        //非同期でも問題ない
        asset = null;
        ABLoader.LoadAssetAsync <GameObject>("prefabs", "Cylinder", (x) => asset = x, ex => throw ex);
        yield return(new WaitWhile(() => asset == null));

        Assert.IsNotNull(asset);
        LoadedTest("materials/testmaterial", false);

        //同じバンドルを二つ同時に呼んでも大丈夫
        asset = null;
        GameObject asset2 = null;

        ABLoader.LoadAsset <GameObject>("prefabs", "Cube", (x) => asset           = x, ex => throw ex);
        ABLoader.LoadAssetAsync <GameObject>("prefabs", "Cylinder", (x) => asset2 = x, ex => throw ex);
        yield return(new WaitWhile(() => asset == null || asset2 == null));

        Assert.IsNotNull(asset);
        Assert.IsNotNull(asset2);
        LoadedTest("materials/testmaterial", false);
    }
Пример #7
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);
    }
Пример #8
0
 void LoadSprites(List <Sprite> assets)
 {
     ABLoader.LoadAsset <Sprite>("sprites/circle", "Circle", (x) => assets.Add(x), ex => throw ex);
     ABLoader.LoadAsset <Sprite>("sprites/diamond", "Diamond", (x) => assets.Add(x), ex => throw ex);
     ABLoader.LoadAsset <Sprite>("sprites/hexagon", "Hexagon", (x) => assets.Add(x), ex => throw ex);
     ABLoader.LoadAsset <Sprite>("sprites/polygon", "Polygon", (x) => assets.Add(x), ex => throw ex);
     ABLoader.LoadAsset <Sprite>("sprites/triangle", "Triangle", (x) => assets.Add(x), ex => throw ex);
 }
Пример #9
0
    private void LoadManifest_Completed(ABAsyncOperationHandle <ABManagerCore.ABManifest> obj)
    {
        ABLoader loader    = new ABLoader();
        var      operation = ABLoader.LoadBundle(obj.Result.Bundles[0], obj.Result);

        operation.Completed += LoadBundle_Completed;
        StartCoroutine(operation);
    }
Пример #10
0
 public void LoadManifest()
 {
     if (!string.IsNullOrEmpty(_remoteManifestPath))
     {
         var operation = ABLoader.LoadManifest(_remoteManifestPath);
         operation.Completed += LoadManifest_Completed;
         StartCoroutine(operation);
     }
 }
Пример #11
0
        /// <summary>
        /// 【代码产生器使用】 初始注册的调用
        /// </summary>
        /// <param name="abPath"></param>
        /// <typeparam name="T"></typeparam>
        /// <exception cref="Exception"></exception>
        public static void Register <T>(string abPath) where T : UIObject
        {
            var type = typeof(T);

            if (UIPrefabDic.ContainsKey(type))
            {
                throw new Exception("已存在对应的UI类型 : " + type);
            }
            UIPrefabDic.Add(type, ABLoader.LoadAB(abPath, false));
        }
Пример #12
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         ABLoader loader    = new ABLoader();
         var      operation = ABLoader.LoadManifest(url);
         operation.Completed += LoadManifest_Completed;
         StartCoroutine(operation);
     }
 }
Пример #13
0
    public void Initial(string bundleName, ABLoadProgress loadProgress)
    {
        this.bundleName   = bundleName;
        this.loadProgress = loadProgress;
        isLoadFinish      = false;
        abLoader          = new ABLoader(loadProgress, BundleLoadFinish);
        abLoader.SetBundleName(bundleName);
        string bundlePath = PathTool.GetWWWAssetBundlePath() + "/" + bundleName;

        abLoader.BundlePath = bundlePath;
    }
Пример #14
0
        public static void Initialize()
        {
            var windowsAB     = ABLoader.LoadAB("UI/UI_Windows");
            var windowsPrefab = windowsAB.Bundle.LoadAsset <GameObject>("UI_Windows");

            UIWindows = GameObject.Instantiate <GameObject>(windowsPrefab);
            GameObject.DontDestroyOnLoad(UIWindows);

            LayerRoot.Add(UILayer.bottom, UIWindows.transform.Find("Bottom"));
            LayerRoot.Add(UILayer.center, UIWindows.transform.Find("Center"));
            LayerRoot.Add(UILayer.cover, UIWindows.transform.Find("Cover"));
        }
Пример #15
0
        public static void CloseUI <UI_Object>(UI_Object ui) where UI_Object : UIObject
        {
            if (ui == null)
            {
                return;
            }
            var type = typeof(UI_Object);

            UIObjectList.Remove(ui as UIView);
            GameObject.Destroy(ui.gameObject);             // 此处销毁的时候,会执行UIObject里的OnDestroy

            ABLoader.UnLoadAB(UIPrefabDic[type]);
        }
Пример #16
0
    public IEnumerator LoadTest16() => TaskTest(async() =>
    {
        //ロード出来た
        var c = await ABLoader.Load("materials/testmaterial");
        Assert.IsNotNull(c);
        //コンテナからの非同期ロードも待てる
        var mat = await c.LoadAssetAsync <Material>("TestMaterial");
        Assert.IsNotNull(mat);

        //個別のアセットのロード
        var sprite = await ABLoader.LoadAsset <Sprite>("sprites/circle", "Circle");
        Assert.IsNotNull(sprite);
    });
Пример #17
0
 void Start()
 {
     mTrackableBehaviour = gameObject.GetComponent <TrackableBehaviour>();
     abloader            = gameObject.GetComponent <ABLoader>();
     if (abloader)
     {
         abloader.URLSet(mTrackableBehaviour.TrackableName);
     }
     if (mTrackableBehaviour)
     {
         mTrackableBehaviour.RegisterTrackableEventHandler(this);
     }
 }
Пример #18
0
        protected GameObject LoadPrefab(string path, string prefabName)
        {
            GameObject  ret       = null;
            ABContainer container = null;

            if (!ABDic.TryGetValue(path, out container))
            {
                container   = ABLoader.LoadAB(path);
                ABDic[path] = container;
            }

            container.Bundle.LoadAsset <GameObject>(name);
            return(ret);
        }
Пример #19
0
 public void LoadScenes()
 {
     RemoveScenes();
     if (_manifest != null && _manifest.Scenes != null)
     {
         var bundleInfo = _manifest.Bundles.FirstOrDefault(bundle => bundle.Name.Contains("all_scenes"));
         if (bundleInfo != null)
         {
             var operation = ABLoader.LoadBundle(bundleInfo, _manifest);
             operation.Completed += LoadBundleScenes_Completed;
             StartCoroutine(operation);
         }
     }
 }
Пример #20
0
    public IEnumerator LoadTest15()
    {
        //拡張マニフェストを利用する
        yield return(Init(useExManifet: true));

        if (!UseExManifest)
        {
            yield break;
        }
        string[] bundles = new string[] {
            "prefabs",
            "testscene",
            "sprites/circle",
            "sprites/diamond",
            "sprites/hexagon",
            "sprites/polygon",
            "sprites/triangle",
        };

        //サイズが取れている
        Assert.AreNotEqual(ABLoader.GetSize(bundles), bundles.Length);

        //CRCでのロードが出来る
        List <BundleContainerRef> refs = new List <BundleContainerRef>();

        for (int i = 0; i < bundles.Length; i++)
        {
            ABLoader.LoadContainer(bundles[i], (r) => refs.Add(r), ex => throw ex);
        }
        yield return(new WaitUntil(() => refs.Count == bundles.Length));

        //GUIDの参照からロードする
        var(bundle, name) = ABLoader.GetReference("083e98c42f9344e4a92b1871cc1b5e2b");
        Assert.AreEqual(bundle, "sprites/diamond");
        Assert.AreEqual(name, "Assets/IchioLib.ABLoader.Test/Tests/AssetBundles/Sprites/Diamond.png");
        Sprite sprite = null;

        ABLoader.LoadAsset <Sprite>(bundle, name, x => sprite = x, ex => throw ex);
        yield return(new WaitUntil(() => sprite != null));

        bool ret = false;

        var(length, progress) = ABLoader.DownloadByTags(new string[] { "Sprites" }, (r) => ret = r, ex => throw ex);
        yield return(new WaitUntil(() => ret));

        Assert.AreEqual(length, 6);
    }
Пример #21
0
    public IEnumerator LoadTest10()
    {
        if (!UseCache())
        {
            yield break;
        }

        //破損ファイルのロード
        yield return(Init());

        //ロード無効
        ABLoader.MaxLoadCount = 0;

        System.Exception error = null;
        ABLoader.LoadContainer("prefabs", (c) => c.Dispose(), ex => error = ex);
        yield return(new WaitForSeconds(1));

        CacheTest("prefabs", true);
        File.Delete(GetCachePath("prefabs"));

        //キャッシュがない状態でロード
        ABLoader.MaxLoadCount = 1;
        yield return(new WaitWhile(() => error == null));

        Assert.IsNotNull(error);

        ABLoader.MaxLoadCount = 0;
        error = null;
        ABLoader.LoadAsset <GameObject>("prefabs", "Cylinder", null, ex => error = ex);

        yield return(new WaitForSeconds(1));

        CacheTest("prefabs", true);

        //データ改ざん
        File.WriteAllText(GetCachePath("prefabs"), "error data");

        ABLoader.MaxLoadCount = 1;
        yield return(new WaitWhile(() => error == null));

        Assert.IsNotNull(error);
        //不正なキャッシュは消されている
        CacheTest("prefabs", false);
    }
Пример #22
0
    public IEnumerator LoadTest12()
    {
        if (!UseCache())
        {
            yield break;
        }

        //一括ダウンロードエラーハンドリング
        yield return(Init());

        string[] names = new string[]
        {
            "prefabs",
            "testscene",
            "sprites/circle",
            "sprites/diamond",
            "sprites/hexagon",
            "sprites/polygon",
            "sprites/triangle",
            "error_data1",
            "error_data2",
        };

        ABLog.EnabledAssert = false;
        bool complete = false;
        bool ret      = false;
        List <System.Exception> errors = new List <System.Exception>();
        var progress = ABLoader.Download(names, r => { ret = r; complete = true; }, ex => errors.Add(ex));

        yield return(new WaitWhile(() => !complete));

        //全体は失敗
        Assert.IsFalse(ret);
        //エラーは2個
        Assert.AreEqual(errors.Count, 2);

        foreach (var name in names)
        {
            bool error = name.Contains("error");
            CacheTest(name, !error);
            LoadedTest(name, false);
        }
    }
Пример #23
0
    public IEnumerator LoadTest17() => TaskTest(async() =>
    {
        //エディタモードではテストしない
        if (IsEditorTest())
        {
            return;
        }

        //エラーのリトライのハンドリング
        System.Exception error = null;
        var loading            = ABLoader.Load("dummy");
        loading.MaxRetryCount  = 10;
        int retry           = 0;
        loading.RetryHandle = (x, err, handle) =>
        {
            //リトライのフック
            retry++;
            handle(true);
        };
        loading.ErrorHandle += x => error = x;

        //Errorを無視しても完了する
        loading.IgnoreError = true;
        loading.ForceAwaiterCompleteIfError = true;

        try
        {
            //一旦、エラーを無視する
            LogAssert.ignoreFailingMessages = true;
            var c = await loading;
            LogAssert.ignoreFailingMessages = false;
            Assert.IsNull(c);
            Assert.IsNull(error);
            //エディタではリトライのエラーはないので
            Assert.AreEqual(retry, loading.MaxRetryCount);
        }
        finally
        {
            LogAssert.ignoreFailingMessages = false;
        }
    });
Пример #24
0
    IEnumerator TaskTest(System.Func <Task> action)
    {
        yield return(Init());

        try
        {
            var task = action();
            while (!task.IsCompleted)
            {
                yield return(null);
            }
            if (task.IsFaulted)
            {
                throw task.Exception;
            }
        }
        finally
        {
            ABLoader.Unload();
        }
    }
Пример #25
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();
    }
Пример #26
0
        public static UI_View CreateUIView <UI_View>(UILayer layer) where UI_View : UIView
        {
            var type      = typeof(UI_View);
            var container = UIPrefabDic[type];

            ABLoader.LoadAB(container);
            if (container.Bundle == null)
            {
                throw new NullReferenceException(string.Format("该路径下没有AB包: [{0}]", container.ABName));
            }
            var prefab = container.Bundle.LoadAsset <GameObject>(type.Name);

            if (prefab == null)
            {
                throw new NullReferenceException(string.Format("AB包中没有预制体:[{0}]", type.Name));
            }
            var itemObj = GameObject.Instantiate <GameObject>(prefab, LayerRoot[layer], false);
            var ret     = itemObj.AddComponent <UI_View>();

            UIObjectList.Add(ret);

            return(ret);
        }
Пример #27
0
        public static UI_Item CreateUIItem <UI_Item>(Transform parent) where UI_Item : UIItem
        {
            var type      = typeof(UI_Item);
            var container = UIPrefabDic[type];

            ABLoader.LoadAB(container);
            if (container.Bundle == null)
            {
                throw new NullReferenceException(string.Format("该路径下没有AB包: [{0}]", container.ABName));
            }
            var prefab = container.Bundle.LoadAsset <GameObject>(type.Name);

            if (prefab == null)
            {
                throw new NullReferenceException(string.Format("AB包中没有预制体:[{0}]", type.Name));
            }
            var itemObj = GameObject.Instantiate <GameObject>(prefab, parent, false);
            var ret     = itemObj.AddComponent <UI_Item>();

            UIObjectList.Add(ret);

            return(ret);
        }
Пример #28
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);
    }
Пример #29
0
    public IEnumerator LoadTest6()
    {
        if (!UseCache())
        {
            yield break;
        }
        //キャッシュ削除
        yield return(Init());

        GameObject asset = null;

        ABLoader.LoadAsset <GameObject>("prefabs", "Cube", (x) => asset = x, ex => throw ex);
        yield return(new WaitWhile(() => asset == null));

        Assert.IsNotNull(asset);
        CacheTest("prefabs", true);
        CacheTest("materials/testmaterial", true);
        CacheTest("_dummy", false);
        yield return(ABLoader.CacheClear());

        //キャッシュが削除されている
        CacheTest("prefabs", false);
        CacheTest("materials/testmaterial", false);
    }
Пример #30
0
        public static UIItem CreateUIItem(Type type, Transform parent)
        {
//			if (!(type is UIItem))
//				throw new Exception("必须继承语UIItem");
            var container = UIPrefabDic[type];

            ABLoader.LoadAB(container);
            if (container.Bundle == null)
            {
                throw new NullReferenceException(string.Format("该路径下没有AB包: [{0}]", container.ABName));
            }
            var prefab = container.Bundle.LoadAsset <GameObject>(type.Name);

            if (prefab == null)
            {
                throw new NullReferenceException(string.Format("AB包中没有预制体:[{0}]", type.Name));
            }
            var itemObj = GameObject.Instantiate <GameObject>(prefab, parent, false);
            var ret     = itemObj.AddComponent(type) as UIItem;

            UIObjectList.Add(ret);

            return(ret);
        }