1

这个问题严格与 TypeScript 相关。如果我在 Cocos Creator 中有基于 JavaScript 的 Cocos 项目,我遇到的问题可以完美运行。

我在名为 enums 的文件中有以下枚举。

export const enum CollisionType {
Static=    0,
Dynamic=   1,
Solid=     2,
SemiSolid= 3
}

在我的 game.ts 文件中,我有以下内容

import {CollisionType} from "./Enums";

export default class PlayerControl extends cc.Component {

@property (CollisionType)
collisionType:CollisionType = CollisionType.Static;

但不幸的是,这不起作用。我在 CollisionType 下得到一条红线,并出现以下错误:

Argument of type 'typeof CollisionType' is not assignable to parameter of type 'string | number | boolean | Function | any[] | { type?: any; visible?: boolean | (() => boolean); displayName?: string; tooltip?: string; multiline?: boolean; readonly?: boolean; min?: number; max?: number; ... 7 more ...; animatable?: boolean; } | ValueType'.

如果我没有将@property 设置为我的变量,它可以正常工作,但是无法在 Cocos Creator 编辑器中编辑该值。

有任何想法吗?

4

1 回答 1

5

试试下面的代码

@property ({type:Enum(CollisionType)})
private collisionType:CollisionType = CollisionType.Static;
于 2018-08-31T13:16:46.120 回答