Class ResLoader

游戏资管理 1、加载默认resources文件夹中资源 2、加载默认bundle远程资源 3、主动传递bundle名时,优先加载传递bundle名资源包中的资源

Hierarchy

  • ResLoader

Constructors

Properties

defaultBundleName: string = "resources"

全局默认加载的资源包名

Methods

  • 打印缓存中所有资源信息

    Returns void

  • 获取资源

    Type Parameters

    • T extends Asset<T>

    Parameters

    • path: string

      资源路径

    • Optional type: null | __types_globals__Constructor<T>

      资源类型

    • Optional bundleName: string

      远程资源包名

    Returns null | T

  • 加载一个资源

    Example

    oops.res.load("spine_path", sp.SkeletonData, (err: Error | null, sd: sp.SkeletonData) => {

    });

    Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string

      远程包名

    • paths: string | string[]

      资源路径

    • type: null | AssetType<T>

      资源类型

    • onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback

      加载进度回调

    • onComplete: any

      加载完成回调

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string
    • paths: string | string[]
    • onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback
    • onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string
    • paths: string | string[]
    • Optional onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string
    • paths: string | string[]
    • type: null | AssetType<T>
    • Optional onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • paths: string | string[]
    • type: null | AssetType<T>
    • onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback
    • onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • paths: string | string[]
    • onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback
    • onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • paths: string | string[]
    • Optional onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • paths: string | string[]
    • type: null | AssetType<T>
    • Optional onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string
    • paths: string | string[]
    • type: null | AssetType<T>

    Returns Promise<T>

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string
    • paths: string | string[]

    Returns Promise<T>

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string
    • paths: string | string[]

    Returns Promise<T>

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string
    • paths: string | string[]
    • type: null | AssetType<T>

    Returns Promise<T>

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • paths: string | string[]
    • type: null | AssetType<T>

    Returns Promise<T>

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • paths: string | string[]

    Returns Promise<T>

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • paths: string | string[]

    Returns Promise<T>

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • paths: string | string[]
    • type: null | AssetType<T>

    Returns Promise<T>

  • 加载资源包

    Example

    var serverUrl = "http://192.168.1.8:8080/";         // 服务器地址
    var md5 = "8e5c0"; // Cocos Creator 构建后的MD5字符
    await oops.res.loadBundle(serverUrl,md5);

    Parameters

    • url: string

      资源地址

    • Optional v: string

      资源MD5版本号

    Returns Promise<Bundle>

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • args: ILoadResArgs<T>

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • bundle: Bundle
    • args: ILoadResArgs<T>

    Returns void

  • 加载文件夹中的资源

    Example

    // 加载进度事件
    var onProgressCallback = (finished: number, total: number, item: any) => {
    console.log("资源加载进度", finished, total);
    }

    // 加载完成事件
    var onCompleteCallback = () => {
    console.log("资源加载完成");
    }
    oops.res.loadDir("game", onProgressCallback, onCompleteCallback);

    Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string

      远程包名

    • dir: string

      文件夹名

    • type: null | AssetType<T>

      资源类型

    • onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback

      加载进度回调

    • onComplete: any

      加载完成回调

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string
    • dir: string
    • onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback
    • onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string
    • dir: string
    • Optional onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • bundleName: string
    • dir: string
    • type: null | AssetType<T>
    • Optional onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • dir: string
    • type: null | AssetType<T>
    • onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback
    • onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • dir: string
    • onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback
    • onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • dir: string
    • Optional onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • dir: string
    • type: null | AssetType<T>
    • Optional onComplete: any

    Returns void

  • 加载远程资源

    Example

    var opt: IRemoteOptions = { ext: ".png" };
    var onComplete = (err: Error | null, data: ImageAsset) => {
    const texture = new Texture2D();
    texture.image = data;

    const spriteFrame = new SpriteFrame();
    spriteFrame.texture = texture;

    var sprite = this.sprite.addComponent(Sprite);
    sprite.spriteFrame = spriteFrame;
    }
    oops.res.loadRemote<ImageAsset>(this.url, opt, onComplete);

    Type Parameters

    • T extends Asset<T>

    Parameters

    • url: string

      资源地址

    • options: IRemoteOptions

      资源参数,例:{ ext: ".png" }

    • Optional onComplete: any

      加载完成回调

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • url: string
    • Optional onComplete: any

    Returns void

  • Type Parameters

    • T extends Asset<T>

    Parameters

    • paths: string | string[]
    • Optional type: any
    • Optional onProgress: any
    • Optional onComplete: any

    Returns {
        onComplete: any;
        onProgress: any;
        paths: any;
        type: any;
    }

    • onComplete: any
    • onProgress: any
    • paths: any
    • type: any
  • 通过资源相对路径释放资源

    Parameters

    • path: string

      资源路径

    • Optional bundleName: string

      远程资源包名

    Returns void

  • 通过相对文件夹路径删除所有文件夹中资源

    Parameters

    • path: string

      资源文件夹路径

    • Optional bundleName: string

      远程资源包名

    Returns void

  • 释放预制依赖资源

    Parameters

    • uuid: string | Asset

    Returns void

Generated using TypeDoc