protected CursorPriorityPair GetHighestCursorPriorityPair()
    {
        CursorPriorityPair highest = null;

        for (int i = 0; i < priorityList.Count; i++)
        {
            highest = (highest == null || priorityList[i].priority >= highest.priority) ? priorityList[i] : highest;
        }

        return(highest);
    }
    public void RemoveCursor(int priority)
    {
        CursorPriorityPair pair = GetCursorPriorityPair(priority);

        if (pair == null)
        {
            return;
        }

        priorityList.Remove(pair);
        UpdateCursor();
    }
    public void RemoveCursor(string cursorName)
    {
        CursorPriorityPair pair = GetCursorPriorityPair(cursorName);

        if (pair == null)
        {
            return;
        }

        priorityList.Remove(pair);
        UpdateCursor();
    }
    // ---- protected methods ----

    protected void UpdateCursor()
    {
        // get most important cursor by priority
        CursorPriorityPair pair = GetHighestCursorPriorityPair();

        // set cursorIndex without triggering another UpdateCursor
        _selectedIndex = (pair != null) ? cursors.IndexOf(pair.cursor) : -1;

        if (selectedCursor != null)
        {
            reticle.texture    = selectedCursor.icon;
            reticle.pixelInset = selectedCursor.offsetRect;
        }
        else
        {
            reticle.texture    = emptyTexture;
            reticle.pixelInset = emptyOffsetRect;
        }
    }
    public void SetCursor(Cursor cursor, int priority)
    {
        CursorPriorityPair pair = GetCursorPriorityPair(priority);

        if (pair == null)
        {
            // add cursor with new priority
            pair = new CursorPriorityPair(cursor, priority);
            priorityList.Add(pair);
        }
        else
        {
            // overwrite cursor with same priority
            pair.cursor   = cursor;
            pair.priority = priority;
        }

        UpdateCursor();
    }
    public void SetCursor(Cursor cursor, int priority)
    {
        CursorPriorityPair pair = GetCursorPriorityPair(priority);

        if (pair == null) {
            // add cursor with new priority
            pair = new CursorPriorityPair(cursor, priority);
            priorityList.Add(pair);

        } else {
            // overwrite cursor with same priority
            pair.cursor = cursor;
            pair.priority = priority;
        }

        UpdateCursor();
    }