Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Prefab

Class for prefab handling.

Hierarchy

Index

Constructors

constructor

Properties

__asyncLoadAssets__

__asyncLoadAssets__: boolean = false

__depends__

__depends__: any = null

__nativeDepend__

__nativeDepend__: any = null

__onLoadedInvoked__

__onLoadedInvoked__: boolean = false

Private _createFunction

_createFunction: Function | null

Private _instantiatedTimes

_instantiatedTimes: number

_native

_native: string = ""

Serializable url for native asset. For internal usage.

default

""

_nativeUrl

_nativeUrl: string = ""

_uuid

_uuid: string

asyncLoadAssets

asyncLoadAssets: boolean = false

Indicates the native assets of this prefab can be load after prefab loaded.

default

false

data

data: any = null

The main Node in the prefab

loaded

loaded: boolean = true

Whether the asset is loaded or not

optimizationPolicy

optimizationPolicy: number = OptimizationPolicy.AUTO

Indicates the optimization policy for instantiating this prefab. Set to a suitable value based on usage, can optimize the time it takes to instantiate this prefab. Suggest to set this policy in the editor's asset inspector.

default

Prefab.OptimizationPolicy.AUTO

example
import { Prefab } from 'cc';
prefab.optimizationPolicy = Prefab.OptimizationPolicy.MULTI_INSTANCE;

Static OptimizationPolicy

OptimizationPolicy: { AUTO: number; MULTI_INSTANCE: number; SINGLE_INSTANCE: number } = OptimizationPolicy

Enumeration for optimization policy

Type declaration

  • AUTO: number
    en

    The optimization policy is automatically chosen based on the number of instantiations. When you first create an instance, the behavior is the same as SINGLE_INSTANCE. MULTI_INSTANCE will be automatically used after multiple creation.

    zh

    根据创建次数自动调整优化策略。初次创建实例时,行为等同 SINGLE_INSTANCE,多次创建后将自动采用 MULTI_INSTANCE。

  • MULTI_INSTANCE: number
    en

    Optimize for creating instances multiple times.
    This option enables code generation for this prefab. When this prefab will usually create multiple instances, please select this option. It is also recommended to select this option if the prefab instance in the scene has Auto Sync enabled and there are multiple instances in the scene.

    zh

    优化多次创建性能。
    该选项会启用针对这个 prefab 的代码生成优化操作。当该 prefab 加载后,一般会创建多个实例时,请选择此项。如果该 prefab 在场景中的节点启用了自动关联,并且在场景中有多份实例,也建议选择此项。

  • SINGLE_INSTANCE: number
    en

    Optimize for single instance creation.
    This option skips code generation for this prefab. When this prefab will usually create only one instances, please select this option.

    zh

    优化单次创建性能。
    该选项会跳过针对这个 prefab 的代码生成优化操作。当该 prefab 加载后,一般只会创建一个实例时,请选择此项。

Static OptimizationPolicyThreshold

OptimizationPolicyThreshold: number = 3

Static _utils

_utils: "D:/workCode/editor-3d/resources/3d/engine/cocos/core/utils/prefab-utils"

for internal use

Static preventDeferredLoadDependents

preventDeferredLoadDependents: boolean = false

Indicates whether its dependent native assets can support deferred load if the owner scene (or prefab) is marked as asyncLoadAssets.

default

false

Static preventPreloadNativeObject

preventPreloadNativeObject: boolean = false

Indicates whether its native object should be preloaded from native url.

default

false

Accessors

Private nativeAsset

  • get nativeAsset(): any
  • set nativeAsset(obj: any): void
  • The underlying native asset of this asset if one is available.
    This property can be used to access additional details or functionality releated to the asset.
    This property will be initialized by the loader if _native is available.

    default

    null

    Returns any

  • The underlying native asset of this asset if one is available.
    This property can be used to access additional details or functionality releated to the asset.
    This property will be initialized by the loader if _native is available.

    default

    null

    Parameters

    • obj: any

    Returns void

nativeDep

  • get nativeDep(): undefined | { __isNative__: boolean; ext: string; uuid: string }

nativeUrl

  • get nativeUrl(): string

refCount

  • get refCount(): number

Methods

Private doInstantiate

  • doInstantiate(rootToRedirect?: any): any

Private instantiate

  • _instantiate(): any

Private setRawAsset

  • setRawAsset(filename: string, inLibrary?: boolean): void

addRef

compileCreateFunction

  • compileCreateFunction(): void
  • Dynamically translation prefab data into minimized code.
    This method will be called automatically before the first time the prefab being instantiated,
    but you can re-call to refresh the create function once you modified the original prefab data in script.

    Returns void

createNode

  • createNode(cb: Function): void

decRef

  • decRef(autoRelease?: boolean): Asset

onLoaded

  • onLoaded(): void

Private serialize

  • serialize(): void

toString

  • toString(): string
  • Returns the string representation of the object.
    The Asset object overrides the toString() method of the Object object.
    JavaScript calls the toString() method automatically
    when an asset is to be represented as a text value or when a texture is referred to in a string concatenation.

    For assets of the native type, it will return this.nativeUrl.
    Otherwise, an empty string is returned.
    This method may be overwritten by subclasses.

    method

    toString

    Returns string

Static deserialize

  • deserialize(data: any): any

Generated using TypeDoc