Options
All
  • Public
  • Public/Protected
  • All
Menu

Module decorator

Index

References

boolean

Re-exports boolean

ccclass

Re-exports ccclass

disallowAnimation

Re-exports disallowAnimation

disallowMultiple

Re-exports disallowMultiple

displayName

Re-exports displayName

displayOrder

Re-exports displayOrder

editable

Re-exports editable

editorOnly

Re-exports editorOnly

executeInEditMode

Re-exports executeInEditMode

executionOrder

Re-exports executionOrder

float

Re-exports float

formerlySerializedAs

Re-exports formerlySerializedAs

help

Re-exports help

icon

Re-exports icon

inspector

Re-exports inspector

integer

Re-exports integer

menu

Re-exports menu

multiline

Re-exports multiline

override

Re-exports override

playOnFocus

Re-exports playOnFocus

radian

Re-exports radian

range

Re-exports range

rangeMax

Re-exports rangeMax

rangeMin

Re-exports rangeMin

rangeStep

Re-exports rangeStep

readOnly

Re-exports readOnly

requireComponent

Re-exports requireComponent

serializable

Re-exports serializable

slide

Re-exports slide

string

Re-exports string

tooltip

Re-exports tooltip

type

Re-exports type

unit

Re-exports unit

visible

Re-exports visible

Type aliases

BabelPropertyDecoratorDescriptor

BabelPropertyDecoratorDescriptor: PropertyDescriptor & { initializer?: any }

IPropertyOptions

IPropertyOptions: IExposedAttributes
zh

CCClass 属性选项。

en

CCClass property options

LegacyPropertyDecorator

LegacyPropertyDecorator: (target: Object, propertyKey: string | symbol, descriptor?: BabelPropertyDecoratorDescriptor) => void
en

The signature compatible with both TypeScript legacy decorator and Babel legacy decorator. The descriptor argument will only appear in Babel case.

zh

该签名同时兼容 TypeScript legacy 装饰器以及 Babel legacy 装饰器。 descriptor 参数只会在 Babel 情况下出现。

Type declaration

PropertyType

SimplePropertyType

SimplePropertyType: Function | string | typeof CCString | typeof CCInteger | typeof CCFloat | typeof CCBoolean

Variables

Const CACHE_KEY

CACHE_KEY: "__ccclassCache__" = "__ccclassCache__"

Const boolean

boolean: (target: Object, propertyKey: string | symbol) => void = type(CCBoolean)
en

Declare the property as boolean

zh

将该属性标记为布尔值。

Type declaration

    • (target: Object, propertyKey: string | symbol): void
    • Parameters

      • target: Object
      • propertyKey: string | symbol

      Returns void

Const ccclass

