前言
网上搜索到的大多是基于js或者旧版本cocos。这里记录一下ts显示Enum的方案,cocos版本使用的3.8.2。
解决方案
方案一:
import { _decorator, Component, TweenEasing } from 'cc';
const { ccclass, property } = _decorator;
const MyTweenEasing = Enum({
Linear : 0,
EaseIn : 1,
EaseOut : 2,
// 添加其他枚举值...
})
@ccclass
export class MyComponent extends Component {
@property({type: MyTweenEasing})
myTweenEasing = MyTweenEasing.Linear;
}
方案二:
import { _decorator, Component, TweenEasing } from 'cc';
const { ccclass, property,type } = _decorator;
const MyTweenEasing = Enum({
Linear : 0,
EaseIn : 1,
EaseOut : 2,
// 添加其他枚举值...
})
@ccclass
export class MyComponent extends Component {
@type(MyTweenEasing)
myTweenEasing = MyTweenEasing.Linear;
}
注意方案二要添加type。