diff --git a/Assets/Fungus/Sprite/Scripts/Clickable2D.cs b/Assets/Fungus/Sprite/Scripts/Clickable2D.cs index c5b64126..a532be32 100644 --- a/Assets/Fungus/Sprite/Scripts/Clickable2D.cs +++ b/Assets/Fungus/Sprite/Scripts/Clickable2D.cs @@ -15,7 +15,6 @@ namespace Fungus { [Tooltip("Is object clicking enabled")] [SerializeField] protected bool clickEnabled = true; - public bool ClickEnabled { set { clickEnabled = value; } } [Tooltip("Mouse texture to use when hovering mouse over object")] [SerializeField] protected Texture2D hoverCursor; @@ -23,7 +22,44 @@ namespace Fungus [Tooltip("Use the UI Event System to check for clicks. Clicks that hit an overlapping UI object will be ignored. Camera must have a PhysicsRaycaster component, or a Physics2DRaycaster for 2D colliders.")] [SerializeField] protected bool useEventSystem; + protected virtual void ChangeCursor(Texture2D cursorTexture) + { + if (!clickEnabled) + { + return; + } + + Cursor.SetCursor(cursorTexture, Vector2.zero, CursorMode.Auto); + } + + protected virtual void DoPointerClick() + { + if (!clickEnabled) + { + return; + } + + // TODO: Cache these objects for faster lookup + ObjectClicked[] handlers = GameObject.FindObjectsOfType(); + foreach (ObjectClicked handler in handlers) + { + handler.OnObjectClicked(this); + } + } + + protected virtual void DoPointerEnter() + { + ChangeCursor(hoverCursor); + } + + protected virtual void DoPointerExit() + { + // Always reset the mouse cursor to be on the safe side + SetMouseCursor.ResetMouseCursor(); + } + #region Legacy OnMouseX methods + protected virtual void OnMouseDown() { if (!useEventSystem) @@ -47,9 +83,17 @@ namespace Fungus DoPointerExit(); } } + + #endregion + + #region IClickable2D implementation + + public bool ClickEnabled { set { clickEnabled = value; } } + #endregion - #region IPointerXHandler implementations + #region IPointerClickHandler implementation + public void OnPointerClick(PointerEventData eventData) { if (useEventSystem) @@ -58,6 +102,10 @@ namespace Fungus } } + #endregion + + #region IPointerEnterHandler implementation + public void OnPointerEnter(PointerEventData eventData) { if (useEventSystem) @@ -66,6 +114,10 @@ namespace Fungus } } + #endregion + + #region IPointerExitHandler implementation + public void OnPointerExit(PointerEventData eventData) { if (useEventSystem) @@ -74,41 +126,6 @@ namespace Fungus } } - protected virtual void DoPointerClick() - { - if (!clickEnabled) - { - return; - } - - // TODO: Cache these objects for faster lookup - ObjectClicked[] handlers = GameObject.FindObjectsOfType(); - foreach (ObjectClicked handler in handlers) - { - handler.OnObjectClicked(this); - } - } - - protected virtual void DoPointerEnter() - { - ChangeCursor(hoverCursor); - } - - protected virtual void DoPointerExit() - { - // Always reset the mouse cursor to be on the safe side - SetMouseCursor.ResetMouseCursor(); - } #endregion - - protected virtual void ChangeCursor(Texture2D cursorTexture) - { - if (!clickEnabled) - { - return; - } - - Cursor.SetCursor(cursorTexture, Vector2.zero, CursorMode.Auto); - } } } diff --git a/Assets/Fungus/Sprite/Scripts/IClickable2D.cs b/Assets/Fungus/Sprite/Scripts/IClickable2D.cs new file mode 100644 index 00000000..8d0e23df --- /dev/null +++ b/Assets/Fungus/Sprite/Scripts/IClickable2D.cs @@ -0,0 +1,15 @@ +namespace Fungus +{ + /// + /// Detects mouse clicks and touches on a Game Object, and sends an event to all Flowchart event handlers in the scene. + /// The Game Object must have a Collider or Collider2D component attached. + /// Use in conjunction with the ObjectClicked Flowchart event handler. + /// + public interface IClickable2D + { + /// + /// Is object clicking enabled. + /// + bool ClickEnabled { set; } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Sprite/Scripts/IClickable2D.cs.meta b/Assets/Fungus/Sprite/Scripts/IClickable2D.cs.meta new file mode 100644 index 00000000..b67ab2e2 --- /dev/null +++ b/Assets/Fungus/Sprite/Scripts/IClickable2D.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 477f75d30919449dfa922f74038ceaa4 +timeCreated: 1473690975 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: