根據不同模式,從AssetBundle中獲取Asset或從Resources中獲取,两种加载方式同时实现的桥接类 读取一个文件的对象,不做拷贝和引用
Наследование: AbstractResourceLoader
Пример #1
0
        protected override void Init(string url, params object[] args)
        {
            base.Init(url, args);

            Path            = url;
            AssetFileBridge = AssetFileLoader.Load(Path, OnAssetLoaded);
        }
Пример #2
0
        protected override void Init(string url, params object[] args)
        {
            base.Init(url, args);

            _assetFileBridge = AssetFileLoader.Load(url, (isOk, asset) =>
            {
                if (IsReadyDisposed) // 中途释放
                {
                    OnFinish(null);
                    return;
                }
                if (!isOk)
                {
                    OnFinish(null);
                    Log.Error("[InstanceAssetLoader]Error on assetfilebridge loaded... {0}", url);
                    return;
                }

                try
                {
                    InstanceAsset = (GameObject)GameObject.Instantiate(asset as UnityEngine.GameObject);
                }
                catch (Exception e)
                {
                    Log.LogException(e);
                }

                if (Application.isEditor)
                {
                    KResoourceLoadedAssetDebugger.Create("AssetCopy", url, InstanceAsset);
                }

                OnFinish(InstanceAsset);
            });
        }
Пример #3
0
        private IEnumerator CoLoadSerializeMaterial()
        {
            var matLoadBridge = AssetFileLoader.Load(Url);

            while (!matLoadBridge.IsCompleted)
            {
                Progress = matLoadBridge.Progress;
                yield return(null);
            }

            var sMat = matLoadBridge.ResultObject as KSerializeMaterial;

            Debuger.Assert(sMat);

            Desc = sMat.ShaderName;

            Debuger.Assert(Mat == null);
            yield return(KResourceModule.Instance.StartCoroutine(CoGenerateMaterial(Url, sMat)));

            Debuger.Assert(Mat);

            matLoadBridge.Release(); //不需要它了

            if (Application.isEditor)
            {
                KResoourceLoadedAssetDebugger.Create("Material", Url, Mat);
            }
            OnFinish(Mat);
        }
Пример #4
0
 /// <summary>
 /// 编辑器模式下,对全部GameObject刷新一下Material
 /// </summary>
 private static void RefreshAllMaterialsShaders()
 {
     foreach (var renderer in GameObject.FindObjectsOfType <Renderer>())
     {
         AssetFileLoader.RefreshMaterialsShaders(renderer);
     }
 }
Пример #5
0
        public static StaticAssetLoader Load(string url, AssetFileLoader.AssetFileBridgeDelegate callback = null, LoaderMode loaderMode = LoaderMode.Async)
        {
            LoaderDelgate newCallback = null;
            if (callback != null)
            {
                newCallback = (isOk, obj) => callback(isOk, obj as UnityEngine.Object);
            }

            return AutoNew<StaticAssetLoader>(url, newCallback, false, loaderMode);
        }
Пример #6
0
        // TODO: 无视AssetName暂时!
        public static InstanceAssetLoader Load(string url, AssetFileLoader.AssetFileBridgeDelegate callback = null)
        {
            var loader = AutoNew<InstanceAssetLoader>(url, (ok, resultObject) =>
            {
                if (callback != null)
                    callback(ok, resultObject as UnityEngine.Object);
            }, true);

            return loader;
        }
Пример #7
0
 //仅仅是预加载,回调仅告知是否加载成功
 public static AssetFileLoader Preload(string path, System.Action <bool> callback = null)
 {
     return(AssetFileLoader.Load(path, (isOk, asset) =>
     {
         if (callback != null)
         {
             callback(isOk);
         }
     }));
 }
Пример #8
0
        //仅仅是预加载,回调仅告知是否加载成功
        public static IEnumerator CoPreload(string path, System.Action <bool> callback = null)
        {
            var w = AssetFileLoader.Load(path, null);

            while (!w.IsCompleted)
            {
                yield return(null);
            }

            if (callback != null)
            {
                callback(!w.IsError); // isOk?
            }
        }
Пример #9
0
        IEnumerator Start()
        {
            _assetFileBridge = AssetFileLoader.Load(_url, (bool isOk, UnityEngine.Object obj) => { },
                                                    _mode);

            while (!_assetFileBridge.IsCompleted)
            {
                yield return(null);
            }
            if (_assetFileBridge.IsError)
            {
                Log.Error("[SceneLoader]Load SceneLoader Failed(Error) when Finished: {0}", _url);
                _assetFileBridge.Release();
                OnFinish(null);
                yield break;
            }

            // load scene
            Debuger.Assert(_assetFileBridge.Asset);

            if (_mode == LoaderMode.Sync)
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene(_sceneName,
                                                                   UnityEngine.SceneManagement.LoadSceneMode.Additive);
            }

            else
            {
                var op = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(_sceneName, UnityEngine.SceneManagement.LoadSceneMode.Additive);
                while (!op.isDone)
                {
                    yield return(null);
                }
            }

            if (Application.isEditor)
            {
                KResourceModule.Instance.StartCoroutine(EditorLoadSceneBugFix(null));
            }

            OnFinish(_assetFileBridge);
        }
