Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 7f0cd4a

Browse files
committed
fix event camera problem
1 parent ce61c6a commit 7f0cd4a

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

Runtime/engine/UIWidgetsPanel.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,31 +312,29 @@ public void OnPointerUp(PointerEventData eventData) {
312312
));
313313
}
314314

315-
public Vector2? getPointPosition(PointerEventData eventData) {
316-
if (eventData.enterEventCamera == null && this.canvas.renderMode == RenderMode.ScreenSpaceCamera) {
317-
return null;
315+
Camera getActiveCamera() {
316+
//refer to: https://zhuanlan.zhihu.com/p/37127981
317+
Camera eventCamera = null;
318+
if (this.canvas.renderMode != RenderMode.ScreenSpaceOverlay) {
319+
eventCamera = this.canvas.GetComponent<GraphicRaycaster>().eventCamera;
318320
}
319-
321+
return eventCamera;
322+
}
323+
324+
Vector2? getPointPosition(PointerEventData eventData) {
325+
Camera camera = this.getActiveCamera();
320326
Vector2 localPoint;
321327
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, eventData.position,
322-
eventData.enterEventCamera, out localPoint);
328+
camera, out localPoint);
323329
var scaleFactor = this.canvas.scaleFactor;
324330
localPoint.x = (localPoint.x - this.rectTransform.rect.min.x) * scaleFactor;
325331
localPoint.y = (this.rectTransform.rect.max.y - localPoint.y) * scaleFactor;
326332
return localPoint;
327333
}
328334

329-
public Vector2? getPointPosition(Vector2 position) {
335+
Vector2? getPointPosition(Vector2 position) {
330336
Vector2 localPoint;
331-
Camera eventCamera = null;
332-
333-
if (this.canvas.renderMode != RenderMode.ScreenSpaceCamera) {
334-
eventCamera = this.canvas.GetComponent<GraphicRaycaster>().eventCamera;
335-
}
336-
337-
if (eventCamera == null && this.canvas.renderMode == RenderMode.ScreenSpaceCamera) {
338-
return null;
339-
}
337+
Camera eventCamera = this.getActiveCamera();
340338

341339
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, position,
342340
eventCamera, out localPoint);

0 commit comments

Comments
 (0)