废弃 API
markAsWarning
对给予对象上的属性中嵌入一个警告,给予对象需要存在该属性。removeProperty
重新定义给予对象上移除的属性,并嵌入一个报错,给予对象应不存在该属性。
按照模块划分,每个模块维护一份废弃文件。为了便于维护,命名统一为 deprecated.ts,并且放在相应模块的目录下,并需要在相应的模块的index.ts
文件中import
该文件,例如import './deprecated'
。
注:cocos\utils
目录下的deprecated.ts
文件为声明和实现文件。
// 对于替换参数不兼容的 API,通过合适的自定义功能进行适配
replaceProperty(Animation.prototype, 'Animation.prototype', [
{
name: 'removeClip',
newName: 'removeState',
customFunction: function (...args: any) {
const arg0 = args[0] as AnimationClip;
return Animation.prototype.removeState.call(this, arg0.name);
]);
replaceProperty(vmath, 'vmath', [
{
name: 'vec2',
newName: 'Vec2',
target: math,
targetName: 'math',
'logTimes': 1
},
{
name: 'EPSILON',
target: math,
targetName: 'math',
'logTimes': 2
]);
removeProperty(vmath, 'vmath', [
{
'name': 'random',
'suggest': 'use Math.random.'
}
]);
markAsWarning(math, 'math', [
{
'name': 'toRadian'
}
]);
replaceProperty
不传入newName
或newTarget
,表示和name
或target
一致。