Skip to content

Game.Prefabs.ZoneBuiltDataKey

Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs

Type: struct

Base: System.ValueType, System.IEquatable

Summary:
A lightweight value-type composite key used to identify built-zone data by the associated Entity (zone) and an integer level. Implements IEquatable for value equality and provides a custom GetHashCode suitable for use in hash-based collections (Dictionary, HashSet). Designed to be used where a stable pairing of a zone Entity and a level is required (for example, indexing prefab/zone-related data).


Fields

  • public Unity.Entities.Entity m_Zone
    Represents the zone Entity this key refers to. Equality compares this Entity using Entity.Equals. Note: the correctness of this key depends on the stability and identity semantics of the Entity value (i.e., the Entity must uniquely and stably represent the zone while the key is used).

  • public int m_Level
    An integer level associated with the zone (for example, stage/tier/level of development). Included in equality and hash code calculations.

Properties

  • This struct exposes no properties. It uses public fields for its data (m_Zone and m_Level). If you prefer immutability, consider wrapping these fields with read-only properties or adding a constructor that sets readonly fields.

Constructors

  • public ZoneBuiltDataKey()
    No explicit constructors are defined in the source; the default parameterless struct constructor is available. You can create and initialize instances with object initializers, or add your own constructor if you need to enforce immutability or validation.

Example suggested constructor (not present in original source):

public ZoneBuiltDataKey(Entity zone, int level)
{
    m_Zone = zone;
    m_Level = level;
}

Methods

  • public bool Equals(ZoneBuiltDataKey other)
    Implements IEquatable. Returns true when both m_Zone and m_Level are equal to those of the other key. The method calls m_Zone.Equals(...) and m_Level.Equals(...).

Behavior summary: - Compares Entity identity first, then level. - Fast value equality suitable for collections and comparisons.

  • public override int GetHashCode()
    Computes a combined hash code from m_Zone and m_Level using a small prime-based mixing formula:
  • (17 * 31 + m_Zone.GetHashCode()) * 31 + m_Level.GetHashCode() This yields a reasonably distributed hash for small numbers of combinations. Because Entity.GetHashCode() is used, ensure Entity identity/hash semantics are stable while keys are stored in hash-based collections.

Notes: - The struct does not override Equals(object). If you use non-generic collections or call object.Equals, boxing will occur and the default ValueType.Equals will be used; consider adding an override for Equals(object) to avoid boxing and to ensure consistent behavior with Equals(ZoneBuiltDataKey).

Usage Example

using Unity.Entities;
using System.Collections.Generic;
using Game.Prefabs;

// create keys (example: zoneEntity obtained from ECS world)
Entity zoneEntity = /* obtain Entity */;
var key1 = new ZoneBuiltDataKey { m_Zone = zoneEntity, m_Level = 2 };
var key2 = new ZoneBuiltDataKey { m_Zone = zoneEntity, m_Level = 3 };

// use as dictionary key
var dict = new Dictionary<ZoneBuiltDataKey, SomeZoneData>();
dict[key1] = new SomeZoneData(...);

// compare keys
if (key1.Equals(key2))
{
    // ...
}

Additional recommendations: - If you intend to use ZoneBuiltDataKey as a persistent dictionary key, consider defining an explicit constructor and making fields readonly to avoid accidental mutation after insertion. - If your code uses non-generic APIs or relies on object.Equals, add an override for Equals(object) to maintain consistent equality behavior and avoid boxing.