Skip to content
DrawBoard

界面 / DrawBoard

DrawBoard Class
​

UI 画板

Hierarchy ​

Table of contents ​

Properties
​

click

Properties
​

onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> client
监听自定义属性同步事件

Accessors
​

canRedo(): boolean client
获取当前是否可以恢复上次的撤销
canUndo(): boolean client
获取当前是否可以撤销一次事务
maxTransactionSize(): number client
最大撤销恢复的数据栈内存大小,单位字节,默认20MB,必须在有绘制操作前才能生效
click

Accessors
​

alignPosition(): Readonly<Vector2> client
获取控件的对齐位置,在对齐方式为靠右对齐、靠下对齐、中心对齐时,alignPosition的值与positon不同;
autoSizeHorizontalEnable(): boolean client
获取是否自动水平设置大小
autoSizeVerticalEnable(): boolean client
获取是否自动垂直设置大小
cachedGeometry(): Geometry client
获取上一次的GetTickSpaceGeometry
constraints(): Readonly<UIConstraintAnchors> client
获取控件的布局
desiredSize(): Vector2 client
获取期望大小
enable(): boolean client
是否可用
guid(): string client
获取控件GUID
isHovered(): boolean client
是否是hovered
mouseCursor(): MouseCursor client
获取控件上光标类型
name(): string client
获取名字
paintSpaceGeometry(): Geometry client
获取最后一次用于渲染Widget的几何信息
parent(): Widget client
获取父节点
pivot(): Vector2 client
获取控件锚点位置,这个属性决定了控件图形与锚点的相对位置;(0,0)时,锚点位于控件左上角;(0.5,0.5)时,锚点位于控件正中心
position(): Readonly<Vector2> client
获取控件的位置
renderOpacity(): number client
获取渲染透明度
renderScale(): Vector2 client
获取渲染缩放
renderShear(): Vector2 client
获取渲染错切形变
renderTransformAngle(): number client
获取渲染的角度
renderTransformPivot(): Vector2 client
获取渲染锚点
size(): Vector2 client
获取大小
tickSpaceGeometry(): Geometry client
获取最后一次用于驱动Widget Tick的几何信息
transform(): Readonly<UITransform> client
得到控件的大小和位置
visibility(): SlateVisibility client
获取可见性
visible(): boolean client
是否可见
zOrder(): number client
获取zorder

Methods
​

addTransaction(): void client
提交一次撤销恢复的事务,会把之前的数据和当前数据进行比较,完成一次撤销恢复事务
clearDraws(): void client
清除全部绘制
drawCustom(vertex: UIDrawCustomVertex[], index: number[], assetId?: string, drawLayerId?: number): number client
自定义绘制图元
drawLines(points: Vector2[], lineData?: DrawDataBase): number client
画多段线
drawText(text: string, position: Vector2, fontSize: number, fontColor: LinearColor, drawLayerId?: number): number client
画文字
exportSaveData(name: string): boolean client
导出当前画布信息到缓存文件
fillCircle(center: Vector2, radius: number, color: LinearColor): void client
填充自定圆形区域内的像素颜色
importSaveData(name: string): boolean client
导入缓存文件到当前画布
redo(): boolean client
恢复一次上次的撤销
undo(): boolean client
撤销一次事务
newObject(parent?: Canvas, inName?: string): DrawBoard client
创建绘画控件
click

Methods
​

