Skip to content

Game.UI.Editor.AssetItem

Assembly:
Game

Namespace: Game.UI.Editor

Type:
class

Base:
IItemPicker.Item, IComparable

Summary:
Represents an asset entry used by the item picker UI. Holds a content identifier (GUID) and a filename/display name and provides a comparison implementation that orders items by a "favorite" flag (inherited from the base item) and then by filename. Commonly used when building and sorting lists of assets in the editor UI.


Fields

  • private Colossal.Hash128 <guid>k__BackingField
    Compiler-generated backing field for the guid auto-property. Stores the 128-bit hash identifier for the asset (Colossal's Hash128 type).

  • private string <fileName>k__BackingField
    Compiler-generated backing field for the fileName auto-property. Stores the asset's filename or display name.

  • protected bool favorite (inherited)
    The inherited favorite flag from IItemPicker.Item used to prioritize items in sorting. The class's CompareTo uses this field from the base type to place favorites before non-favorites.

Properties

  • public Colossal.Hash128 guid { get; set; }
    Unique identifier for the asset in the content system. Use this to reference the underlying asset resource.

  • public string fileName { get; set; }
    Filename or display name shown in the UI for the asset.

Constructors

  • public AssetItem()
    Default parameterless constructor (compiler-provided). Initializes auto-properties to their default values and calls the base constructor from IItemPicker.Item.

Methods

  • public int CompareTo(AssetItem other)
    Compares this AssetItem with another for ordering. Behavior:
  • If both items have the same favorite value (inherited from the base), compares their fileName using string.CompareOrdinal (ordinal, case-sensitive).
  • If the favorite values differ, returns the negated result of favorite.CompareTo(other.favorite) so that items marked as favorites appear before non-favorites when sorted ascending.

Usage Example

using System.Collections.Generic;
using Colossal;

var a = new Game.UI.Editor.AssetItem { guid = new Hash128(1,2,3,4), fileName = "SmallHouse", /* favorite inherited */ };
var b = new Game.UI.Editor.AssetItem { guid = new Hash128(5,6,7,8), fileName = "Apartment", /* favorite inherited */ };

var list = new List<Game.UI.Editor.AssetItem> { a, b };
// set favorite flags via the base type if accessible:
// (Assuming IItemPicker.Item exposes a way to set favorite; otherwise the base handles it.)
list.Sort(); // Uses CompareTo: favorites first, then filename (ordinal)

foreach (var item in list)
{
    // Use item.guid to load the asset and item.fileName for display
}