diff --git a/Assets/Fungus/Sprite/Scripts/Clickable2D.cs b/Assets/Fungus/Sprite/Scripts/Clickable2D.cs index b7f68658..6b76ea14 100644 --- a/Assets/Fungus/Sprite/Scripts/Clickable2D.cs +++ b/Assets/Fungus/Sprite/Scripts/Clickable2D.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using UnityEngine.Events; using System.Collections; @@ -9,12 +9,15 @@ namespace Fungus * The Game Object must have a Collider2D component attached. * Use in conjunction with the ObjectClicked Flowchart event handler. */ - public class Clickable2D : MonoBehaviour + public class Clickable2D : MonoBehaviour { [Tooltip("Is object clicking enabled")] public bool clickEnabled = true; - void OnMouseDown() + [Tooltip("Mouse texture to use when hovering mouse over object")] + public Texture2D hoverCursor; + + protected virtual void OnMouseDown() { if (!clickEnabled) { @@ -28,6 +31,26 @@ namespace Fungus handler.OnObjectClicked(this); } } + + protected virtual void OnMouseEnter() + { + changeCursor(hoverCursor); + } + + protected virtual void OnMouseExit() + { + SetMouseCursor.ResetMouseCursor(); + } + + protected virtual void changeCursor(Texture2D cursorTexture) + { + if (!clickEnabled) + { + return; + } + + Cursor.SetCursor(cursorTexture, Vector2.zero, CursorMode.Auto); + } } -} \ No newline at end of file +} diff --git a/Assets/Fungus/Sprite/Scripts/Commands/SetMouseCursor.cs b/Assets/Fungus/Sprite/Scripts/Commands/SetMouseCursor.cs new file mode 100644 index 00000000..c7e99ce5 --- /dev/null +++ b/Assets/Fungus/Sprite/Scripts/Commands/SetMouseCursor.cs @@ -0,0 +1,53 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus +{ + [CommandInfo("Sprite", + "Set Mouse Cursor", + "Sets the mouse cursor sprite.")] + [AddComponentMenu("")] + public class SetMouseCursor : Command + { + [Tooltip("Texture to use for cursor. Will use default mouse cursor if no sprite is specified")] + public Texture2D cursorTexture; + + [Tooltip("The offset from the top left of the texture to use as the target point")] + public Vector2 hotSpot; + + // Cached static cursor settings + protected static Texture2D activeCursorTexture; + protected static Vector2 activeHotspot; + + public static void ResetMouseCursor() + { + // Change mouse cursor back to most recent settings + Cursor.SetCursor(activeCursorTexture, activeHotspot, CursorMode.Auto); + } + + public override void OnEnter() + { + Cursor.SetCursor(cursorTexture, hotSpot, CursorMode.Auto); + + activeCursorTexture = cursorTexture; + activeHotspot = hotSpot; + + Continue(); + } + + public override string GetSummary() + { + if (cursorTexture == null) + { + return "Error: No cursor sprite selected"; + } + + return cursorTexture.name; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Sprite/Scripts/Commands/SetMouseCursor.cs.meta b/Assets/Fungus/Sprite/Scripts/Commands/SetMouseCursor.cs.meta new file mode 100644 index 00000000..688a391f --- /dev/null +++ b/Assets/Fungus/Sprite/Scripts/Commands/SetMouseCursor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fb6f88496f37c444a91acef47749f723 +timeCreated: 1439302629 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Sprite/Scripts/Draggable2D.cs b/Assets/Fungus/Sprite/Scripts/Draggable2D.cs index c67c03d3..73c9697b 100644 --- a/Assets/Fungus/Sprite/Scripts/Draggable2D.cs +++ b/Assets/Fungus/Sprite/Scripts/Draggable2D.cs @@ -22,8 +22,10 @@ namespace Fungus [Tooltip("Time object takes to return to its starting position")] public float returnDuration = 1f; - protected Vector3 startingPosition; + [Tooltip("Mouse texture to use when hovering mouse over object")] + public Texture2D hoverCursor; + protected Vector3 startingPosition; protected bool updatePosition = false; protected Vector3 newPosition; @@ -142,6 +144,26 @@ namespace Fungus // TODO: Cache these object for faster lookup return GameObject.FindObjectsOfType(); } + + protected virtual void OnMouseEnter() + { + changeCursor(hoverCursor); + } + + protected virtual void OnMouseExit() + { + SetMouseCursor.ResetMouseCursor(); + } + + protected virtual void changeCursor(Texture2D cursorTexture) + { + if (!dragEnabled) + { + return; + } + + Cursor.SetCursor(cursorTexture, Vector2.zero, CursorMode.Auto); + } } } diff --git a/Assets/Fungus/Sprite/Sprites/HandPointer.png b/Assets/Fungus/Sprite/Sprites/HandPointer.png new file mode 100644 index 00000000..7a8eeae2 Binary files /dev/null and b/Assets/Fungus/Sprite/Sprites/HandPointer.png differ diff --git a/Assets/Fungus/Sprite/Sprites/HandPointer.png.meta b/Assets/Fungus/Sprite/Sprites/HandPointer.png.meta new file mode 100644 index 00000000..5be1d7cf --- /dev/null +++ b/Assets/Fungus/Sprite/Sprites/HandPointer.png.meta @@ -0,0 +1,55 @@ +fileFormatVersion: 2 +guid: 22eb050bacf8c401ca8503e24bff3570 +timeCreated: 1439303347 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 2 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + linearTexture: 0 + correctGamma: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: .25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 0 + cubemapConvolution: 0 + cubemapConvolutionSteps: 8 + cubemapConvolutionExponent: 1.5 + seamlessCubemap: 0 + textureFormat: -1 + maxTextureSize: 2048 + textureSettings: + filterMode: -1 + aniso: -1 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + rGBM: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: .5, y: .5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaIsTransparency: 1 + textureType: 8 + buildTargetSettings: [] + spriteSheet: + sprites: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Sprite/Sprites/MousePointer.png b/Assets/Fungus/Sprite/Sprites/MousePointer.png new file mode 100644 index 00000000..67f8052a Binary files /dev/null and b/Assets/Fungus/Sprite/Sprites/MousePointer.png differ diff --git a/Assets/Fungus/Sprite/Sprites/MousePointer.png.meta b/Assets/Fungus/Sprite/Sprites/MousePointer.png.meta new file mode 100644 index 00000000..e1ce5ce1 --- /dev/null +++ b/Assets/Fungus/Sprite/Sprites/MousePointer.png.meta @@ -0,0 +1,55 @@ +fileFormatVersion: 2 +guid: 502e0c9b755f34db0b90bf78857d8a1c +timeCreated: 1439303347 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 2 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + linearTexture: 0 + correctGamma: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: .25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 0 + cubemapConvolution: 0 + cubemapConvolutionSteps: 8 + cubemapConvolutionExponent: 1.5 + seamlessCubemap: 0 + textureFormat: -1 + maxTextureSize: 2048 + textureSettings: + filterMode: -1 + aniso: -1 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + rGBM: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: .5, y: .5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaIsTransparency: 1 + textureType: 8 + buildTargetSettings: [] + spriteSheet: + sprites: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/FungusExamples/DragAndDrop/DragAndDrop.unity b/Assets/FungusExamples/DragAndDrop/DragAndDrop.unity index 6a5e22ed..0103f437 100644 --- a/Assets/FungusExamples/DragAndDrop/DragAndDrop.unity +++ b/Assets/FungusExamples/DragAndDrop/DragAndDrop.unity @@ -130,6 +130,14 @@ Prefab: propertyPath: m_Name value: ClickableSprite1 objectReference: {fileID: 0} + - target: {fileID: 11400000, guid: 0e6bcf37a2876432fa58eff8888bf177, type: 2} + propertyPath: hoverOverCursorTexture + value: + objectReference: {fileID: 2800000, guid: 22eb050bacf8c401ca8503e24bff3570, type: 3} + - target: {fileID: 11400000, guid: 0e6bcf37a2876432fa58eff8888bf177, type: 2} + propertyPath: hoverCursor + value: + objectReference: {fileID: 2800000, guid: 22eb050bacf8c401ca8503e24bff3570, type: 3} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 0e6bcf37a2876432fa58eff8888bf177, type: 2} m_IsPrefabParent: 0 @@ -205,6 +213,7 @@ Camera: m_OcclusionCulling: 1 m_StereoConvergence: 10 m_StereoSeparation: .0219999999 + m_StereoMirrorMode: 0 --- !u!4 &268187672 Transform: m_ObjectHideFlags: 0 @@ -371,6 +380,14 @@ Prefab: propertyPath: m_Name value: ClickableSprite2 objectReference: {fileID: 0} + - target: {fileID: 11400000, guid: 0e6bcf37a2876432fa58eff8888bf177, type: 2} + propertyPath: hoverOverCursorTexture + value: + objectReference: {fileID: 2800000, guid: 22eb050bacf8c401ca8503e24bff3570, type: 3} + - target: {fileID: 11400000, guid: 0e6bcf37a2876432fa58eff8888bf177, type: 2} + propertyPath: hoverCursor + value: + objectReference: {fileID: 2800000, guid: 22eb050bacf8c401ca8503e24bff3570, type: 3} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 0e6bcf37a2876432fa58eff8888bf177, type: 2} m_IsPrefabParent: 0 @@ -435,6 +452,9 @@ GameObject: - 114: {fileID: 2019116694} - 114: {fileID: 2019116696} - 114: {fileID: 2019116695} + - 114: {fileID: 2019116698} + - 114: {fileID: 2019116697} + - 114: {fileID: 2019116699} m_Layer: 0 m_Name: Flowchart m_TagString: Untagged @@ -453,6 +473,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7a334fe2ffb574b3583ff3b18b4792d3, type: 3} m_Name: m_EditorClassIdentifier: + version: 1.0 scrollPos: {x: 226, y: 86} variablesScrollPos: {x: 0, y: 0} variablesExpanded: 1 @@ -461,11 +482,12 @@ MonoBehaviour: scrollViewRect: serializedVersion: 2 x: -591 - y: -392 + y: -452 width: 1887 - height: 1020 - selectedBlock: {fileID: 2019116694} - selectedCommands: [] + height: 1080 + selectedBlock: {fileID: 2019116698} + selectedCommands: + - {fileID: 2019116697} variables: [] description: 'This scene shows how to set up a drag-and-drop @@ -999,6 +1021,57 @@ MonoBehaviour: m_EditorClassIdentifier: parentBlock: {fileID: 2019116694} clickableObject: {fileID: 591590529} +--- !u!114 &2019116697 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2019116667} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fb6f88496f37c444a91acef47749f723, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 21 + errorMessage: + indentLevel: 0 + cursorTexture: {fileID: 2800000, guid: 502e0c9b755f34db0b90bf78857d8a1c, type: 3} + hotSpot: {x: 0, y: 0} +--- !u!114 &2019116698 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2019116667} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3d3d73aef2cfc4f51abf34ac00241f60, type: 3} + m_Name: + m_EditorClassIdentifier: + nodeRect: + serializedVersion: 2 + x: -143 + y: -50 + width: 120 + height: 40 + itemId: 20 + blockName: Start + description: + eventHandler: {fileID: 2019116699} + commandList: + - {fileID: 2019116697} +--- !u!114 &2019116699 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2019116667} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d2f6487d21a03404cb21b245f0242e79, type: 3} + m_Name: + m_EditorClassIdentifier: + parentBlock: {fileID: 2019116698} --- !u!1001 &2135880372 Prefab: m_ObjectHideFlags: 0 @@ -1038,6 +1111,10 @@ Prefab: propertyPath: m_RootOrder value: 1 objectReference: {fileID: 0} + - target: {fileID: 11400000, guid: 4d55f86cf3b124c8fb1158da26ffa96d, type: 2} + propertyPath: hoverCursor + value: + objectReference: {fileID: 2800000, guid: 22eb050bacf8c401ca8503e24bff3570, type: 3} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 4d55f86cf3b124c8fb1158da26ffa96d, type: 2} m_IsPrefabParent: 0