Skip to content
UIWidget

UI / UIWidget

UIWidget Class

World UI


  1. UI The interface is divided into two types: screen UI and world UI.

UIWidget It is specially used to make world UI. Please refer to UIService or UserWidget for the detailed production method of screen UI.

  1. UIWidget There are two ways to create a world UI:
  • 🌵 Dynamic loading (only use code to dynamically create a world UI)

Usage example: create a script named NewScript, place it in the object bar, open the script, modify the original content to the following, save and run the game, and generate a world UI in the scene - slider

ts
@Component
export default class NewScript extends Script {

    user:UserWidget;
    widget:UIWidget;
    progressBar:ProgressBar;

    protected onStart(): void {
        if(SystemUtil.isClient()){
            this.creatUI();
            this.widget = GameObject.spawn<UIWidget>("UIWidget",{replicates:false});
            this.widget.worldTransform.position = new Vector(0,0,100);
            this.widget.setTargetUIWidget(this.user);
        }
    }

    public creatUI(){
        this.user = UserWidget.newObject();

        let rootCanvas = Canvas.newObject();
        rootCanvas.size = new Vector2(1920, 1080);
        rootCanvas.position = Vector2.zero;

        this.user.rootContent = rootCanvas;

        this.progressBar = ProgressBar.newObject(rootCanvas);
    }
}
@Component
export default class NewScript extends Script {

    user:UserWidget;
    widget:UIWidget;
    progressBar:ProgressBar;

    protected onStart(): void {
        if(SystemUtil.isClient()){
            this.creatUI();
            this.widget = GameObject.spawn<UIWidget>("UIWidget",{replicates:false});
            this.widget.worldTransform.position = new Vector(0,0,100);
            this.widget.setTargetUIWidget(this.user);
        }
    }

    public creatUI(){
        this.user = UserWidget.newObject();

        let rootCanvas = Canvas.newObject();
        rootCanvas.size = new Vector2(1920, 1080);
        rootCanvas.position = Vector2.zero;

        this.user.rootContent = rootCanvas;

        this.progressBar = ProgressBar.newObject(rootCanvas);
    }
}
  • 🌵 Mount the world UI logic object on the object in advance in the object manager, and place the corresponding UIPrefab in the property panel.

Hierarchy

Table of contents

Properties

click

Properties

onBeforeDestroyDelegate: MulticastDelegate<() => void> other
Event callback before object destruction
onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Monitor custom attribute synchronization events
onDestroyDelegate: MulticastDelegate<() => void> other
Event callback after object destruction
onPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>>
Monitor system replicated events

Accessors

distanceScaleFactor(): number
Obtain the scaling distance coefficient
drawSize(): Vector2
Obtain the actual rendering size
extraParam(): string
Get extended parameters
headUIMaxVisibleDistance(): number
Get the maximum visible distance of overhead UI
hideByDistanceEnable(): boolean
Get whether to enable maximum visible distance
interaction(): boolean other
Get World UI interaction status
isEnemy(): boolean
Get whether to be an enemy Player. The enemy Player does not display overhead UI
occlusionEnable(): boolean
Obtain whether it can be obstructed
pivot(): Vector2
Obtain anchor point location
scaledByDistanceEnable(): boolean
Get whether to enable near large far small
selfOcclusion(): boolean
Obtain whether it can be obscured by oneself
translucentSortPriority(): number other
Get the render layer. Objects at higher render layer will be displayed closer to the line of sight
widgetSpace(): WidgetSpaceMode
Get display mode
click

Accessors

actorFlagValue(): number other
Get object tags
actorLevel(): number other
Obtain Actor Level
assetId(): string other
Retrieve the UID of the resource currently being used by the object
gameObjectId(): string other
Get the unique identification of an object (a string that uniquely identifies an object).
isDestroyed(): boolean other
Has the current object been destroyed
isReady(): boolean other
Current object status
localTransform(): Transform other
Local transformation of the current object
name(): string other
Return the current object name
netStatus(): NetStatus other
Get the current object synchronization status
parent(): GameObject other
Retrieve the current parent object
tag(): string other
Get the tag of the current object
worldTransform(): Transform other
Current object world transformation

Methods