Пример #10
0
        protected override void Init(string path, params object[] args)
        {
            var loaderMode = (LoaderMode)args[0];

            base.Init(path, args);
            if (string.IsNullOrEmpty(path))
            {
                Log.Error("StaticAssetLoader 空资源路径!");
            }

            _assetFileLoader = AssetFileLoader.Load(path, (_isOk, _obj) =>
            {
                OnFinish(_obj);

                if (Application.isEditor)
                {
                    if (TheAsset != null)
                    {
                        KResoourceLoadedAssetDebugger.Create("StaticAsset", path, TheAsset);
                    }
                }
            }, loaderMode);
        }
Пример #11
0
 /// <summary>
 /// Load Async Asset Bundle
 /// </summary>
 /// <param name="path"></param>
 /// <param name="callback">cps style async</param>
 /// <returns></returns>
 public static AbstractResourceLoader LoadBundleAsync(string path, AssetFileLoader.AssetFileBridgeDelegate callback = null)
 {
     var request = AssetFileLoader.Load(path, callback);
     return request;
 }
Пример #12
0
        protected override void Init(string url, params object[] args)
        {
            base.Init(url, args);

            _bridge = AssetFileLoader.Load(Url, (_isOk, _obj) => { OnFinish(_obj); });
        }
Пример #13
0
        /// <summary>
        /// load asset bundle immediatly
        /// </summary>
        /// <param name="path"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public static AbstractResourceLoader LoadBundle(string path, AssetFileLoader.AssetFileBridgeDelegate callback = null)
        {
            var request = AssetFileLoader.Load(path, callback, LoaderMode.Sync);

            return(request);
        }
Пример #14
0
        protected override void Init(string path, params object[] args)
        {
            var loaderMode = (LoaderMode)args[0];

            base.Init(path, args);
            if (string.IsNullOrEmpty(path))
                Log.Error("StaticAssetLoader 空资源路径!");

            _assetFileLoader = AssetFileLoader.Load(path, (_isOk, _obj) =>
            {
                OnFinish(_obj);

                if (Application.isEditor)
                    if (TheAsset != null)
                        KResoourceLoadedAssetDebugger.Create("StaticAsset", path, TheAsset);
            }, loaderMode);
        }
Пример #15
0
        protected override void Init(string url, params object[] args)
        {
            base.Init(url, args);

            Path = url;
            AssetFileBridge = AssetFileLoader.Load(Path, OnAssetLoaded);
        }
Пример #16
0
 /// <summary>
 /// Load Async Asset Bundle
 /// </summary>
 /// <param name="path"></param>
 /// <param name="callback">cps style async</param>
 /// <returns></returns>
 public static AbstractResourceLoader LoadBundleAsync(string path, AssetFileLoader.AssetFileBridgeDelegate callback = null)
 {
     var request = AssetFileLoader.Load(path, callback);
     return request;
 }
Пример #17
0
        protected override void Init(string url, params object[] args)
        {
            base.Init(url, args);

            _bridge = AssetFileLoader.Load(Url, (_isOk, _obj) => { OnFinish(_obj); });
        }
Пример #18
0
        protected override void Init(string url, params object[] args)
        {
            base.Init(url, args);

            AssetFileBridge = AssetFileLoader.Load(url, (bool isOk, UnityEngine.Object obj) => { OnFinish(obj); });
        }
Пример #19
0
        protected override void Init(string url, params object[] args)
        {
            base.Init(url, args);

            _assetFileBridge = AssetFileLoader.Load(url, (isOk, asset) =>
            {
                if (IsReadyDisposed) // 中途释放
                {
                    OnFinish(null);
                    return;
                }
                if (!isOk)
                {
                    OnFinish(null);
                    Log.Error("[InstanceAssetLoader]Error on assetfilebridge loaded... {0}", url);
                    return;
                }

                try
                {
                    InstanceAsset = (GameObject)GameObject.Instantiate(asset as UnityEngine.GameObject);
                }
                catch (Exception e)
                {
                    Log.LogException(e);
                }

                if (Application.isEditor)
                {
                    KResoourceLoadedAssetDebugger.Create("AssetCopy", url, InstanceAsset);
                }

                OnFinish(InstanceAsset);
            });
        }
Пример #20
0
        protected override void Init(string url, params object[] args)
        {
            base.Init(url, args);

            AssetFileBridge = AssetFileLoader.Load(url, (bool isOk, UnityEngine.Object obj) => { OnFinish(obj); });
        }
Пример #21
0
        IEnumerator Start()
        {
            _assetFileBridge = AssetFileLoader.Load(_url, (bool isOk, UnityEngine.Object obj) => { },
                _mode);

            while (!_assetFileBridge.IsCompleted)
            {
                yield return null;
            }
            if (_assetFileBridge.IsError)
            {
                Log.Error("[SceneLoader]Load SceneLoader Failed(Error) when Finished: {0}", _url);
                _assetFileBridge.Release();
                OnFinish(null);
                yield break;
            }

            // load scene
            Debuger.Assert(_assetFileBridge.Asset);

            if (_mode == LoaderMode.Sync)
                UnityEngine.SceneManagement.SceneManager.LoadScene(_sceneName,
                    UnityEngine.SceneManagement.LoadSceneMode.Additive);

            else
            {
                var op = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(_sceneName, UnityEngine.SceneManagement.LoadSceneMode.Additive);
                while (!op.isDone)
                {
                    yield return null;
                }
            }

            if (Application.isEditor)
                KResourceModule.Instance.StartCoroutine(EditorLoadSceneBugFix(null));

            OnFinish(_assetFileBridge);
        }