Skip to content

Game.Areas.AreaSearchItem

Assembly: Assembly-CSharp (typical for Cities: Skylines 2 mod/game code)
Namespace: Game.Areas

Type: struct

Base: System.ValueType, implements System.IEquatable

Summary:
A lightweight value type used to identify/search an area by its Unity.Entities.Entity reference and a triangle index. Commonly used as a simple key or element in search collections (e.g., HashSet or Dictionary) when working with area geometry or spatial lookups in the game's area system. Note that the struct exposes public mutable fields rather than readonly fields.


Fields

  • public Unity.Entities.Entity m_Area
    Represents the area entity (Unity.Entities.Entity) associated with this search item. This is the primary identifier for which area the item belongs to.

  • public int m_Triangle
    The triangle index within the area's mesh or topology. Used to identify a specific triangle inside the area.

Properties

  • This struct defines no properties. It uses public fields directly.

Constructors

  • public AreaSearchItem(Unity.Entities.Entity area, int triangle)
    Initializes a new AreaSearchItem with the provided area Entity and triangle index.

Methods

  • public bool Equals(AreaSearchItem other)
    Implements IEquatable. Returns true if both m_Area and m_Triangle are equal. Implementation uses the single ampersand operator ('&') between the two boolean results, which forces evaluation of both sides (instead of the conditional '&&'). Functionally correct for equality checks, but slightly unusual stylistically.

  • public override int GetHashCode()
    Computes a combined hash code using a small seed/multiplicative scheme: (17 * 31 + m_Area.GetHashCode()) * 31 + m_Triangle.GetHashCode() Suitable for use when this struct is used as a key in hash-based collections.

Usage Example

using Unity.Entities;
using Game.Areas;

// Example instantiation (Entity normally obtained from an EntityManager/system)
Entity areaEntity = new Entity { Index = 1, Version = 1 }; // placeholder; typically created by ECS
var itemA = new AreaSearchItem(areaEntity, 5);
var itemB = new AreaSearchItem(areaEntity, 5);

// Equality check
bool equal = itemA.Equals(itemB); // true

// Hash code (for use in dictionaries/sets)
int hash = itemA.GetHashCode();

Additional notes: - The fields are public and mutable. If immutability is desired for safe usage as a dictionary key, consider making the fields readonly. - Because Equals uses a single '&' between the boolean results, both operands are evaluated even if the first is false. This is not incorrect for correctness, but using '&&' is more idiomatic for short-circuiting. - The struct is suitable for lightweight, copyable usage and is appropriate as a key type when paired with a consistent GetHashCode implementation.