@@ -240,24 +240,30 @@ void OnGUI() {
240
240
241
241
void handleMouseMovement ( ) {
242
242
var pos = this . getPointPosition ( Input . mousePosition ) ;
243
+ if ( pos == null ) {
244
+ return ;
245
+ }
243
246
this . _windowAdapter . postPointerEvent ( new PointerData (
244
247
timeStamp : Timer . timespanSinceStartup ,
245
248
change : PointerChange . hover ,
246
249
kind : PointerDeviceKind . mouse ,
247
250
device : this . getMouseButtonDown ( ) ,
248
- physicalX : pos . x ,
249
- physicalY : pos . y
251
+ physicalX : pos . Value . x ,
252
+ physicalY : pos . Value . y
250
253
) ) ;
251
254
}
252
255
253
256
void handleMouseScroll ( ) {
254
257
if ( Input . mouseScrollDelta . y != 0 || Input . mouseScrollDelta . x != 0 ) {
255
258
var scaleFactor = this . canvas . scaleFactor ;
256
259
var pos = this . getPointPosition ( Input . mousePosition ) ;
260
+ if ( pos == null ) {
261
+ return ;
262
+ }
257
263
this . _windowAdapter . onScroll ( Input . mouseScrollDelta . x * scaleFactor ,
258
264
Input . mouseScrollDelta . y * scaleFactor ,
259
- pos . x ,
260
- pos . y ,
265
+ pos . Value . x ,
266
+ pos . Value . y ,
261
267
InputUtils . getScrollButtonKey ( ) ) ;
262
268
}
263
269
}
@@ -276,31 +282,41 @@ int getMouseButtonDown() {
276
282
}
277
283
278
284
public void OnPointerDown ( PointerEventData eventData ) {
279
- EventSystem . current . SetSelectedGameObject ( this . gameObject , eventData ) ;
280
285
var position = this . getPointPosition ( eventData ) ;
286
+ if ( position == null ) {
287
+ return ;
288
+ }
289
+ EventSystem . current . SetSelectedGameObject ( this . gameObject , eventData ) ;
281
290
this . _windowAdapter . postPointerEvent ( new PointerData (
282
291
timeStamp : Timer . timespanSinceStartup ,
283
292
change : PointerChange . down ,
284
293
kind : InputUtils . getPointerDeviceKind ( eventData ) ,
285
294
device : InputUtils . getPointerDeviceKey ( eventData ) ,
286
- physicalX : position . x ,
287
- physicalY : position . y
295
+ physicalX : position . Value . x ,
296
+ physicalY : position . Value . y
288
297
) ) ;
289
298
}
290
299
291
300
public void OnPointerUp ( PointerEventData eventData ) {
292
301
var position = this . getPointPosition ( eventData ) ;
302
+ if ( position == null ) {
303
+ return ;
304
+ }
293
305
this . _windowAdapter . postPointerEvent ( new PointerData (
294
306
timeStamp : Timer . timespanSinceStartup ,
295
307
change : PointerChange . up ,
296
308
kind : InputUtils . getPointerDeviceKind ( eventData ) ,
297
309
device : InputUtils . getPointerDeviceKey ( eventData ) ,
298
- physicalX : position . x ,
299
- physicalY : position . y
310
+ physicalX : position . Value . x ,
311
+ physicalY : position . Value . y
300
312
) ) ;
301
313
}
302
314
303
- public Vector2 getPointPosition ( PointerEventData eventData ) {
315
+ public Vector2 ? getPointPosition ( PointerEventData eventData ) {
316
+ if ( eventData . enterEventCamera == null && this . canvas . renderMode == RenderMode . ScreenSpaceCamera ) {
317
+ return null ;
318
+ }
319
+
304
320
Vector2 localPoint ;
305
321
RectTransformUtility . ScreenPointToLocalPointInRectangle ( this . rectTransform , eventData . position ,
306
322
eventData . enterEventCamera , out localPoint ) ;
@@ -310,14 +326,17 @@ public Vector2 getPointPosition(PointerEventData eventData) {
310
326
return localPoint ;
311
327
}
312
328
313
- public Vector2 getPointPosition ( Vector2 position ) {
329
+ public Vector2 ? getPointPosition ( Vector2 position ) {
314
330
Vector2 localPoint ;
315
331
Camera eventCamera = null ;
316
332
317
333
if ( this . canvas . renderMode != RenderMode . ScreenSpaceCamera ) {
318
334
eventCamera = this . canvas . GetComponent < GraphicRaycaster > ( ) . eventCamera ;
319
335
}
320
336
337
+ if ( eventCamera == null && this . canvas . renderMode == RenderMode . ScreenSpaceCamera ) {
338
+ return null ;
339
+ }
321
340
322
341
RectTransformUtility . ScreenPointToLocalPointInRectangle ( this . rectTransform , position ,
323
342
eventCamera , out localPoint ) ;
@@ -329,44 +348,52 @@ public Vector2 getPointPosition(Vector2 position) {
329
348
330
349
public void OnDrag ( PointerEventData eventData ) {
331
350
var position = this . getPointPosition ( eventData ) ;
351
+ if ( position == null ) {
352
+ return ;
353
+ }
332
354
this . _windowAdapter . postPointerEvent ( new PointerData (
333
355
timeStamp : Timer . timespanSinceStartup ,
334
356
change : PointerChange . move ,
335
357
kind : InputUtils . getPointerDeviceKind ( eventData ) ,
336
358
device : InputUtils . getPointerDeviceKey ( eventData ) ,
337
- physicalX : position . x ,
338
- physicalY : position . y
359
+ physicalX : position . Value . x ,
360
+ physicalY : position . Value . y
339
361
) ) ;
340
362
}
341
363
342
364
public void OnPointerEnter ( PointerEventData eventData ) {
365
+ var position = this . getPointPosition ( eventData ) ;
366
+ if ( position == null ) {
367
+ return ;
368
+ }
343
369
var pointerKey = InputUtils . getPointerDeviceKey ( eventData ) ;
344
370
this . _enteredPointers . Add ( pointerKey ) ;
345
371
346
372
this . _lastMouseMove = eventData . position ;
347
- var position = this . getPointPosition ( eventData ) ;
348
373
this . _windowAdapter . postPointerEvent ( new PointerData (
349
374
timeStamp : Timer . timespanSinceStartup ,
350
375
change : PointerChange . hover ,
351
376
kind : InputUtils . getPointerDeviceKind ( eventData ) ,
352
377
device : pointerKey ,
353
- physicalX : position . x ,
354
- physicalY : position . y
378
+ physicalX : position . Value . x ,
379
+ physicalY : position . Value . y
355
380
) ) ;
356
381
}
357
382
358
383
public void OnPointerExit ( PointerEventData eventData ) {
384
+ var position = this . getPointPosition ( eventData ) ;
385
+ if ( position == null ) {
386
+ return ;
387
+ }
359
388
var pointerKey = InputUtils . getPointerDeviceKey ( eventData ) ;
360
389
this . _enteredPointers . Remove ( pointerKey ) ;
361
-
362
- var position = this . getPointPosition ( eventData ) ;
363
390
this . _windowAdapter . postPointerEvent ( new PointerData (
364
391
timeStamp : Timer . timespanSinceStartup ,
365
392
change : PointerChange . hover ,
366
393
kind : InputUtils . getPointerDeviceKind ( eventData ) ,
367
394
device : pointerKey ,
368
- physicalX : position . x ,
369
- physicalY : position . y
395
+ physicalX : position . Value . x ,
396
+ physicalY : position . Value . y
370
397
) ) ;
371
398
}
372
399
0 commit comments