CursorManager
Coding Style wiki
CursorManager is the cursor manager of CursorSystem (a MonoBehaviour singleton) that manages the CursorState list configured in the Inspector and drives the frame animation of dynamic cursors in Update. Import the CursorManager Prefab via Samples and drop it into the boot scene, or let the Cursors facade create it automatically.
| Namespace | OxGKit.CursorSystem |
| Type | [DisallowMultipleComponent] public class CursorManager : MonoBehaviour |
| Source | CursorManager.cs |
using OxGKit.CursorSystem;
Reminder The instance methods of CursorManager correspond one-to-one with the Cursors static facade (the singleton accessor is internal); route calls through Cursors — there is no need to hold an instance reference yourself.
Quick Start
using OxGKit.CursorSystem;
// The CursorManager is automatically found or created by the Cursors facade (singleton)
Cursors.InitInstance();
// After authoring Cursor States in the Inspector, switch by name
Cursors.SetCursorState("Loading");
General Rules
Singleton and Lifecycle
- The first access through Cursors automatically finds the
CursorManagerin the scene; if none exists, a[CursorManager]node is created automatically. - In
Awake, it parents itself under theOxGKitcontainer node and persists with DontDestroyOnLoad, and initializes the current state to the first element in the list. - In
Start, it resets the rendering (applies the default state); inUpdate, it drives the current state's dynamic cursor animation according to the Ignore Time Scale setting. OnEnableresets back to the default state;OnDisableremoves the cursor rendering (restores the system cursor).
Inspector Members
| Member | Description |
|---|---|
Ignore Time Scale | Whether the dynamic cursor animation ignores Time.timeScale (default true, driven by Time.unscaledDeltaTime). |
List Cursor States | The CursorState list; the first entry is the default state (a built-in Default state with frameRate 30). |
Methods Overview
| Method | Description |
|---|---|
| SetIgnoreScale | Sets whether dynamic cursor animation ignores Time.timeScale. |
| GetCurrentCursorLockState | Gets the current cursor lock mode. |
| SetCursorLockState | Sets the cursor lock mode. |
| IsCursorVisible | Checks whether the cursor is visible. |
| SetCursorVisible | Sets the cursor visibility. |
| SetScaleToAllCursors | Sets the scale for all cursor states and resets the rendering. |
| GetAllCursorStates | Gets all cursor states. |
| GetCursorState | Gets the cursor state with the given name. |
| GetCurrentCursorState | Gets the current cursor state. |
| SetCursorState | Switches the cursor state by name. |
| ResetCursorState | Resets back to the default state (first element). |
| ResetRender | Resets the rendering of the current cursor state. |
| RemoveCursorRender | Removes the cursor rendering (restores the system cursor). |
SetIgnoreScale
public void SetIgnoreScale(bool ignore)
Sets whether the dynamic cursor animation update ignores Time.timeScale (default true, driven by Time.unscaledDeltaTime).
GetCurrentCursorLockState
public CursorLockMode GetCurrentCursorLockState()
Gets the current cursor lock mode (i.e., Cursor.lockState).
SetCursorLockState
public void SetCursorLockState(CursorLockMode cursorLockMode)
Sets the cursor lock mode (None, Locked, Confined).
IsCursorVisible
public bool IsCursorVisible()
Checks whether the cursor is currently visible (i.e., Cursor.visible).
SetCursorVisible
public void SetCursorVisible(bool visible)
Sets the cursor visibility (i.e., Cursor.visible).
SetScaleToAllCursors
public void SetScaleToAllCursors(Vector2 scale)
Sets the scale for all cursor states and resets the rendering (scaling only takes effect with scalingEnabled + ForceSoftware).
GetAllCursorStates
public CursorState[] GetAllCursorStates()
Gets all configured cursor states (CursorState).
GetCursorState
public CursorState GetCursorState(string stateName)
Gets the cursor state with the given name; returns null if not found.
GetCurrentCursorState
public CursorState GetCurrentCursorState()
Gets the current cursor state.
SetCursorState
public bool SetCursorState(string stateName)
Switches the cursor state by name and resets the rendering; returns true on success, or false if the name is not found.
ResetCursorState
public void ResetCursorState()
Resets the cursor state to the default state (first element in the list) and resets the rendering.
ResetRender
public void ResetRender()
Resets the rendering of the current cursor state.
RemoveCursorRender
public void RemoveCursorRender()
Removes the cursor rendering (clears the current state and restores the system default cursor); to restore the custom cursor rendering, call ResetCursorState to re-initialize and reset the rendering.
CursorState
Cursor state (serializable, nested in CursorManager) that defines a single cursor state's render type, textures, hotspot, and animation parameters. Author it in the Inspector, or get it via Cursors.GetCursorState and adjust it at runtime (e.g., assign textures loaded from an AssetBundle).
| Type | [Serializable] public class CursorState |
| Source | CursorManager.cs |
Members
| Member | Description |
|---|---|
public string stateName | The state name (the key for runtime switching). |
public RenderType renderType | Static or dynamic cursor type, default Static. |
public CursorMode cursorMode | Cursor rendering mode (Auto / ForceSoftware), default Auto. |
public bool scalingEnabled | Scaling toggle, default false (scaling is only supported in ForceSoftware rendering mode). |
public Vector2 scale | Scale factor, default (1, 1) (requires scalingEnabled to take effect). |
public Vector2 hotspot | The cursor hotspot position, default (0, 0). |
public Texture2D staticCursorTexture | The static cursor texture. |
public List<Texture2D> dynamicCursorTextures | The dynamic cursor frame sequence. |
public bool isLoop | Whether the dynamic cursor loops, default false. |
public PlayMode playMode | The dynamic cursor play mode, default Normal. |
public int frameRate | The dynamic cursor frame rate (FPS), field default 0 (must be greater than 0 for the animation to play). |
RenderType
Defines the static or dynamic cursor type.
public enum RenderType
{
Static, // Static cursor
Dynamic // Dynamic cursor (frame animation)
}
PlayMode
Defines the animation play mode.
public enum PlayMode
{
Normal, // Forward
Reverse, // Backward
PingPong, // Forward -> backward
PingPongReverse // Backward -> forward
}
Attention With isLoop off, Normal / Reverse stop at the last frame; PingPong / PingPongReverse stop after one full round trip.
Methods Overview
| Method | Description |
|---|---|
| GetStateName | Gets the state name. |
| SetStateName | Sets the state name. |
| SetRenderType | Sets the render type (static/dynamic). |
| SetCursorMode | Sets the cursor rendering mode. |
| SetCursorScale | Sets the scale factor. |
| SetCursorOffset | Sets the cursor hotspot position. |
| SetStaticCursor | Sets the static cursor texture and applies the render immediately. |
| SetDynamicCursor | Replaces the dynamic cursor frame sequence and resets the animation. |
| SetFrameRate | Sets the frame rate. |
| SetLoop | Sets the loop toggle. |
| ResetRender | Resets the render according to the render type. |
| DriveUpdate | Drives the dynamic cursor animation update (called automatically by CursorManager). |
GetStateName
public string GetStateName()
Gets the state name.
SetStateName
public void SetStateName(string stateName)
Sets the state name.
SetRenderType
public void SetRenderType(RenderType renderType)
Sets the render type (RenderType static/dynamic).
SetCursorMode
public void SetCursorMode(CursorMode cursorMode)
Sets the cursor rendering mode (Auto / ForceSoftware).
SetCursorScale
public void SetCursorScale(Vector2 scale)
Sets the scale factor (requires scalingEnabled and ForceSoftware mode to take effect).
SetCursorOffset
public void SetCursorOffset(Vector2 offset)
Sets the cursor hotspot position.
SetStaticCursor
public void SetStaticCursor(Texture2D t2d = null)
Sets the static cursor texture and applies the render immediately; when t2d is null, the current staticCursorTexture is re-applied directly (in ForceSoftware mode with scaling enabled, the scaled texture is applied).
// Assign a texture at runtime (e.g., loaded from an AssetBundle)
var cursorState = Cursors.GetCursorState("Default");
cursorState.SetStaticCursor(tex);
SetDynamicCursor
public void SetDynamicCursor(Texture2D[] t2ds)
Replaces the dynamic cursor frame sequence and resets the animation parameters (plays from the beginning).
// Replace the frame sequence and adjust parameters at runtime
var cursorState = Cursors.GetCursorState("Loading");
cursorState.SetDynamicCursor(texture2ds);
cursorState.SetFrameRate(12);
cursorState.SetLoop(true);
cursorState.ResetRender();
Attention SetStaticCursor / SetDynamicCursor do not change renderType; to switch the state's render type, call SetRenderType and then ResetRender.
SetFrameRate
public void SetFrameRate(int frameRate)
Sets the dynamic cursor frame rate (FPS).
SetLoop
public void SetLoop(bool isLoop)
Sets the dynamic cursor loop toggle.
ResetRender
public void ResetRender()
Resets the render according to the render type (Static re-applies the static texture; Dynamic resets the animation parameters and replays).
DriveUpdate
public void DriveUpdate(float dt)
Drives the frame-animation update of the dynamic cursor; called automatically by CursorManager's Update (normally no need to call it yourself).