Beispiel #1
0
    private IEnumerator CoLoadSerializeMaterial()
    {
        var matLoadBridge = KAssetFileLoader.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);
    }
Beispiel #2
0
    protected override void Init(string url, params object[] args)
    {
        base.Init(url, args);

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

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

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

            OnFinish(InstanceAsset);
        });
    }
Beispiel #3
0
    protected override void Init(string path, params object[] args)
    {
        var loaderMode = (KAssetBundleLoaderMode)args[0];

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

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

            if (Application.isEditor)
            {
                if (TheAsset != null)
                {
                    KResoourceLoadedAssetDebugger.Create("StaticAsset", path, TheAsset);
                }
            }
        }, loaderMode);
    }
Beispiel #4
0
    private IEnumerator _Init(string path, string assetName, KAssetBundleLoaderMode loaderMode)
    {
        IsLoadAssetBundle = KEngine.AppEngine.GetConfig("IsLoadAssetBundle").ToInt32() != 0;
        AssetInBundleName = assetName;

        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)
            {
                Logger.LogError("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)
            {
                Logger.LogError("[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 (AssetInBundleName == null)
            {
                // 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化
                //AssetBundleRequest request = assetBundle.LoadAsync("", typeof(Object));// mainAsset
                //while (!request.isDone)
                //{
                //    yield return null;
                //}
                try
                {
                    Logger.Assert(getAsset = assetBundle.mainAsset);
                }
                catch
                {
                    Logger.LogError("[OnAssetBundleLoaded:mainAsset]{0}", path);
                }
            }
            else
            {
                // TODO: 未测试过这几行!~~
                AssetBundleRequest request = assetBundle.LoadAsync(AssetInBundleName, typeof(Object));
                while (!request.isDone)
                {
                    yield return(null);
                }

                getAsset = request.asset;
            }

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

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

            _bundleLoader.Release(); // 释放Bundle(WebStream)
        }

        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);
    }