Browse Source

Added Set Mouse Cursor command and drag and drop support

master
chrisgregan 10 years ago
parent
commit
407d13f4ca
  1. 27
      Assets/Fungus/Sprite/Scripts/Clickable2D.cs
  2. 53
      Assets/Fungus/Sprite/Scripts/Commands/SetMouseCursor.cs
  3. 12
      Assets/Fungus/Sprite/Scripts/Commands/SetMouseCursor.cs.meta
  4. 24
      Assets/Fungus/Sprite/Scripts/Draggable2D.cs
  5. BIN
      Assets/Fungus/Sprite/Sprites/HandPointer.png
  6. 55
      Assets/Fungus/Sprite/Sprites/HandPointer.png.meta
  7. BIN
      Assets/Fungus/Sprite/Sprites/MousePointer.png
  8. 55
      Assets/Fungus/Sprite/Sprites/MousePointer.png.meta
  9. 85
      Assets/FungusExamples/DragAndDrop/DragAndDrop.unity

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

@ -1,4 +1,4 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using System.Collections; using System.Collections;
@ -14,7 +14,10 @@ namespace Fungus
[Tooltip("Is object clicking enabled")] [Tooltip("Is object clicking enabled")]
public bool clickEnabled = true; 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) if (!clickEnabled)
{ {
@ -28,6 +31,26 @@ namespace Fungus
handler.OnObjectClicked(this); 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);
}
} }
} }

53
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);
}
}
}

12
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:

24
Assets/Fungus/Sprite/Scripts/Draggable2D.cs

@ -22,8 +22,10 @@ namespace Fungus
[Tooltip("Time object takes to return to its starting position")] [Tooltip("Time object takes to return to its starting position")]
public float returnDuration = 1f; 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 bool updatePosition = false;
protected Vector3 newPosition; protected Vector3 newPosition;
@ -142,6 +144,26 @@ namespace Fungus
// TODO: Cache these object for faster lookup // TODO: Cache these object for faster lookup
return GameObject.FindObjectsOfType<T>(); return GameObject.FindObjectsOfType<T>();
} }
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);
}
} }
} }

BIN
Assets/Fungus/Sprite/Sprites/HandPointer.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

55
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:

BIN
Assets/Fungus/Sprite/Sprites/MousePointer.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

55
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:

85
Assets/FungusExamples/DragAndDrop/DragAndDrop.unity

@ -130,6 +130,14 @@ Prefab:
propertyPath: m_Name propertyPath: m_Name
value: ClickableSprite1 value: ClickableSprite1
objectReference: {fileID: 0} 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_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 0e6bcf37a2876432fa58eff8888bf177, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 0e6bcf37a2876432fa58eff8888bf177, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0
@ -205,6 +213,7 @@ Camera:
m_OcclusionCulling: 1 m_OcclusionCulling: 1
m_StereoConvergence: 10 m_StereoConvergence: 10
m_StereoSeparation: .0219999999 m_StereoSeparation: .0219999999
m_StereoMirrorMode: 0
--- !u!4 &268187672 --- !u!4 &268187672
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -371,6 +380,14 @@ Prefab:
propertyPath: m_Name propertyPath: m_Name
value: ClickableSprite2 value: ClickableSprite2
objectReference: {fileID: 0} 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_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 0e6bcf37a2876432fa58eff8888bf177, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 0e6bcf37a2876432fa58eff8888bf177, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0
@ -435,6 +452,9 @@ GameObject:
- 114: {fileID: 2019116694} - 114: {fileID: 2019116694}
- 114: {fileID: 2019116696} - 114: {fileID: 2019116696}
- 114: {fileID: 2019116695} - 114: {fileID: 2019116695}
- 114: {fileID: 2019116698}
- 114: {fileID: 2019116697}
- 114: {fileID: 2019116699}
m_Layer: 0 m_Layer: 0
m_Name: Flowchart m_Name: Flowchart
m_TagString: Untagged m_TagString: Untagged
@ -453,6 +473,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7a334fe2ffb574b3583ff3b18b4792d3, type: 3} m_Script: {fileID: 11500000, guid: 7a334fe2ffb574b3583ff3b18b4792d3, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
version: 1.0
scrollPos: {x: 226, y: 86} scrollPos: {x: 226, y: 86}
variablesScrollPos: {x: 0, y: 0} variablesScrollPos: {x: 0, y: 0}
variablesExpanded: 1 variablesExpanded: 1
@ -461,11 +482,12 @@ MonoBehaviour:
scrollViewRect: scrollViewRect:
serializedVersion: 2 serializedVersion: 2
x: -591 x: -591
y: -392 y: -452
width: 1887 width: 1887
height: 1020 height: 1080
selectedBlock: {fileID: 2019116694} selectedBlock: {fileID: 2019116698}
selectedCommands: [] selectedCommands:
- {fileID: 2019116697}
variables: [] variables: []
description: 'This scene shows how to set up a drag-and-drop description: 'This scene shows how to set up a drag-and-drop
@ -999,6 +1021,57 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
parentBlock: {fileID: 2019116694} parentBlock: {fileID: 2019116694}
clickableObject: {fileID: 591590529} 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 --- !u!1001 &2135880372
Prefab: Prefab:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1038,6 +1111,10 @@ Prefab:
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 1 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 11400000, guid: 4d55f86cf3b124c8fb1158da26ffa96d, type: 2}
propertyPath: hoverCursor
value:
objectReference: {fileID: 2800000, guid: 22eb050bacf8c401ca8503e24bff3570, type: 3}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 4d55f86cf3b124c8fb1158da26ffa96d, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 4d55f86cf3b124c8fb1158da26ffa96d, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0

Loading…
Cancel
Save