ResourceDep资源依赖系统主入口
示例#1
0
        private static IEnumerator CoLoadAssetBundleAsync(string relativePath, ResourceDepRequest request)
        {
            // manifest
            string manifestPath = ResourceDepUtils.GetBuildPath(String.Format("{0}.manifest{1}", relativePath,
                                                                              AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt)));
            var manifestLoader = KBytesLoader.Load(manifestPath, LoaderMode.Sync);

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

            // manifest读取失败,可能根本没有manifest,是允许的
            if (manifestLoader.IsSuccess)
            {
                var manifestBytes = manifestLoader.Bytes;
                manifestLoader.Release(); // 释放掉文本字节
                string[] manifestList = GetManifestList(manifestBytes);
                for (var i = 0; i < manifestList.Length; i++)
                {
                    var depPath   = manifestList[i] + AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt);
                    var depLoader = KAssetFileLoader.Load(depPath);
                    if (request.Loaders == null)
                    {
                        request.Loaders = new List <KAbstractResourceLoader>();
                    }
                    request.Loaders.Add(depLoader);
                    while (!depLoader.IsCompleted)
                    {
                        yield return(null);
                    }
                }
            }
            string path =
                GetBuildPath(String.Format("{0}{1}", relativePath,
                                           AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt)));

            // 获取后缀名
            var ext = Path.GetExtension(relativePath);

            if (ext == ".unity" || ext == ".shader")
            {
                // Scene
                var sceneLoader = KAssetBundleLoader.Load(path);

                if (request.Loaders == null)
                {
                    request.Loaders = new List <KAbstractResourceLoader>();
                }
                request.Loaders.Add(sceneLoader);
                while (!sceneLoader.IsCompleted)
                {
                    yield return(null);
                }
            }
            else
            {
                var assetLoader = KAssetFileLoader.Load(path);
                while (!assetLoader.IsCompleted)
                {
                    yield return(null);
                }
                request.Asset = assetLoader.Asset;
            }

            request.IsDone = true;
        }
示例#2
0
        /// <summary>
        /// 同步加载AssetBundle
        /// </summary>
        /// <param name="relativePath"></param>
        /// <returns></returns>
        public static Object LoadAssetBundleSync(string relativePath)
        {
            //CheckLoadShadersPrefab();
            // manifest
            string manifestPath = ResourceDepUtils.GetBuildPath(String.Format("{0}.manifest{1}", relativePath,
                                                                              AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt)));
            var manifestLoader = KBytesLoader.Load(manifestPath, LoaderMode.Sync);
            //while (!manifestLoader.IsCompleted)
            //    yield return null;
            var manifestBytes = manifestLoader.Bytes;

            manifestLoader.Release(); // 释放掉文本字节
            if (manifestBytes != null)
            {
                var manifestList = GetManifestList(manifestBytes);
                for (var i = 0; i < manifestList.Length; i++)
                {
                    var depPath = manifestList[i] + AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt);
                    //var depLoader =
                    KAssetFileLoader.Load(depPath);
                    //while (!depLoader.IsCompleted)
                    //{
                    //    yield return null;
                    //}

                    /*if (Application.isEditor)
                     * {
                     *  Log.Info("Load dep sync:{0}, from: {1}", depPath, relativePath);
                     * }*/
                }
            }
            else
            {
                Log.Warning("Cannot find Manifest: {0}", relativePath);
            }

            string path =
                GetBuildPath(String.Format("{0}{1}", relativePath,
                                           AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt)));

            //while (!assetLoader.IsCompleted)
            //    yield return null;
            // 获取后缀名
            var ext = Path.GetExtension(relativePath);

            if (ext == ".unity" || ext == ".shader")
            {
                // Scene
                //var sceneLoader =
                KAssetBundleLoader.Load(path);
                //while (!sceneLoader.IsCompleted)
                //    yield return null;
                return(null);
            }
            else
            {
                var assetLoader = KAssetFileLoader.Load(path);
                //while (!assetLoader.IsCompleted)
                //    yield return null;
                return(assetLoader.Asset);
            }
        }