addChild(child: Widget): void client
添加子节点
clone(position: Vector2, Parent?: Widget): Widget client
克隆UI控件及其子节点到指定父控件位置(默认到其父节点)
destroyObject(): void client
立刻移除并销毁 不可以在使用
equal(that: Widget): boolean client
判断是不是同一个对象
findChildByPath(inPath: string): Widget client
通过相对路径查找节点
getChildAt(index: number): Widget client
获取第几位子节点
getChildByName<T: extends Widget<T>>(name: string): T: extends Widget<T> client
通过名字查找节点
getChildrenCount(): number client
获取子节点数量
getCustomProperties(): string[] client
获取所有自定义属性
getCustomProperty<T: extends CustomPropertyType>(propertyName: string): T: extends CustomPropertyType client
获取自定义属性
getCustomPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> client
给定对象属性修改时触发的事件代理
invalidateLayoutAndVolatility(): void client
立刻触发重新渲染的和排布计算
isValid(): boolean client
判断控件有没有被销毁,是否是有效的控件
removeAllChildren(): void client
清除所有子节点,会销毁UI无法再使用
removeChild(child: Widget): void client
移除节点,会销毁UI无法在使用
removeChildAt(index: number): void client
移除第几个节点,会销毁UI无法再使用
removeObject(): void client
立刻移除并添加到根节点 可以再使用
serialize(): string client
序列化UI控件
setCustomProperty(propertyName: string, value: undefined CustomPropertyType): void client
设置自定义属性
deserialize(Data: string, Parent?: Widget): Widget client
反序列化UI

Properties ​

Accessors ​


canRedo
​

• get canRedo(): boolean client

获取当前是否可以恢复上次的撤销

Returns ​

boolean返回撤销恢复是否可执行

canUndo
​

• get canUndo(): boolean client

获取当前是否可以撤销一次事务

Returns ​

boolean返回撤销恢复是否可执行

maxTransactionSize
​

• get maxTransactionSize(): number client

• set maxTransactionSize(count): void client

最大撤销恢复的数据栈内存大小,单位字节,默认20MB,必须在有绘制操作前才能生效

Returns ​

number返回最大撤销恢复的数据栈内存大小

最大撤销恢复的数据栈内存大小,单位字节,默认20MB,必须在有绘制操作前才能生效

Parameters ​

count number字节大小 count: >0 type: 整形

返回最大撤销恢复的数据栈内存大小

Methods ​


addTransaction
​

• addTransaction(): void client

提交一次撤销恢复的事务,会把之前的数据和当前数据进行比较,完成一次撤销恢复事务


clearDraws
​

• clearDraws(): void client

清除全部绘制


drawCustom
​

• drawCustom(vertex, index, assetId?, drawLayerId?): number client

自定义绘制图元

Parameters ​

vertex UIDrawCustomVertex[]顶点图元数据信息
index number[]顶点图元索引信息
assetId? stringUI贴图资源 default: "" range: 无
drawLayerId? number绘制层级 default: 0 range: 无 type: 整形

Returns ​

number返回drawId

drawLines
​

• drawLines(points, lineData?): number client

画多段线

Parameters ​

points Vector2[]线的各个点坐标
lineData? DrawDataBase绘制图元信息 default: new DrawDataBase()

Returns ​

number返回drawId

drawText
​

• drawText(text, position, fontSize, fontColor, drawLayerId?): number client

画文字

Parameters ​

text string要绘制的文本 range: 无
position Vector2位置
fontSize number字体大小 type: 整形 range: 无
fontColor LinearColor颜色
drawLayerId? number绘制层级 default: 0 range: 无 type: 整形

Returns ​

number返回drawId

exportSaveData
​

• exportSaveData(name): boolean client

导出当前画布信息到缓存文件

Parameters ​

name string导出文件名字 range: 无

Returns ​

boolean是否成功

fillCircle
​

• fillCircle(center, radius, color): void client

填充自定圆形区域内的像素颜色

Parameters ​

center Vector2圆中心
radius number圆半径 range: >0 type: 整形
color LinearColor填充颜色

importSaveData
​

• importSaveData(name): boolean client

导入缓存文件到当前画布

Parameters ​

name string导出文件名字 range: 无

Returns ​

boolean是否成功

redo
​

• redo(): boolean client

恢复一次上次的撤销

Returns ​

boolean返回撤销恢复是否成功

undo
​

• undo(): boolean client

撤销一次事务

Returns ​

boolean返回撤销恢复是否成功

newObject
​

• Static newObject(parent?, inName?): DrawBoard client

创建绘画控件

Parameters ​

parent? Canvas创建控件的外parent对象 default: null
inName? string创建控件的名称 default:null range:设置合理的名称即可

Returns ​

DrawBoard返回创建的对象

当parent和inName与已有的对象相同时,旧的对象会被销毁