ccclass: (name?: undefined | string) => ClassDecorator & ClassDecorator = makeSmartClassDecorator<string>((constructor, name) => {let base = js.getSuper(constructor);if (base === Object) {base = null;}const proto = {name,extends: base,ctor: constructor,};const cache = constructor[CACHE_KEY];if (cache) {const decoratedProto = cache.proto;if (decoratedProto) {// decoratedProto.properties = createProperties(ctor, decoratedProto.properties);js.mixin(proto, decoratedProto);}constructor[CACHE_KEY] = undefined;}const res = CCClass(proto);// validate methodsif (DEV) {const propNames = Object.getOwnPropertyNames(constructor.prototype);for (let i = 0; i < propNames.length; ++i) {const prop = propNames[i];if (prop !== 'constructor') {const desc = Object.getOwnPropertyDescriptor(constructor.prototype, prop);const func = desc && desc.value;if (typeof func === 'function') {doValidateMethodWithProps_DEV(func, prop, js.getClassName(constructor), constructor, base);}}}}return res;})
en

Declare a standard class as a CCClass, please refer to the document

zh

将标准写法的类声明为 CC 类,具体用法请参阅类型定义

param

The class name used for serialization.

example
import { _decorator, Component } from 'cc';
const {ccclass} = _decorator;

// define a CCClass, omit the name
 @ccclass
class NewScript extends Component {
    // ...
}

// define a CCClass with a name
 @ccclass('LoginData')
class LoginData {
    // ...
}

Const disallowAnimation

disallowAnimation: LegacyPropertyDecorator = !EDITOR ? emptyDecorator : (target, propertyKey, descriptor) => property({__noImplicit: true,animatable: false,})(target, propertyKey, descriptor)
en

Sets the property so that it does not interop with the animation parts in editor.

zh

设置该属性不参与编辑器中动画相关的交互。

Const disallowMultiple

disallowMultiple: ClassDecorator & (yes?: undefined | false | true) => ClassDecorator = DEV ? makeSmartEditorClassDecorator('disallowMultiple', true) : emptySmartClassDecorator
en

Forbid add multiple instances of the component to the same node.

zh

防止多个相同类型(或子类型)的组件被添加到同一个节点。

example
import { _decorator, Component } from 'cc';
const {ccclass, disallowMultiple} = _decorator;

@ccclass
@disallowMultiple
class CameraCtrl extends Component {
    // ...
}

Const displayName

displayName: (text: string) => LegacyPropertyDecorator = !DEV ? emptyDecoratorFn: (text) => property(makeEditable({displayName: text,}))
en

Sets the display name of the property in editor.

zh

设置该属性在编辑器中的显示名称。

param

显示名称。

Type declaration

Const displayOrder

displayOrder: (order: number) => LegacyPropertyDecorator = !DEV ? emptyDecoratorFn: (order) => property(makeEditable({displayOrder: order,}))
en

Sets the display order of the property in editor.

zh

设置该属性在编辑器中的显示顺序。

param

显示顺序。

Type declaration

Const editable

editable: LegacyPropertyDecorator = !DEV ? emptyDecorator : (target, propertyKey, descriptor) => property(makeEditable({ }))(target, propertyKey, descriptor)
en

Enables the editor interoperability of the property.

zh

允许该属性与编辑器交互。

Const emptySmartClassDecorator

emptySmartClassDecorator: <TFunction>(target: TFunction) => TFunction | void & (arg?: TArg) => ClassDecorator = makeSmartClassDecorator(() => {})
en

Acts like emptyDecorator if called in form of @x; acts like emptyDecoratorFn if called in form of @x(...args).

zh

当以 @x 形式调用时表现如同 emptyDecorator,当以 @x(...args) 形式调用时表现如同 emptyDecoratorFn

Const executeInEditMode

executeInEditMode: ClassDecorator & (yes?: undefined | false | true) => ClassDecorator = DEV ? makeSmartEditorClassDecorator('executeInEditMode', true) : emptySmartClassDecorator
en

Makes a CCClass that inherit from component execute in edit mode.
By default, all components are only executed in play mode,
which means they will not have their callback functions executed while the Editor is in edit mode.

zh

允许继承自 Component 的 CCClass 在编辑器里执行。
默认情况下,所有 Component 都只会在运行时才会执行,也就是说它们的生命周期回调不会在编辑器里触发。

example
import { _decorator, Component } from 'cc';
const {ccclass, executeInEditMode} = _decorator;

 @ccclass
 @executeInEditMode
class NewScript extends Component {
    // ...
}

Const executionOrder

executionOrder: (priority: number) => ClassDecorator = makeEditorClassDecoratorFn('executionOrder')
en

Set the component priority, it decides at which order the life cycle functions of components will be invoked. Smaller priority get invoked before larger priority. This will affect onLoad, onEnable, start, update and lateUpdate, but onDisable and onDestroy won't be affected.

zh

设置脚本生命周期方法调用的优先级。优先级小于 0 的组件将会优先执行,优先级大于 0 的组件将会延后执行。优先级仅会影响 onLoad, onEnable, start, update 和 lateUpdate,而 onDisable 和 onDestroy 不受影响。

param

The execution order of life cycle methods for Component. Smaller priority get invoked before larger priority.

example
import { _decorator, Component } from 'cc';
const {ccclass, executionOrder} = _decorator;

@ccclass
@executionOrder(1)
class CameraCtrl extends Component {
    // ...
}

Type declaration

    • (priority: number): ClassDecorator
    • Parameters

      • priority: number

      Returns ClassDecorator

Const float

float: (target: Object, propertyKey: string | symbol) => void = type(CCFloat)
en

Declare the property as float

zh

将该属性标记为浮点数。

Type declaration

    • (target: Object, propertyKey: string | symbol): void
    • Parameters

      • target: Object
      • propertyKey: string | symbol

      Returns void

Const help

help: (url: string) => ClassDecorator = DEV ? makeEditorClassDecoratorFn('help') : emptyDecoratorFn
en

Define the help documentation url, if given, the component section in the inspector will have a help documentation icon reference to the web page given.

zh

指定当前组件的帮助文档的 url,设置过后,在 属性检查器 中就会出现一个帮助图标,用户点击将打开指定的网页。

param

The url of the help documentation

example
import { _decorator, Component } from 'cc';
const {ccclass, help} = _decorator;

@ccclass
@help("app://docs/html/components/spine.html")
class NewScript extends Component {
    // ...
}

Type declaration

    • (url: string): ClassDecorator
    • Parameters

      • url: string

      Returns ClassDecorator

Private Const icon

icon: (url: string) => ClassDecorator = DEV ? makeEditorClassDecoratorFn('icon') : emptyDecoratorFn
en

Define the icon of the component.

zh

自定义当前组件在编辑器中显示的图标 url。

param
example
import { _decorator, Component } from 'cc';
const {ccclass, icon} = _decorator;

 @ccclass
 @icon("xxxx.png")
class NewScript extends Component {
    // ...
}

Type declaration

    • (url: string): ClassDecorator
    • Parameters

      • url: string

      Returns ClassDecorator

Const inspector

inspector: (url: string) => ClassDecorator = DEV ? makeEditorClassDecoratorFn('inspector') : emptyDecoratorFn
en

Use a customized inspector page in the inspector

zh

自定义当前组件在 属性检查器 中渲染时所用的 UI 页面描述。

param

The url of the page definition in js

example
import { _decorator, Component } from 'cc';
const {ccclass, inspector} = _decorator;

@ccclass
@inspector("packages://inspector/inspectors/comps/camera-ctrl.js")
class NewScript extends Component {
    // ...
}

Type declaration

    • (url: string): ClassDecorator
    • Parameters

      • url: string

      Returns ClassDecorator

Const integer

integer: (target: Object, propertyKey: string | symbol) => void = type(CCInteger)
en

Declare the property as integer

zh

将该属性标记为整数。

Type declaration

    • (target: Object, propertyKey: string | symbol): void
    • Parameters

      • target: Object
      • propertyKey: string | symbol

      Returns void

Const menu

menu: (path: string) => ClassDecorator = DEV ? makeEditorClassDecoratorFn('menu') : emptyDecoratorFn
en

Add the current component to the specific menu path in Add Component selector of the inspector panel

zh

将当前组件添加到组件菜单中,方便用户查找。例如 "Rendering/CameraCtrl"。

param

The path is the menu represented like a pathname. For example the menu could be "Rendering/CameraCtrl".

example
import { _decorator, Component } from 'cc';
const {ccclass, menu} = _decorator;

@ccclass
@menu("Rendering/CameraCtrl")
class NewScript extends Component {
    // ...
}

Type declaration

    • (path: string): ClassDecorator
    • Parameters

      • path: string

      Returns ClassDecorator

Const multiline

multiline: LegacyPropertyDecorator = !DEV ? emptyDecorator: (target, propertyKey, descriptor) => property(makeEditable({multiline: true,}))(target, propertyKey, descriptor)
en

Enable multi-line display of the property in editor.

zh

允许在编辑器中对该属性进行多行显示。

Const playOnFocus

playOnFocus: ClassDecorator & (yes?: undefined | false | true) => ClassDecorator = DEV ? makeSmartEditorClassDecorator<boolean>('playOnFocus', true) : emptySmartClassDecorator
en

When {{executeInEditMode}} is set, this decorator will decide when a node with the component is on focus whether the editor should running in high FPS mode.

zh

当指定了 "executeInEditMode" 以后,playOnFocus 可以在选中当前组件所在的节点时,提高编辑器的场景刷新频率到 60 FPS,否则场景就只会在必要的时候进行重绘。

example
import { _decorator, Component } from 'cc';
const {ccclass, playOnFocus, executeInEditMode} = _decorator;

@ccclass
@executeInEditMode
@playOnFocus
class CameraCtrl extends Component {
    // ...
}

Const radian

radian: LegacyPropertyDecorator = !DEV ? emptyDecorator: (target, propertyKey, descriptor) => property(makeEditable({radian: true,}))(target, propertyKey, descriptor)
en

Sets to convert the value into radian before feed it to the property in editor.

zh

设置在编辑器中赋值该属性前将值先转换为弧度制。

Const range

range: (values: [] | []) => LegacyPropertyDecorator = !DEV ? emptyDecoratorFn: (values) => property(makeEditable({range: values,}))
en

Sets the allowed range of the property in editor.

zh

设置该属性在编辑器中允许设置的范围。

param

范围。

Type declaration

Const rangeMax

rangeMax: (value: number) => LegacyPropertyDecorator = !DEV ? emptyDecoratorFn: (value) => property(makeEditable({max: value,}))
en

Sets the allowed max value of the property in editor.

zh

设置该属性在编辑器中允许的最大值。

param

最大值。

Type declaration

Const rangeMin

rangeMin: (value: number) => LegacyPropertyDecorator = !DEV ? emptyDecoratorFn: (value) => property(makeEditable({min: value,}))
en

Sets the allowed min value of the property in editor.

zh

设置该属性在编辑器中允许的最小值。

param

最小值。

Type declaration

Const rangeStep

rangeStep: (value: number) => LegacyPropertyDecorator = !DEV ? emptyDecoratorFn: (value) => property(makeEditable({step: value,}))
en

Sets the step of the property in editor.

zh

设置该属性在编辑器中的步进值。

param

步进值。

Type declaration

Const readOnly

readOnly: LegacyPropertyDecorator = !DEV ? emptyDecorator : (target, propertyKey, descriptor) => property(makeEditable({readonly: true,}))(target, propertyKey, descriptor)
en

Sets the property to be read only in editor.

zh

设置该属性在编辑器中仅是可读的。

Const requireComponent

requireComponent: (requiredComponent: Function) => ClassDecorator = makeEditorClassDecoratorFn('requireComponent')
en

Declare that the current component relies on another type of component. If the required component doesn't exist, the engine will create a new empty instance of the required component and add to the node.

zh

为声明为 CCClass 的组件添加依赖的其它组件。当组件添加到节点上时,如果依赖的组件不存在,引擎将会自动将依赖组件添加到同一个节点,防止脚本出错。该设置在运行时同样有效。

param

The required component type

example
import {_decorator, Sprite, Component} from cc;
import {ccclass, requireComponent} from _decorator;

@ccclass
@requireComponent(Sprite)
class SpriteCtrl extends Component {
    // ...
}

Type declaration

    • (requiredComponent: Function): ClassDecorator
    • Parameters

      • requiredComponent: Function

      Returns ClassDecorator

Const slide

slide: LegacyPropertyDecorator = !DEV ? emptyDecorator: (target, propertyKey, descriptor) => property(makeEditable({slide: true,}))(target, propertyKey, descriptor)
en

Enable a slider be given to coordinate the property in editor.

zh

允许在编辑器中提供滑动条来调节值

Const string

string: (target: Object, propertyKey: string | symbol) => void = type(CCString)
en

Declare the property as string

zh

将该属性标记为字符串。

Type declaration

    • (target: Object, propertyKey: string | symbol): void
    • Parameters

      • target: Object
      • propertyKey: string | symbol

      Returns void

Const tooltip

tooltip: (text: string) => LegacyPropertyDecorator = !DEV ? emptyDecoratorFn: (text) => property(makeEditable({tooltip: text,}))
en

Sets the tooltip content of the property in editor.

zh

设置该属性在编辑器中的工具提示内容。

param

工具提示。

Type declaration

Const unit

unit: (name: "lm" | "lx" | "cd/m²") => LegacyPropertyDecorator = !DEV ? emptyDecoratorFn: (name) => property(makeEditable({unit: name,}))
en

Sets the unit of the property in editor.

zh

设置该属性在编辑器中的计量单位。

param

计量单位的名称。

Type declaration

Const visible

visible: (condition: boolean | (() => boolean)) => LegacyPropertyDecorator = !DEV ? emptyDecoratorFn: (condition) => property(makeEditable({visible: condition,}))
en

Sets the condition to show the property.

zh

设置在编辑器展示该属性的条件。

param

展示条件,当返回 true 时展示;否则不展示。

Type declaration

Functions

Const editorOnly

  • editorOnly(target: Object, propertyKey: string | symbol, descriptor: undefined | (PropertyDescriptor & { initializer?: any })): void
  • 设置该属性仅在编辑器中生效。

    Parameters

    • target: Object
    • propertyKey: string | symbol
    • descriptor: undefined | (PropertyDescriptor & { initializer?: any })

    Returns void

Const emptyDecorator

  • emptyDecorator(): void

Const emptyDecoratorFn

  • emptyDecoratorFn(): <TFunction>(target: TFunction) => TFunction | void & (target: Object, propertyKey: string | symbol, descriptor?: BabelPropertyDecoratorDescriptor) => void

extractActualDefaultValues

  • extractActualDefaultValues(ctor: any): any

formerlySerializedAs

genProperty

  • genProperty(ctor: any, properties: any, propertyKey: Parameters<LegacyPropertyDecorator>[1], options: any, descriptor: Parameters<LegacyPropertyDecorator>[2] | undefined, cache: any): void
  • Parameters

    • ctor: any
    • properties: any
    • propertyKey: Parameters<LegacyPropertyDecorator>[1]
    • options: any
    • descriptor: Parameters<LegacyPropertyDecorator>[2] | undefined
    • cache: any

    Returns void

getClassCache

  • getClassCache(ctor: any, decoratorName?: any): any

getDefaultFromInitializer

  • getDefaultFromInitializer(initializer: any): any

getSubDict

  • getSubDict(obj: any, key: any): any

makeEditable

makeEditorClassDecoratorFn

  • makeEditorClassDecoratorFn<TValue>(propertyName: string): (value: TValue) => ClassDecorator
  • 创建一个函数,该函数接受一个参数值并返回一个类装饰器。 该装饰器将被装饰类的编辑器属性 propertyName 设置为该参数的值。

    Type parameters

    • TValue

    Parameters

    • propertyName: string

      The editor property.

    Returns (value: TValue) => ClassDecorator

      • (value: TValue): ClassDecorator
      • Parameters

        • value: TValue

        Returns ClassDecorator

makeSerializable

makeSmartClassDecorator

  • makeSmartClassDecorator<TArg>(decorate: <TFunction>(constructor: TFunction, arg?: TArg) => ReturnType<ClassDecorator>): ClassDecorator & (arg?: TArg) => ClassDecorator
  • 创建一个智能类装饰器,它能正确地处理以下形式的装饰器语法:

    • @x
    • @x(arg0)

    并且,将被装饰的类和 arg0(若是第一种形式,arg0 就是 undefined)一起转发给 decorate

    Type parameters

    • TArg

    Parameters

    • decorate: <TFunction>(constructor: TFunction, arg?: TArg) => ReturnType<ClassDecorator>
        • <TFunction>(constructor: TFunction, arg?: TArg): ReturnType<ClassDecorator>
        • Type parameters

          • TFunction: Function

          Parameters

          • constructor: TFunction
          • Optional arg: TArg

          Returns ReturnType<ClassDecorator>

    Returns ClassDecorator & (arg?: TArg) => ClassDecorator

makeSmartEditorClassDecorator

  • makeSmartEditorClassDecorator<TValue>(propertyName: string, defaultValue: TValue): <TFunction>(target: TFunction) => TFunction | void & (arg?: TArg) => ClassDecorator
  • Make a smart class decorator. The smart decorator sets the editor property propertyName, on the decorated class, into:

    • defaultValue if the decorator is called with @x form, or
    • the argument if the decorator is called with an argument, eg, the @x(arg0) form.

    创建一个智能类装饰器。 该智能类装饰器将根据以下情况来设置被装饰类的编辑器属性 propertyName

    • 如果该装饰器是以 @x 形式调用的,该属性将被设置为 defaultValue
    • 如果该装饰器是以一个参数的形式,即 @x(arg0) 的形式调用的,该属性将被设置为传入的参数值。

    Type parameters

    • TValue

    Parameters

    • propertyName: string

      The editor property.

    • defaultValue: TValue

    Returns <TFunction>(target: TFunction) => TFunction | void & (arg?: TArg) => ClassDecorator

Const override

  • override(target: Object, propertyKey: string | symbol, descriptor: undefined | (PropertyDescriptor & { initializer?: any })): void

property

Const serializable

  • serializable(target: Object, propertyKey: string | symbol, descriptor: undefined | (PropertyDescriptor & { initializer?: any })): void

type

  • type(type: Function | [] | any): PropertyDecorator
  • type<T>(type: PrimitiveType<T> | []): PropertyDecorator

writeEditorClassProperty

  • writeEditorClassProperty<TValue>(constructor: Function, propertyName: string, value: TValue): void

Generated using TypeDoc