浏览代码

fix mouse position bug when canvas.renderMode == ScreenSpaceCamera (https://answers.unity.com/questions/849117/46-ui-image-follow-mouse-position.html)

/main
xingwei.zhu 5 年前
当前提交
ec189832
共有 1 个文件被更改,包括 47 次插入20 次删除
  1. 67
      Runtime/engine/UIWidgetsPanel.cs

67
Runtime/engine/UIWidgetsPanel.cs


void handleMouseMovement() {
var pos = this.getPointPosition(Input.mousePosition);
if (pos == null) {
return;
}
physicalX: pos.x,
physicalY: pos.y
physicalX: pos.Value.x,
physicalY: pos.Value.y
));
}

var pos = this.getPointPosition(Input.mousePosition);
if (pos == null) {
return;
}
pos.x,
pos.y,
pos.Value.x,
pos.Value.y,
InputUtils.getScrollButtonKey());
}
}

}
public void OnPointerDown(PointerEventData eventData) {
EventSystem.current.SetSelectedGameObject(this.gameObject, eventData);
if (position == null) {
return;
}
EventSystem.current.SetSelectedGameObject(this.gameObject, eventData);
physicalX: position.x,
physicalY: position.y
physicalX: position.Value.x,
physicalY: position.Value.y
if (position == null) {
return;
}
physicalX: position.x,
physicalY: position.y
physicalX: position.Value.x,
physicalY: position.Value.y
public Vector2 getPointPosition(PointerEventData eventData) {
public Vector2? getPointPosition(PointerEventData eventData) {
if (eventData.enterEventCamera == null && this.canvas.renderMode == RenderMode.ScreenSpaceCamera) {
return null;
}
Vector2 localPoint;
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, eventData.position,
eventData.enterEventCamera, out localPoint);

return localPoint;
}
public Vector2 getPointPosition(Vector2 position) {
public Vector2? getPointPosition(Vector2 position) {
Vector2 localPoint;
Camera eventCamera = null;

if (eventCamera == null && this.canvas.renderMode == RenderMode.ScreenSpaceCamera) {
return null;
}
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, position,
eventCamera, out localPoint);

public void OnDrag(PointerEventData eventData) {
var position = this.getPointPosition(eventData);
if (position == null) {
return;
}
physicalX: position.x,
physicalY: position.y
physicalX: position.Value.x,
physicalY: position.Value.y
var position = this.getPointPosition(eventData);
if (position == null) {
return;
}
var position = this.getPointPosition(eventData);
physicalX: position.x,
physicalY: position.y
physicalX: position.Value.x,
physicalY: position.Value.y
var position = this.getPointPosition(eventData);
if (position == null) {
return;
}
var position = this.getPointPosition(eventData);
physicalX: position.x,
physicalY: position.y
physicalX: position.Value.x,
physicalY: position.Value.y
));
}

正在加载...
取消
保存