[开发者心得] 常见的世界UI用什么实现的呢

[复制链接]
2118 |0
功能介绍

显示不同模式下的世界UI表现
世界空间模式效果展示:

屏幕空间模式效果展示:

头顶UI模式效果展示:


一分钟快速上手
资源准备:将一个人形对象拖到场景中,选择客户端
相关代码:

import TestUI_Generate from "./ui-generate/TestUI_generate";

@Core.Class
export default class TestScript extends Core.Script {
    private _worldUI: Gameplay.UIWidget = null;
    private _humanoid: Gameplay.NPC = null;

    protected onStart(): void {
        if (SystemUtil.isClient()) {
            this._humanoid = Core.GameObject.find("3DEB13D2") as Gameplay.NPC;
            InputUtil.onKeyDown(Type.Keys.P, async () => {
                if (!this._worldUI) {
                    this._worldUI = await Core.GameObject.asyncSpawn({ guid: "UIWidget" }) as Gameplay.UIWidget;
                    let ui = UI.UIManager.instance.create(TestUI_Generate);
                    this._worldUI.setTargetUIWidget(ui.uiWidgetBase);
                    this._worldUI.drawSize = ui.uiWidgetBase.size;
                }
                //世界空间模式
                // this.initWorldUI();
                //屏幕空间模式
                // this.initScreenUI();
                //头顶UI模式
                this.initHeadUI();
            })
        }
    }

    /**世界空间 */
    protected initWorldUI() {
        this._worldUI.widgetSpace = Gameplay.WidgetSpaceMode.World;
        this._worldUI.worldLocation = this._humanoid.worldLocation.clone().add(new Vector(0, 0, 350));
    }

    /**屏幕空间 */
    protected initScreenUI() {
        this._worldUI.widgetSpace = Gameplay.WidgetSpaceMode.Screen;
        this._worldUI.worldLocation = this._humanoid.worldLocation.clone().add(new Vector(0, 0, 350));
    }

    /**头顶UI */
    protected initHeadUI() {
        this._worldUI.widgetSpace = Gameplay.WidgetSpaceMode.OverheadUI;
        this._worldUI.attachToGameObject(this._humanoid.getHeadUIWidget());
        this._worldUI.relativeLocation = Vector.zero;
    }

}


完整项目:
WorldUI.rar (49.19 KB, 下载次数: 111)
回复

使用道具 举报

热门版块
快速回复 返回顶部 返回列表