Pipeline 类型

模块: cc.AssetManager

管线能执行任务达到某个效果

索引

属性(properties)
  • id Number 管线的 id
  • name String 管线的名字
  • pipes Function[] 所有的管道
方法
  • constructor 创建一个管线
  • insert 在某个特定的点为管线插入一个新的 pipe
  • append 添加一个管道到管线中
  • remove 移除特定位置的管道
  • sync 同步执行任务
  • async 异步执行任务

Details

属性(properties)

id

管线的 id

meta description
类型 Number
定义于 cocos2d/core/asset-manager/pipeline.js:50
name

管线的名字

meta description
类型 String
定义于 cocos2d/core/asset-manager/pipeline.js:62
pipes

所有的管道

meta description
类型 Function[]
定义于 cocos2d/core/asset-manager/pipeline.js:74

方法

constructor

创建一个管线

meta description
定义于 cocos2d/core/asset-manager/pipeline.js:97
参数列表
  • name string The name of pipeline
  • funcs Function[] The array of pipe, every pipe must be function which take two parameters, the first is a Task flowed in pipeline, the second is complete callback
示例
var pipeline = new Pipeline('download', [
(task, done) => {
     var url = task.input;
     cc.assetManager.downloader.downloadFile(url, null, null, (err, result) => {
         task.output = result;
         done(err);
     });
},
(task, done) => {
     var text = task.input;
     var json = JSON.stringify(text);
     task.output = json;
     done();
}
]);
insert

在某个特定的点为管线插入一个新的 pipe

meta description
返回 Pipeline
定义于 cocos2d/core/asset-manager/pipeline.js:130
参数列表
  • func Function The new pipe
    • task Task The task handled with pipeline will be transferred to this function
    • callback Function Callback you need to invoke manually when this pipe is finished. if the pipeline is synchronous, callback is unnecessary.
  • index number The specific point you want to insert at.
示例
var pipeline = new Pipeline('test', []);
pipeline.insert((task, done) => {
     // do something
     done();
}, 0);
append

添加一个管道到管线中

meta description
返回 Pipeline
定义于 cocos2d/core/asset-manager/pipeline.js:165
参数列表
  • func Function The new pipe
    • task Task The task handled with pipeline will be transferred to this function
    • callback Function Callback you need to invoke manually when this pipe is finished. if the pipeline is synchronous, callback is unnecessary.
示例
var pipeline = new Pipeline('test', []);
pipeline.append((task, done) => {
     // do something
     done();
});
remove

移除特定位置的管道

meta description
返回 Pipeline
定义于 cocos2d/core/asset-manager/pipeline.js:197
参数列表
  • index number The specific point
示例
var pipeline = new Pipeline('test', (task, done) => {
     // do something
     done();
});
pipeline.remove(0);
sync

同步执行任务

meta description
返回 Any
定义于 cocos2d/core/asset-manager/pipeline.js:227
参数列表
  • task Task The task will be executed
示例
var pipeline = new Pipeline('sync', [(task) => {
     let input = task.input;
     task.output = doSomething(task.input);
}]);

var task = new Task({input: 'test'});
console.log(pipeline.sync(task));
async

异步执行任务

meta description
定义于 cocos2d/core/asset-manager/pipeline.js:275
参数列表
  • task Task The task will be executed
示例
var pipeline = new Pipeline('sync', [(task, done) => {
     let input = task.input;
     task.output = doSomething(task.input);
     done();
}]);
var task = new Task({input: 'test', onComplete: (err, result) => console.log(result)});
pipeline.async(task);

条与 "" 相匹配的结果

    没有与 "" 匹配的结果