废弃 API

    • markAsWarning 对给予对象上的属性中嵌入一个警告,给予对象需要存在该属性。

    • removeProperty 重新定义给予对象上移除的属性,并嵌入一个报错,给予对象应不存在该属性。

    按照模块划分,每个模块维护一份废弃文件。为了便于维护,命名统一为 deprecated.ts,并且放在相应模块的目录下,并需要在相应的模块的index.ts文件中import该文件,例如import './deprecated'

    注:cocos\utils目录下的deprecated.ts文件为声明和实现文件

    1. // 对于替换参数不兼容的 API,通过合适的自定义功能进行适配
    2. replaceProperty(Animation.prototype, 'Animation.prototype', [
    3. {
    4. name: 'removeClip',
    5. newName: 'removeState',
    6. customFunction: function (...args: any) {
    7. const arg0 = args[0] as AnimationClip;
    8. return Animation.prototype.removeState.call(this, arg0.name);
    9. ]);
    10. replaceProperty(vmath, 'vmath', [
    11. {
    12. name: 'vec2',
    13. newName: 'Vec2',
    14. target: math,
    15. targetName: 'math',
    16. 'logTimes': 1
    17. },
    18. {
    19. name: 'EPSILON',
    20. target: math,
    21. targetName: 'math',
    22. 'logTimes': 2
    23. ]);
    24. removeProperty(vmath, 'vmath', [
    25. {
    26. 'name': 'random',
    27. 'suggest': 'use Math.random.'
    28. }
    29. ]);
    30. markAsWarning(math, 'math', [
    31. {
    32. 'name': 'toRadian'
    33. }
    34. ]);
    • replaceProperty不传入newNamenewTarget,表示和nametarget一致。