鼠标移动到物体上,利用label和box来显示提示框的区别

bool flag;

void Start()

{

flag=false;

}

void OnMouseEnter()

{

 flag=true;

}

void OnMouseExit()

{

flag=false;

}

void OnGUI()

{

if(flag)

{

Debug.Log(flag);//控制台显示flag的值;

GUI.label(new Rect(Inout.mousePositon.x,Screen.height-Input.mousePosition.y,200,200),"123");//按照这种方法,label可以正常显示;

GUI.Box(new Rect(Inout.mousePositon.x,Screen.height-Input.mousePosition.y,200,200),"123");//按照这种方法,box会一直闪现,原因是,程序不能准确判断鼠标是否在物体上,会出现T/F循环;

}

}

至于为什么label正常,而box一直闪现,不知是否与其边框有关,有待研究!个人见解,仅供参考!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现鼠标移入 entity 显示 label 信息提示框,移出时提示框消失,可以按照以下步骤进行: 1. 在 Vue 组件中引入 Cesium 库: ```javascript import Cesium from 'cesium/Cesium'; import 'cesium/Widgets/widgets.css'; ``` 2. 在 `mounted` 钩子函数中初始化 Cesium 以及创建 viewer: ```javascript mounted() { // 初始化 Cesium this.viewer = new Cesium.Viewer(this.$refs.cesiumContainer, { geocoder: false, homeButton: false, sceneModePicker: false, navigationHelpButton: false, animation: false, timeline: false }); } ``` 3. 在 `created` 钩子函数中创建要显示的 entity 和 label: ```javascript created() { // 创建要显示的 entity 和 label const position = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883); const entity = this.viewer.entities.add({ position: position, point: { pixelSize: 10, color: Cesium.Color.YELLOW } }); entity.label = { text: 'Hello, world!', show: false, showBackground: true, font: '14px monospace', style: Cesium.LabelStyle.FILL_AND_OUTLINE, outlineWidth: 2, verticalOrigin: Cesium.VerticalOrigin.BOTTOM, pixelOffset: new Cesium.Cartesian2(0, -9) }; } ``` 4. 在 `mounted` 钩子函数中添加鼠标移入和移出事件监听器: ```javascript mounted() { // ... // 添加鼠标移入和移出事件监听器 this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas); this.handler.setInputAction(event => { const pickedObject = this.viewer.scene.pick(event.endPosition); if (Cesium.defined(pickedObject) && pickedObject.id === entity) { entity.label.show = true; } }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); this.handler.setInputAction(event => { entity.label.show = false; }, Cesium.ScreenSpaceEventType.LEFT_CLICK); } ``` 这样,当鼠标移动到 entity 上时,label 信息提示框显示出来,移出时会消失。其中 `entity` 是在第三步中创建的,需要在第四步中使用。同时需要注意,要在组件销毁时清除事件监听器: ```javascript beforeDestroy() { // 清除事件监听器 this.handler.destroy(); this.viewer.destroy(); } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值