工具 / ScreenUtil
ScreenUtil Class
屏幕视口工具
Table of contents
Methods
checkWidgetAt(screenPosition: Vector2): boolean client |
|---|
| 获取屏幕坐标点处是否有UI,注意该方法性能过差,不要频繁调用 |
getGameObjectByScreenPosition(sceneX: number, sceneY: number, distance?: number, multiTrace?: boolean, onRay?: boolean): HitResult[] client |
| 获取视口相应位置的物体 |
getSightBeadPosition(): Vector client |
| 获取相机中心点所瞄准的世界位置 |
getWidgetAt(screenPosition: Vector2): Widget client |
| 获取屏幕坐标点处的UI,注意该方法性能过差,不要频繁调用 |
projectWorldPositionToWidgetPosition(player: Player, worldLocation: Vector, outScreenPosition: Vector2, isPlayerViewportRelative: boolean): boolean client |
| 获取投影世界到播放器的屏幕位置,然后将其转换为控件位置,考虑任何质量缩放。 |
Methods
checkWidgetAt
• Static checkWidgetAt(screenPosition): boolean client
获取屏幕坐标点处是否有UI,注意该方法性能过差,不要频繁调用
Parameters
screenPosition Vector2 | 屏幕坐标点 |
|---|
Returns
boolean | 是否有UI在这个位置 |
|---|
getGameObjectByScreenPosition
• Static getGameObjectByScreenPosition(sceneX, sceneY, distance?, multiTrace?, onRay?): HitResult[] client
获取视口相应位置的物体
Parameters
sceneX number | 视口坐标 X range:不超过屏幕坐标,关于屏幕坐标详情请看 class Vector2 type: 浮点数 |
|---|---|
sceneY number | 视口坐标 Y range:不超过屏幕坐标,关于屏幕坐标详情请看 class Vector2 type: 浮点数 |
distance? number | 检测距离 default:100000 range: 不做限制,type: 浮点数 |
multiTrace? boolean | 是否获取多个GameObject default:false |
onRay? boolean | 是否开启射线显示效果 default:false |
Returns
HitResult[] | 点击位置的物体 |
|---|
ts
@Component
export default class ScreenExample extends Script {
touch: TouchInput;
async onStart() {
this.touch = new TouchInput();
this.touch.onTouch.add((index, location, type) => {
console.log("ontouch", index, location, type);
if (type == TouchInputType.TouchBegin) {
console.log("触摸的GameObject名字是:" + this.onTouchBegin(index, location).name);
}
})
}
// 开始触摸屏幕,从此位置
private onTouchBegin(index: number, location: Vector2): mw.GameObject{
return ScreenUtil.getGameObjectByScreenPosition(location.x, location.y)[0].gameObject;
}
}@Component
export default class ScreenExample extends Script {
touch: TouchInput;
async onStart() {
this.touch = new TouchInput();
this.touch.onTouch.add((index, location, type) => {
console.log("ontouch", index, location, type);
if (type == TouchInputType.TouchBegin) {
console.log("触摸的GameObject名字是:" + this.onTouchBegin(index, location).name);
}
})
}
// 开始触摸屏幕,从此位置
private onTouchBegin(index: number, location: Vector2): mw.GameObject{
return ScreenUtil.getGameObjectByScreenPosition(location.x, location.y)[0].gameObject;
}
}getSightBeadPosition
• Static getSightBeadPosition(): Vector client
获取相机中心点所瞄准的世界位置
Returns
Vector | 目标点世界位置 |
|---|
ts
@Component
export default class ScreenExample extends Script {
touch: TouchInput;
async onStart() {
this.touch = new TouchInput();
this.touch.onTouchMove.add((index, location, type) => {
console.log("ontouch", index, location, type);
if (type == TouchInputType.TouchMove) {
console.log("视口中心点所对应的世界位置是:" + getSightBeadPosition());
}
})
}@Component
export default class ScreenExample extends Script {
touch: TouchInput;
async onStart() {
this.touch = new TouchInput();
this.touch.onTouchMove.add((index, location, type) => {
console.log("ontouch", index, location, type);
if (type == TouchInputType.TouchMove) {
console.log("视口中心点所对应的世界位置是:" + getSightBeadPosition());
}
})
}getWidgetAt
• Static getWidgetAt(screenPosition): Widget client
获取屏幕坐标点处的UI,注意该方法性能过差,不要频繁调用
Parameters
screenPosition Vector2 | 屏幕坐标点 |
|---|
Returns
Widget | 返回这个点的UI,如果没有返回空 |
|---|
projectWorldPositionToWidgetPosition
• Static projectWorldPositionToWidgetPosition(player, worldLocation, outScreenPosition, isPlayerViewportRelative): boolean client
获取投影世界到播放器的屏幕位置,然后将其转换为控件位置,考虑任何质量缩放。
Parameters
player Player | 玩家在游戏世界中的位置投射到屏幕上的控制器 |
|---|---|
worldLocation Vector | 要投射的世界位置 |
outScreenPosition Vector2 | 在视口的位置 |
isPlayerViewportRelative boolean | 是否与玩家视口子区域相关(当在分屏中使用玩家附加的小部件或当宽度比受限时有用)如果位置投射到屏幕上,返回true |
Returns
boolean | boolean |
|---|