Ejemplo n.º 1
0
        /// <summary>
        /// 异步加载资源
        /// </summary>
        /// <typeparam name="T">资源类型</typeparam>
        /// <param name="assetName">资源名称(完整名称,加路径及后缀名)</param>
        /// <param name="callback">回调函数</param>
        /// <returns>加载进度</returns>
        public IProgress LoadAsync <T>(string assetName, Action <T> callback) where T : UnityEngine.Object
        {
            var temp = Utility.Text.SplitPathName(assetName);

            DynamicMultiProgress progress = new DynamicMultiProgress(2, 0.9f, 0.1f);

            var abProgress = LoadAssetBundleAsync(temp[0], (ab) =>
            {
                var request     = ab.LoadAssetAsync(temp[1]);
                SingleTask task = new SingleTask(() =>
                {
                    return(request.isDone);
                });
                task.Then(() => { callback(request.asset as T); return(true); });
                task.Start();

                SingleResProgress resProgress = new SingleResProgress(request);
                progress.Add(resProgress);
            });

            progress.Add(abProgress);

            return(progress);
        }
Ejemplo n.º 2
0
        public IProgress LoadAsync <T>(string assetName, System.Action <T> callback) where T : Object
        {
            var temp = Utility.Text.SplitPathName(assetName);

            DynamicMultiProgress progress = new DynamicMultiProgress(2);

            var abProgress = GetAssetBundleAsync(temp[0], (ab) =>
            {
                var request     = ab.LoadAssetAsync(temp[1]);
                SingleTask task = new SingleTask(() =>
                {
                    return(request.isDone);
                });
                task.Then(() => { callback(request.asset as T); return(true); });
                GameEntry.GetModule <TaskManager>().StartTask(task);

                SingleResProgress resProgress = new SingleResProgress(request);
                progress.Add(resProgress);
            });

            progress.Add(abProgress);

            return(progress);
        }