对XXXLoader的结果Asset进行Debug显示
Inheritance: UnityEngine.MonoBehaviour
コード例 #1
0
ファイル: KShaderLoader.cs プロジェクト: chen13469990/Racing
        private IEnumerator CoLoadShader()
        {
            var loader = AssetBundleLoader.Load(Url);

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

            var shader = loader.Bundle.mainAsset as Shader;

            Debuger.Assert(shader);

            Desc = shader.name;

            if (Application.isEditor)
            {
                KResoourceLoadedAssetDebugger.Create("Shader", Url, shader);
            }

            loader.Release(IsBeenReleaseNow);

            OnFinish(shader);
        }
コード例 #2
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);
        }
コード例 #3
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);
            });
        }
コード例 #4
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);
        }
コード例 #5
0
        private IEnumerator _Init(string path, LoaderMode loaderMode)
        {
            IsLoadAssetBundle = AppEngine.GetConfig("KEngine", "IsLoadAssetBundle").ToInt32() != 0;

            Object getAsset = null;

            if (IsEditorLoadAsset)
            {
#if UNITY_EDITOR
                if (path.EndsWith(".unity"))
                {
                    // scene
                    getAsset = KResourceModule.Instance;
                    Log.LogWarning("Load scene from Build Settings: {0}", path);
                }
                else
                {
                    getAsset = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/" + KEngineDef.ResourcesBuildDir + "/" + path, typeof(UnityEngine.Object));
                    if (getAsset == null)
                    {
                        Log.Error("Asset is NULL(from {0} Folder): {1}", KEngineDef.ResourcesBuildDir, path);
                    }
                }
#else
                Log.Error("`IsEditorLoadAsset` is Unity Editor only");
#endif
                OnFinish(getAsset);
            }
            else if (!IsLoadAssetBundle)
            {
                string extension = Path.GetExtension(path);
                path = path.Substring(0, path.Length - extension.Length); // remove extensions

                getAsset = Resources.Load <Object>(path);
                if (getAsset == null)
                {
                    Log.Error("Asset is NULL(from Resources Folder): {0}", path);
                }
                OnFinish(getAsset);
            }
            else
            {
                _bundleLoader = AssetBundleLoader.Load(path, null, loaderMode);

                while (!_bundleLoader.IsCompleted)
                {
                    if (IsReadyDisposed) // 中途释放
                    {
                        _bundleLoader.Release();
                        OnFinish(null);
                        yield break;
                    }
                    yield return(null);
                }

                if (!_bundleLoader.IsSuccess)
                {
                    Log.Error("[AssetFileLoader]Load BundleLoader Failed(Error) when Finished: {0}", path);
                    _bundleLoader.Release();
                    OnFinish(null);
                    yield break;
                }

                var assetBundle = _bundleLoader.Bundle;

                DateTime beginTime = DateTime.Now;
#if UNITY_5 || UNITY_2017_1_OR_NEWER
                // Unity 5 下,不能用mainAsset, 要取对象名
                var abAssetName = Path.GetFileNameWithoutExtension(Url).ToLower();
                if (!assetBundle.isStreamedSceneAssetBundle)
                {
                    if (loaderMode == LoaderMode.Sync)
                    {
                        getAsset = assetBundle.LoadAsset(abAssetName);
                        Debuger.Assert(getAsset);
                        _bundleLoader.PushLoadedAsset(getAsset);
                    }
                    else
                    {
                        var request = assetBundle.LoadAssetAsync(abAssetName);
                        while (!request.isDone)
                        {
                            yield return(null);
                        }
                        Debuger.Assert(getAsset = request.asset);
                        _bundleLoader.PushLoadedAsset(getAsset);
                    }
                }
                else
                {
                    // if it's a scene in asset bundle, did nothing
                    // but set a fault Object the result
                    getAsset = KResourceModule.Instance;
                }
#else
                // 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化
                //AssetBundleRequest request = assetBundle.LoadAsync("", typeof(Object));// mainAsset
                //while (!request.isDone)
                //{
                //    yield return null;
                //}
                try
                {
                    Debuger.Assert(getAsset = assetBundle.mainAsset);
                }
                catch
                {
                    Log.Error("[OnAssetBundleLoaded:mainAsset]{0}", path);
                }
#endif

                KResourceModule.LogLoadTime("AssetFileBridge", path, beginTime);

                if (getAsset == null)
                {
                    Log.Error("Asset is NULL: {0}", path);
                }
            }

            if (Application.isEditor)
            {
                if (getAsset != null)
                {
                    KResoourceLoadedAssetDebugger.Create(getAsset.GetType().Name, Url, getAsset as Object);
                }

                // 编辑器环境下,如果遇到GameObject,对Shader进行Fix
                if (getAsset is GameObject)
                {
                    var go = getAsset as GameObject;
                    foreach (var r in go.GetComponentsInChildren <Renderer>(true))
                    {
                        RefreshMaterialsShaders(r);
                    }
                }
            }

            if (getAsset != null)
            {
                // 更名~ 注明来源asset bundle 带有类型
                getAsset.name = String.Format("{0}~{1}", getAsset, Url);
            }
            OnFinish(getAsset);
        }
