Skip to content

Game.UICursorCollection

Assembly: Assembly-CSharp (game)
Namespace: Game

Type: class

Base: UnityEngine.ScriptableObject

Summary:
A ScriptableObject that centralizes cursor textures and hotspots used by the game's UI. It defines a small set of common cursor types (pointer, text, move) and supports an array of named cursors for custom usages. The asset is creatable from the editor via the CreateAssetMenu attribute and is intended to be referenced by UI code to change the OS cursor using Unity's Cursor.SetCursor API.


Fields

  • public CursorInfo m_Pointer
    Stores the texture and hotspot used for the default pointer cursor. Use SetCursor(Cursors.Pointer) to apply.

  • public CursorInfo m_Text
    Stores the texture and hotspot used for the text / I-beam cursor. Use SetCursor(Cursors.Text) to apply.

  • public CursorInfo m_Move
    Stores the texture and hotspot used for the move cursor. Use SetCursor(Cursors.Move) to apply.

  • public NamedCursorInfo[] m_NamedCursors
    An array of custom named cursors that can be referenced by string name. Each element contains a name, texture and hotspot. Populated and used to build the dictionary on OnEnable.

  • private Dictionary<string, CursorInfo> m_NamedCursorsDict
    Runtime lookup dictionary mapping keys of the form "cursor://{name}" to CursorInfo (the NamedCursorInfo instances). Built/cleared during OnEnable and RefreshNamedCursorsDict for fast lookups when calling SetCursor(string).

  • public class CursorInfo (nested)
    Holds a Texture2D and a Vector2 hotspot and provides Apply() to set that cursor via Cursor.SetCursor.

  • public class NamedCursorInfo : CursorInfo (nested)
    Extends CursorInfo with a string m_Name to identify the named cursor in the inspector and dictionary.

Properties

  • None (no public C# properties defined on this type).
    {{ This ScriptableObject exposes cursor data via public fields and nested classes rather than properties. Access and mutation are intended to be done through the inspector or via the provided SetCursor methods. }}

Constructors

  • public UICursorCollection()
    Default parameterless constructor (ScriptableObjects are typically instantiated via CreateInstance() or created in the Editor using the Create Asset menu).

{{ Note: Because this is a ScriptableObject with CreateAssetMenu, typical workflow is to create the asset in the editor and assign it to components via the inspector rather than constructing it at runtime. }}

Methods

  • private void OnEnable()
    Initializes runtime state when the ScriptableObject is enabled/loaded. Ensures m_NamedCursors is not null, creates the m_NamedCursorsDict, and calls RefreshNamedCursorsDict to populate it.

{{ OnEnable is called by Unity when the asset is loaded. It guarantees the named-cursor array is non-null and prepares the lookup dictionary used by SetCursor(string). }}

  • public void SetCursor(Cursors cursor)
    Sets one of the built-in cursors based on the Cursors enum. Supported enum values handled in the switch: Pointer, Text, Move. Unrecognized values call ResetCursor().

{{ The Cursors enum is defined elsewhere in the codebase; when implementing UI logic, use this method to set one of the common cursor types. }}

  • public void SetCursor(string cursorName)
    Attempts to find a named cursor in the dictionary using the provided key. If found, applies that cursor; otherwise calls ResetCursor().

{{ The dictionary keys are constructed as "cursor://{m_Name}" — see RefreshNamedCursorsDict. When calling this method from code, pass the exact key (including the "cursor://" prefix) or construct the same prefix yourself. }}

  • public static void ResetCursor()
    Resets the OS cursor to the default by calling Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto).

{{ Use this to clear any custom cursor and revert to the system default. }}

  • private void RefreshNamedCursorsDict()
    Clears and rebuilds the m_NamedCursorsDict from the m_NamedCursors array. For each NamedCursorInfo it inserts an entry keyed as "cursor://{m_Name}" pointing to that NamedCursorInfo.

{{ This means the external string key to retrieve a named cursor must include the "cursor://" prefix. RefreshNamedCursorsDict is called on enable; if you modify m_NamedCursors at runtime you should call this method to keep the dictionary in sync. }}

  • public void CursorInfo.Apply() (nested CursorInfo method)
    Applies this cursor's Texture2D and hotspot to the OS cursor via Cursor.SetCursor(m_Texture, m_Hotspot, CursorMode.Auto).

{{ Apply() wraps the Unity API call and is used internally by SetCursor implementations. Ensure the texture is properly imported so Cursor.SetCursor works (see notes below). }}

Usage Example

// Example MonoBehaviour that uses a UICursorCollection assigned via the inspector.
public class CursorUser : MonoBehaviour
{
    public UICursorCollection cursors;

    void OnPointerEnter()
    {
        // Use built-in enum cursor:
        cursors.SetCursor(Cursors.Pointer);
    }

    void OnTextAreaFocus()
    {
        cursors.SetCursor(Cursors.Text);
    }

    void OnCustomMode()
    {
        // Use named cursor. Note the prefix used by RefreshNamedCursorsDict:
        cursors.SetCursor("cursor://MyCustomCursorName");
    }

    void OnPointerExit()
    {
        UICursorCollection.ResetCursor();
    }
}

Additional notes for modders: - Create the asset in the Unity editor via: Assets -> Create -> Colossal -> UI -> UICursorCollection (per the CreateAssetMenu attribute). Populate m_Pointer, m_Text, m_Move and the m_NamedCursors array in the inspector. - For Texture2D used as cursors, ensure proper import settings (uncompressed or readable as needed, and appropriate alpha). In many Unity versions you can set Texture Type to Cursor or set the texture format so that Cursor.SetCursor displays correctly. - The named-cursor dictionary keys include the "cursor://" prefix. Either store and pass that full key, or mirror the same prefix convention when composing keys in code. - Cursor.SetCursor is platform dependent: cursor appearance and size/scale may vary across OS and DPI settings. Test on target platforms.