Browse Source

Fixed Clickable sprites can be clicked through UI objects #377

master
chrisgregan 9 years ago
parent
commit
19dca7e555
  1. 12
      Assets/Fungus/Sprite/Scripts/Clickable2D.cs

12
Assets/Fungus/Sprite/Scripts/Clickable2D.cs

@ -1,5 +1,6 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.EventSystems;
using System.Collections; using System.Collections;
namespace Fungus namespace Fungus
@ -24,6 +25,11 @@ namespace Fungus
return; return;
} }
if (EventSystem.current.IsPointerOverGameObject())
{
return; // Ignore this mouse event, pointer is over UI
}
// TODO: Cache these object for faster lookup // TODO: Cache these object for faster lookup
ObjectClicked[] handlers = GameObject.FindObjectsOfType<ObjectClicked>(); ObjectClicked[] handlers = GameObject.FindObjectsOfType<ObjectClicked>();
foreach (ObjectClicked handler in handlers) foreach (ObjectClicked handler in handlers)
@ -34,11 +40,17 @@ namespace Fungus
protected virtual void OnMouseEnter() protected virtual void OnMouseEnter()
{ {
if (EventSystem.current.IsPointerOverGameObject())
{
return; // Ignore this mouse event, pointer is over UI
}
changeCursor(hoverCursor); changeCursor(hoverCursor);
} }
protected virtual void OnMouseExit() protected virtual void OnMouseExit()
{ {
// Always reset the mouse cursor to be on the safe side
SetMouseCursor.ResetMouseCursor(); SetMouseCursor.ResetMouseCursor();
} }

Loading…
Cancel
Save