Create smooth, responsive context sensitive and animated cursors for your game.
The cursor system allows for easy code free context sensitive mouse cursors with support for animation.
The Cursor Animator component handles cursor animation, you should only have 1 of these active at any given time.
With an active Cursor System you can effect the state of the pointer by attaching Cursor State components to desired game objects or through code where you want or need a more bespoke solution.
Vector2representing the hot spot of the cursor e.g. the "tip" in the case of an arrow or wedge or a pointing finger. This is the finite location of the pointer.
CursorAnimationfield, this is a custom object which defines the settings of a simple texture animation.
Indicates rather or not the animation should loop endlessly or if it should animate to the end and hold the last frame
The set of textures to be animated through. Each frame should be its own texture and should have the same hot point as is defined on the Cursor State.
How many frames should be shown in 1 second. This value is used to determine the time per frame dictating the speed of the animation.
The cursor system works with a concept of "Cursor State", a state defines the icon to be used and the settings for its animation. At run time the state can be changed by triggers such as Mouse Over Cursor State behavior.
This default state is the state the system will return to when a component state is no longer true; for example when your pointer exits a Mouse Over Cursor State object it will return to the Default State you defined in the Cursor System.
Defaults to Auto, this indicates what type of cursor the game should use. Software Cursors can be more flexible in terms of what you can do with them, however they also tend to show a lag or latency and so Auto or Hardware is recommended.
Hold on mouse down is a feature of the Set State function of Cursor System. When a state is being applied, it can optionally be applied as "Hold On Mouse Down". This indicates to the system that if the left mouse button is pressed while the state is active that the state should persist for as long as the left mouse button is held.
Hold On Mouse Down is most often used with drag features such as drag and drop UI elements, drag to resize handles on windows and drag to move handles on windows. This insures that the cursor doesn't switch to default as the mouse is moved around and gives a more natural feel to the user.
SetState(CursorState state, bool setOnDown, bool holdOnDown);
This simple component can be added game objects and will cause the state of the cursor to change when the mouse enters the object. Optionally the state can be set to hold on mouse down, which can be useful of hand grab icons such as might be used for a drag to scroll UI element.
The button cursor state handles two (2) possible state changes, one for mouse enter similar to the Mousse Over Cursor State and one for On Click. This allows the component to show a 2nd cursor state while the mouse is held down such as highlighted pointer or tapping finger.
The change cursor default state will change the registered default state on enter and exit.
In most cases the desired effects can be handled code free, however the system is also designed with programmers in mind and has an easy to use interface. Most of the examples below will require a reference to a desired CursorState. Generally this reference would be set at development time much like you would any reference in Unity.
public class SomeBehaviour : MonoBehaviour
public CursorState cursorState;
You can then simply drag the desired state into the "Cursor State" field in the Unity Inspector.
//The same as calling SetActive(this, false, false);
cursorState.Active = true;
CursorSystem.SetActive(cursorState, setOnHold, holdOnDown);
var isActive = cursorState.Active;
var activeState = CursorSystem.CurrentState;
The handler should take a single parameter of type EventData<bool>
private void HandlerFunction(EventData<bool> data)
//The sender is the CursorState
var cursorState = data.sender as CursorState;
//The value indicates rather it was activated or deactivated
Debug.Log(cursorStae.name " was activated");
Debug.Log(cursorStae.name " was deactivated");