Skip to content

Game.Tools.OwnerDefinition

Assembly: Assembly-CSharp
Namespace: Game.Tools

Type: struct OwnerDefinition
Base: System.ValueType
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, System.IEquatable

Summary:
Represents a lightweight ECS component that holds a reference to a prefab Entity plus a local transform (position and rotation). Typically used to define ownership/spawn information for systems that need to instantiate or reference an "owner" entity in Cities: Skylines 2 mod code. Equality is implemented to allow comparison in queries and hashing.


Fields

  • public Entity m_Prefab
    Holds the prefab Entity reference (the entity to be considered the "owner" or the entity to instantiate).

  • public float3 m_Position
    Local position for the owner relative to some context. Uses Unity.Mathematics.float3.

  • public quaternion m_Rotation
    Local rotation for the owner. Uses Unity.Mathematics.quaternion.

Properties

  • This type declares no properties.

Constructors

  • public OwnerDefinition()
    Structs have a default parameterless constructor provided by C#. No explicit constructor overloads are defined in the source. Initialize fields using an object initializer when creating instances.

Methods

  • public bool Equals(OwnerDefinition other)
    Implements IEquatable. Returns true when m_Prefab, m_Position and m_Rotation are all equal. The implementation first checks m_Prefab and m_Position equality and then returns the comparison of m_Rotation.

  • public override int GetHashCode()
    Combines the hash codes of m_Prefab, m_Position and m_Rotation into a single hash using a simple multiplier mixing pattern: ((17 * 31 + m_Prefab.GetHashCode()) * 31 + m_Position.GetHashCode()) * 31 + m_Rotation.GetHashCode()

Usage Example

using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using Game.Tools;

// Create/initialize an OwnerDefinition
var ownerDef = new OwnerDefinition
{
    m_Prefab = prefabEntity,
    m_Position = new float3(0f, 0f, 0f),
    m_Rotation = quaternion.identity
};

// Add it as a component to an existing entity via EntityManager
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
em.AddComponentData(targetEntity, ownerDef);

// Compare two OwnerDefinition instances
var other = new OwnerDefinition { m_Prefab = prefabEntity, m_Position = new float3(0f), m_Rotation = quaternion.identity };
bool equal = ownerDef.Equals(other); // true if all fields match