# Asset

资源操作接口

Kind: global class

# asset.loadAsset(object) ⇒ Promise.<engine.Entity>

加载单个资源

Kind: instance method of Asset
Returns: Promise.<engine.Entity> - 返回一个Promise对象
Version: 0.1.28

Param Type Description
object Object
object.assetPath string 资源路径, 相对于 assets 的相对路径, 如: 路径为 assets/Assets/1.prefab, 则传入的path 是 Assets/1.prefab
object.success loadAssetSuccessCallback 注册成功回调
object.fail loadAssetFailCallback 注册失败回调

Example (Promise用法)

GameEditor.asset.loadAsset({
  assetPath: 'myScene/1.prefab' // 传入资源路径, 相对于 assets 目录
}).then((entity) => {
  console.log(entity)
}).catch((errMsg) => {
  console.error(errMsg)
})

Example (注册回调用法)

GameEditor.asset.loadAsset({
  assetPath: 'myScene/1.prefab' // 传入资源路径, 相对于 assets 目录
  success: function(entity) {
    console.log(entity)
  },
  fail: function(errMsg) {
    console.error(errMsg)
  }
})

# asset.loadAssetList(object) ⇒ Promise.<engine.Entity>

加载多个资源

Kind: instance method of Asset
Returns: Promise.<engine.Entity> - 返回一个Promise对象
Version: 0.1.28

Param Type Description
object Object
object.assetPathList string 资源路径数组
object.success loadAssetListSuccessCallback 注册成功回调
object.fail loadAssetListFailCallback 注册失败回调

Example (Promise用法)

GameEditor.asset.loadAsset({
  assetPathList: ['assetPathxxxxx'] // 传入资源路径
}).then((entity) => {
  console.log(entity)
}).catch((errMsg) => {
  console.error(errMsg)
})

Example (注册回调用法)

GameEditor.asset.loadAsset({
  assetPathList: ['assetPathxxxxx'] // 传入资源路径
  success: function(entity) {
    console.log(entity)
  },
  fail: function(errMsg) {
    console.error(errMsg)
  }
})

# asset.saveAsset(object) ⇒ Promise.<engine.Entity>

保存资源, 将内存中的内存对象落地到文件中

Kind: instance method of Asset
Returns: Promise.<engine.Entity> - 返回一个Promise对象
Version: 0.1.28

Param Type Description
object Object
object.assetPath string 资源路径
object.entity engine.Entity entity内存对象
object.success saveAssetSuccessCallback 注册成功回调
object.fail saveAssetFailCallback 注册失败回调

Example (Promise用法)

GameEditor.asset.loadAsset({
  assetPathList: ['assetPathxxxxx'] // 传入资源路径
}).then((entity) => {
  console.log(entity)
}).catch((errMsg) => {
  console.error(errMsg)
})

Example (注册回调用法)

GameEditor.asset.loadAsset({
  assetPathList: ['assetPathxxxxx'] // 传入资源路径
  success: function(entity) {
    console.log(entity)
  },
  fail: function(errMsg) {
    console.error(errMsg)
  }
})

# asset.getAllScenesPath() ⇒ Promise

获取所有Scene资源路径

Kind: instance method of Asset
Returns: Promise -
Promise.reject {string} errMsg 错误信息
Promise.resolve {array} data 所有Scene资源路径

Version: 0.1.28
Example (获取所有Scene资源路径)

const scenePathList = GameEditor.getAllScenesPath()
console.log(scenePathList)

# asset.getAllPrefabPath() ⇒ Promise

获取所有Prefab资源路径

Kind: instance method of Asset
Returns: Promise - 返回资源路径数组
Promise.reject {string} errMsg 错误信息
Promise.resolve {array} data 所有Prefab资源路径

Version: 0.1.28
Example (获取所有Prefab资源路径)

const prefabPathList = GameEditor.getAllPrefabPathSync()
console.log(prefabPathList)

# asset.readFile()

读取文件内容。详见 CustomerManager.readFile

Kind: instance method of Asset

# asset.writeFile()

写文件。详见 CustomerManager.writeFile

Kind: instance method of Asset

# asset.getFileOrDirStat()

获取文件或者文件夹的详情。详见CustomerFileOperator.getFileOrDirStat

Kind: instance method of Asset

# asset.getUint64String()

读取文件内容。详见 CustomerManager.getUint64String

Kind: instance method of Asset

# asset.getAllFileListInDir()

获取指定目录下的文件信息(不包含文件内容)。详见 CustomerManager.getAllFileListInDir

Kind: instance method of Asset

# asset.createSpriteFrameInfo()

落地图集信息到assets目录下指定目录。落地后文件目录结构保持不变。详见 CustomerManager.createSpriteFrameInfo

Kind: instance method of Asset

# asset.getFileDefaultDataByType()

根据类型获取对应文件数据结构.详见 CustomerManager.getFileDefaultDataByType

Kind: instance method of Asset

# asset.loadAssetSuccessCallback : function

loadAsset 成功回调

Kind: instance typedef of Asset

Param Type Description
entity engine.Entity assetPath对应的Entity内存对象

# asset.loadAssetFailCallback : function

loadAsset 失败回调

Kind: instance typedef of Asset

Param Type Description
errMsg string 错误信息

# asset.loadAssetListSuccessCallback : function

loadAssetList 成功回调

Kind: instance typedef of Asset

Param Type Description
entity engine.Entity assetPath对应的Entity内存对象

# asset.loadAssetListFailCallback : function

loadAssetList 失败回调

Kind: instance typedef of Asset

Param Type Description
errMsg string 错误信息

# asset.saveAssetSuccessCallback : function

saveAsset 成功回调

Kind: instance typedef of Asset

Param Type Description
entity engine.Entity assetPath对应的Entity内存对象

# asset.saveAssetFailCallback : function

saveAsset 失败回调

Kind: instance typedef of Asset

Param Type Description
errMsg string 错误信息
点击咨询小助手