Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Pipeline

pipeline 描述了一系列的操作,每个操作都被称为 pipe。
它被设计来做加载过程的流程管理。所以 item 应该是 url,并且该 url 将是在处理中的每个 item 的身份标识。
一个 item 列表可以在 pipeline 中流动,它将输出加载项经过所有 pipe 之后的结果。
它们穿过 pipeline 就像水在管子里流动,将会按顺序流过每个 pipe。
最后当所有加载项都流出 pipeline 时,整个加载流程就结束了。

class

Pipeline

Hierarchy

Index

Constructors

constructor

  • 构造函数,通过一系列的 pipe 来构造一个新的 pipeline,pipes 将会在给定的顺序中被锁定。
    一个 pipe 就是一个对象,它包含了字符串类型的 ‘id’ 和 ‘handle’ 函数,在 pipeline 中 id 必须是唯一的。
    它还可以包括 ‘async’ 属性以确定它是否是一个异步过程。

    example
     let pipeline = new Pipeline([
         {
             id: 'Downloader',
             handle: function (item, callback) {},
             async: true
         },
         {id: 'Parser', handle: function (item) {}, async: false}
     ]);

    Parameters

    • pipes: any

    Returns Pipeline

Properties

_cache

_cache: any = createMap(true)

Protected _pipes

_pipes: Array<IPipe>

Static ItemState

ItemState: any = ItemState

Methods

appendPipe

  • appendPipe(pipe: any): void
  • 添加一个新的 pipe 到 pipeline 尾部。
    该 pipe 必须包含一个字符串类型 ‘id’ 和 ‘handle’ 函数,该 id 在 pipeline 必须是唯一标识。

    method

    appendPipe

    Parameters

    • pipe: any

      The pipe to be appended

    Returns void

clear

  • clear(): void

copyItemStates

  • copyItemStates(srcItem: any, dstItems: any): void
  • 从一个源 item 向所有目标 item 复制它的 pipe 状态,用于避免重复通过部分 pipe。
    当一个源 item 生成了一系列新的 items 时很有用,
    你希望让这些新的依赖项进入 pipeline,但是又不希望它们通过源 item 已经经过的 pipe,
    但是你可能希望他们源 item 已经通过并跳过所有 pipes,
    这个时候就可以使用这个 API。

    method

    copyItemStates

    Parameters

    • srcItem: any

      The source item

    • dstItems: any

      A single destination item or an array of destination items

    Returns void

flowIn

  • flowIn(items: any): void
  • 让新的 item 流入 pipeline 中。
    这里的每个 item 可以是一个简单字符串类型的 url 或者是一个对象, 如果它是一个对象的话,他必须要包含 ‘id’ 属性。
    你也可以指定它的 ‘type’ 属性类型,默认情况下,该类型是 ‘url’ 的后缀名。
    也通过添加一个 包含 ‘skips’ 属性的 item 对象,你就可以跳过 skips 中包含的 pipe。
    该对象可以包含任何附加属性。

    example
     pipeline.flowIn([
         'res/Background.png',
         {
             id: 'res/scene.json',
             type: 'scene',
             name: 'scene',
             skips: ['Downloader']
         }
     ]);

    Parameters

    • items: any

    Returns void

flowInDeps

  • flowInDeps(owner: any, urlList: any, callback: any): IItem[]
  • 让新 items 流入 pipeline 并且当 item 列表完成时进行回调函数。
    这个 API 的使用通常是为了加载依赖项。
    例如:
    我们需要加载一个场景配置的 JSON 文件,该场景会将所有的依赖项全部都加载完毕以后,进行回调表示加载完毕。

    deprecated

    since v1.3

    Parameters

    • owner: any
    • urlList: any
    • callback: any

    Returns IItem[]

    Items accepted by the pipeline

flowOut

  • flowOut(item: any): void

getItem

  • getItem(id: any): any

insertPipe

  • insertPipe(pipe: any, index: any): void
  • 在给定的索引位置插入一个新的 pipe。
    一个 pipe 必须包含一个字符串类型的 ‘id’ 和 ‘handle’ 函数,该 id 在 pipeline 必须是唯一标识。

    method

    insertPipe

    Parameters

    • pipe: any

      The pipe to be inserted

    • index: any

      The index to insert

    Returns void

insertPipeAfter

  • insertPipeAfter(refPipe: any, newPipe: any): void
  • 在当前 pipeline 的一个已知 pipe 后面插入一个新的 pipe。

    method

    insertPipeAfter

    Parameters

    • refPipe: any

      An existing pipe in the pipeline.

    • newPipe: any

      The pipe to be inserted.

    Returns void

removeItem

  • removeItem(id: any): any
  • 移除指定的已完成 item。 这将仅仅从 pipeline 或者 loader 中删除其缓存,并不会释放它所依赖的资源。 cc.loader 中提供了另一种删除资源及其依赖的清理方法,请参考 CCLoader.release

    method

    removeItem

    Parameters

    • id: any

      The id of the item

    Returns any

    succeed or not

Generated using TypeDoc