Unity3D Hardware Cursor

A Unity library for changing system cursor image - the best way to make in-game cursor fast, responsive and framerate-independent. Library works with Windows and Mac OS X standalone builds, does not require Unity PRO. Can load cursor images from both files and memory (therefore, from assets too).
Note: intended to be used with Unity3d versions prior 4.0. Unity v.4.0 has native support for hardware cursor.

Installation

Copy HardwareCursor.dll into your project Assets folder.

Usage

Create cursor, initialize it from file and set as active:
using UnityEngine;
using HardwareCursor;
///...
var cursor = Cursor.Create();
var hotSpotX = 0f;
var hotSpotY = 0f;
cursor.InitFromFile("cursor.cur", hotSpotX, hotSpotY); // supports CUR, ICO, PNG
cursor.SetActive();
///...
Create cursor, initialize it from an asset and set as active:
using UnityEngine;
using HardwareCursor;
//...
var data = (Resources.Load("Textures/cursor") as Texture2D).EncodeToPNG();
var hotSpotX = 0f;
var hotSpotY = 0f;
cursor.InitFromMemory(data, hotSpotX, hotSpotY);
cursor.SetActive();
//...
Reset to default cursor:
cursor.ActivateDefaultCursor();
Note: to be able to use texture asset as a cursor image, the texture should be imported with Advanced texture type, should have Read/Write enabled set to true and its format set to ARGB 32 bit.

Known bugs

  • Does not work in editor, only in standalone builds.
  • Under Mac OS X the cursor is reset to default if game resolution is changed in runtime. You can work around this by re-activating the cursor.
© 2014-2017 Aleksey Fedotov