getTargetUIWidget(): UserWidget other
Retrieve UI object resources
refresh(): void other
Request to redraw
setTargetUIWidget(uiUserWidget: UserWidget): void other
Set UI, which can set UI resources for the current UI. UI resources can be obtained from paths or directly referenced by other UI components
setUIbyID(ID: string): void other
Set UI through UID
click

Methods

addComponent<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>, bInReplicates?: boolean): T: extends Script<T> other
Add a script component
asyncGetChildByName(name: string): Promise<GameObject> other
Asynchronous search for sub objects based on their names
asyncReady(): Promise<GameObject> other
Return after the object is ready
clone(gameObjectInfo?: GameObjectInfo): GameObject other
Copy Objects
destroy(): void other
delete object
getBoundingBox(nonColliding?: boolean, includeFromChild?: boolean, outer?: Vector): Vector other
Get the size of the object's bounding box
getBounds(onlyCollidingComponents: boolean, originOuter: Vector, boxExtentOuter: Vector, includeFromChild?: boolean): void other
Obtain object boundaries
getChildByGameObjectId(gameObjectId: string): GameObject other
Search for sub objects based on gameObjectid
getChildByName(name: string): GameObject other
Search for sub objects by name
getChildByPath(path: string): GameObject other
Find sub objects according to path
getChildren(): GameObject[] other
Obtain sub objects
getChildrenBoundingBoxCenter(outer?: Vector): Vector other
Get the center point of all child objects' bounding box (not including the parent object, if the parent object is unavailable, return [0,0,0])
getChildrenByName(name: string): GameObject[] other
Search for all sub objects by name
getComponent<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T> other
Get the component of the specified type
getComponentPropertys<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>): Map<string, IPropertyOptions> other
Get property of script component
getComponents<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T>[] other
Get all component of the specified type
getCustomProperties(): string[] other
Get all customize property
getCustomProperty<T: extends CustomPropertyType>(propertyName: string): T: extends CustomPropertyType other
Get customize property
getCustomPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Event proxy triggered when a given object property is modified
getPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Event proxy triggered when a given object property is modified
getVisibility(): boolean other
Obtain whether the object is displayed
isPrefabActor(): boolean other
Return whether the current object is a prefabricated body
moveBy(velocity: Vector, isLocal?: boolean): void other
Smoothly move an object over time according to a given velocity vector
moveTo(targetPosition: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly move from the current position to the target position within the specified time
rotateBy(rotation: Quaternion Rotation, multiplier: number, isLocal?: boolean): void other
Rotate the object smoothly over time according to the given rotation amount
rotateTo(targetRotation: Quaternion Rotation, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly changes from the current rotation to the target rotation within the specified time
scaleBy(scale: Vector, isLocal?: boolean): void other
Smoothly scale objects over time using a given scaling vector per second
scaleTo(targetScale: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly changes from the current scale to the target scale within the specified time
setAbsolute(absolutePosition?: boolean, absoluteRotation?: boolean, absoluteScale?: boolean): void other
Set whether the object localTransform is relative to the parent object or the world
setCustomProperty(propertyName: string, value: undefined CustomPropertyType): void other
Set custom attributes
setVisibility(status: boolean PropertyStatus, propagateToChildren?: boolean): void other
Set whether the object is displayed
stopMove(): void other
Interrupt further movement of moveTo() and moveBy()
stopRotate(): void other
Interrupt further rotation from rotateTo() or rotateBy()
stopScale(): void other
Interrupt further scale from ScaleTo() or ScaleBy()
asyncFindGameObjectById(gameObjectId: string): Promise<GameObject> other
Asynchronous search for GameObject through gameObjectid
asyncGetGameObjectByPath(path: string): Promise<GameObject> other
Asynchronously find objects through path
asyncSpawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): Promise<T: extends GameObject<T>> other
Asynchronous construction of an object
bulkPivotTo(gameObjects: GameObject[], transforms: Transform[]): void other
Batch set position
findGameObjectById(gameObjectId: string): GameObject other
Search for objects through gameObjectid
findGameObjectByName(name: string): GameObject other
Search for objects by name
findGameObjectsByName(name: string): GameObject[] other
Search for objects by name
findGameObjectsByTag(tag: string): GameObject[] other
Get objects through customize tag
getGameObjectByPath(path: string): GameObject other
Search for objects through paths
spawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): T: extends GameObject<T> other
Construct an object

Properties

Accessors


distanceScaleFactor

get distanceScaleFactor(): number

set distanceScaleFactor(Value): void

Obtain the scaling distance coefficient

Returns

numberDistance coefficient

Set scale distance coefficient

Parameters

Value numberUsage: Distance coefficient

drawSize

get drawSize(): Vector2

set drawSize(newSize): void

Obtain the actual rendering size

Returns

Vector2Rendering Size 2D

Set the actual rendering size

Parameters

newSize Vector2Usage: render size 2D

extraParam

get extraParam(): string

set extraParam(Value): void

Get extended parameters

Returns

stringExtended parameters

Set extension parameters

Parameters

Value stringUsage: Extended Parameters

headUIMaxVisibleDistance

get headUIMaxVisibleDistance(): number

set headUIMaxVisibleDistance(Value): void

Get the maximum visible distance of overhead UI

Returns

numberVisible distance

Set the maximum visible distance of overhead UI

Parameters

Value numberUsage: visible distance

hideByDistanceEnable

get hideByDistanceEnable(): boolean

set hideByDistanceEnable(Value): void

Get whether to enable maximum visible distance

Returns

booleanTrue: Enable

Set whether to enable the maximum visible distance

Parameters

Value booleanUsage: Boolean value

interaction

get interaction(): boolean other

set interaction(inInteraction): void other

Get World UI interaction status

Precautions

Effective for World UI and overhead UI

Returns

booleanIs it interactive

Set World UI interaction state

Precautions

Effective for World UI and overhead UI

Parameters

inInteraction booleanUsage: Is it interactive

Is the setting successful


isEnemy

get isEnemy(): boolean

set isEnemy(Value): void

Get whether to be an enemy Player. The enemy Player does not display overhead UI

Returns

booleanBoolean value

Set whether as an enemy player, enemy players will not display the overhead UI

Parameters

Value booleanUsage: Boolean value

occlusionEnable

get occlusionEnable(): boolean

set occlusionEnable(Value): void

Obtain whether it can be obstructed

Returns

booleanTrue: Can be obscured

Set whether it can be obscured

Parameters

Value booleanUsage: Boolean value

pivot

get pivot(): Vector2

set pivot(position): void

Obtain anchor point location

Returns

Vector2position information

Set anchor position

Parameters

position Vector2Usage: Location information

scaledByDistanceEnable

get scaledByDistanceEnable(): boolean

set scaledByDistanceEnable(Value): void

Get whether to enable near large far small

Returns

booleanTrue: Enable

Set whether to enable near large far small

Parameters

Value booleanUsage: Boolean value

selfOcclusion

get selfOcclusion(): boolean

set selfOcclusion(Value): void

Obtain whether it can be obscured by oneself

Returns

booleanBoolean value

Set whether it can be obscured by oneself

Parameters

Value booleanUsage: Boolean value

translucentSortPriority

get translucentSortPriority(): number other

set translucentSortPriority(value): void other

Get the render layer. Objects at higher render layer will be displayed closer to the line of sight

Precautions

Please call on the client side

Returns

number

Set the rendering layer. Objects at higher rendering layer will be displayed closer to the line of sight

Precautions

Please call on the client side

Parameters

value numberNew rendering level with a value range of [0, 31]

widgetSpace

get widgetSpace(): WidgetSpaceMode

set widgetSpace(newSpace): void

Get display mode

Returns

WidgetSpaceModeDisplay method enumeration

Set display mode

Parameters

newSpace WidgetSpaceModeUsage: Display mode

Methods


getTargetUIWidget

getTargetUIWidget(): UserWidget other

Retrieve UI object resources

Returns

UserWidgetUI Object asset

refresh

refresh(): void other

Request to redraw


setTargetUIWidget

setTargetUIWidget(uiUserWidget): void other

Set UI, which can set UI resources for the current UI. UI resources can be obtained from paths or directly referenced by other UI components

Parameters

uiUserWidget UserWidgetUsage: UI resource object

setUIbyID

setUIbyID(ID): void other

Set UI through UID

Parameters

ID stringUI ID range: determined by the length of the resource ID