コード例 #6
0
        private IEnumerator _Init(string path, LoaderMode loaderMode)
        {
            IsLoadAssetBundle = KEngine.AppEngine.GetConfig("KEngine", "IsLoadAssetBundle").ToInt32() != 0;

            UnityEngine.Object getAsset = null;
            if (!IsLoadAssetBundle)
            {
                string extension = System.IO.Path.GetExtension(path);
                path = path.Substring(0, path.Length - extension.Length); // remove extensions

                getAsset = Resources.Load <UnityEngine.Object>(path);
                if (getAsset == null)
                {
                    Log.Error("Asset is NULL(from Resources Folder): {0}", path);
                }
                OnFinish(getAsset);
            }
            else
            {
                _bundleLoader = KAssetBundleLoader.Load(path, null, loaderMode);

                while (!_bundleLoader.IsCompleted)
                {
                    if (IsReadyDisposed) // 中途释放
                    {
                        _bundleLoader.Release();
                        OnFinish(null);
                        yield break;
                    }
                    yield return(null);
                }

                if (!_bundleLoader.IsSuccess)
                {
                    Log.Error("[KAssetFileLoader]Load BundleLoader Failed(Error) when Finished: {0}", path);
                    _bundleLoader.Release();
                    OnFinish(null);
                    yield break;
                }

                var assetBundle = _bundleLoader.Bundle;

                System.DateTime beginTime = System.DateTime.Now;
#if UNITY_5
                // Unity 5 下,不能用mainAsset, 要取对象名
                var abAssetName = Path.GetFileNameWithoutExtension(Url).ToLower();
                if (loaderMode == LoaderMode.Sync)
                {
                    getAsset = assetBundle.LoadAsset(abAssetName);
                    Debuger.Assert(getAsset);
                }
                else
                {
                    var request = assetBundle.LoadAssetAsync(abAssetName);
                    while (!request.isDone)
                    {
                        yield return(null);
                    }
                    Debuger.Assert(getAsset = request.asset);
                }
#else
                // 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化
                //AssetBundleRequest request = assetBundle.LoadAsync("", typeof(Object));// mainAsset
                //while (!request.isDone)
                //{
                //    yield return null;
                //}
                try
                {
                    Debuger.Assert(getAsset = assetBundle.mainAsset);
                }
                catch
                {
                    Log.Error("[OnAssetBundleLoaded:mainAsset]{0}", path);
                }
#endif

                KResourceModule.LogLoadTime("AssetFileBridge", path, beginTime);

                if (getAsset == null)
                {
                    Log.Error("Asset is NULL: {0}", path);
                }
            }

            if (Application.isEditor)
            {
                if (getAsset != null)
                {
                    KResoourceLoadedAssetDebugger.Create(getAsset.GetType().Name, Url, getAsset as UnityEngine.Object);
                }
            }

            if (getAsset != null)
            {
                // 更名~ 注明来源asset bundle 带有类型
                getAsset.name = string.Format("{0}~{1}", getAsset, Url);
            }
            OnFinish(getAsset);
        }