示例#1
0
        /// <summary>
        /// 暂时不用
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static ResourceDepRequest LoadLevelAdditiveAsync(string path)
        {
            var req = new ResourceDepRequest();

            KResourceModule.Instance.StartCoroutine(CoLoadLevelAdditiveAsync(path, req));
            return(req);
        }
示例#2
0
        /// <summary>
        /// 异步加载Asset Bundle,自动处理依赖
        /// </summary>
        /// <param name="relativePath"></param>
        /// <returns></returns>
        public static ResourceDepRequest LoadAssetBundleAsync(string relativePath)
        {
            //CheckLoadShadersPrefab();
            var request = new ResourceDepRequest {
                Path = relativePath
            };

            AppEngine.EngineInstance.StartCoroutine(CoLoadAssetBundleAsync(relativePath, request));
            return(request);
        }
示例#3
0
        /// <summary>
        /// 暂时不用,交给KResources
        /// </summary>
        /// <param name="path"></param>
        /// <param name="req"></param>
        /// <returns></returns>
        static IEnumerator CoLoadLevelAdditiveAsync(string path, ResourceDepRequest req)
        {
            var abReq = LoadAssetBundleAsync(path);

            while (!abReq.IsDone)
            {
                yield return(null);
            }

            var levelName = Path.GetFileNameWithoutExtension(path);
            var op        = Application.LoadLevelAdditiveAsync(levelName);

            while (!op.isDone)
            {
                yield return(null);
            }

            RefreshAllMaterialsShaders();
            req.IsDone = true;
            Log.Info("[LoadLevelAdditiveAsync]Load Level `{0}` Complete!", path);
        }
示例#4
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;
        }
示例#5
0
        /// <summary>
        /// 暂时不用,交给KResources
        /// </summary>
        /// <param name="path"></param>
        /// <param name="req"></param>
        /// <returns></returns>
        static IEnumerator CoLoadLevelAdditiveAsync(string path, ResourceDepRequest req)
        {
            var abReq = LoadAssetBundleAsync(path);
            while (!abReq.IsDone)
                yield return null;

            var levelName = Path.GetFileNameWithoutExtension(path);
            var op = Application.LoadLevelAdditiveAsync(levelName);
            while (!op.isDone)
                yield return null;

            RefreshAllMaterialsShaders();
            req.IsDone = true;
            Log.Info("[LoadLevelAdditiveAsync]Load Level `{0}` Complete!", path);
        }
示例#6
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 = HotBytesLoader.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;
        }
示例#7
0
 /// <summary>
 /// 暂时不用
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static ResourceDepRequest LoadLevelAdditiveAsync(string path)
 {
     var req = new ResourceDepRequest();
     KResourceModule.Instance.StartCoroutine(CoLoadLevelAdditiveAsync(path, req));
     return req;
 }
示例#8
0
 /// <summary>
 /// 异步加载Asset Bundle,自动处理依赖
 /// </summary>
 /// <param name="relativePath"></param>
 /// <returns></returns>
 public static ResourceDepRequest LoadAssetBundleAsync(string relativePath)
 {
     //CheckLoadShadersPrefab();
     var request = new ResourceDepRequest { Path = relativePath };
     AppEngine.EngineInstance.StartCoroutine(CoLoadAssetBundleAsync(relativePath, request));
     return request;
 }