Game.Objects.Transform
Assembly: (unspecified — part of the game's/mod assembly)
Namespace: Game.Objects
Type: struct
Base: System.ValueType
Summary:
Represents a simple ECS component holding position and rotation for an object. Implements Unity.Entities.IComponentData for use with the DOTS/ECS world, IQueryTypeParameter to allow usage as a query parameter, IEquatable
Fields
-
public Unity.Mathematics.float3 m_Position
Holds the world-space position. Public field intended to be used directly (typical for ECS components). -
public Unity.Mathematics.quaternion m_Rotation
Holds the object rotation as a quaternion. Public field intended to be used directly.
Properties
- None.
This struct exposes its data via public fields rather than properties.
Constructors
public Transform(Unity.Mathematics.float3 position, Unity.Mathematics.quaternion rotation)
Creates a Transform with the given position and rotation. Simply assigns m_Position and m_Rotation.
Methods
-
public bool Equals(Transform other)
Implements IEquatable. Returns true when both m_Position and m_Rotation are equal (uses float3/quaternion Equals implementations). -
public override int GetHashCode()
Combines hash codes of position and rotation using a small custom formula: (17 * 31 + positionHash) * 31 + rotationHash. Useful if storing transforms in hash-based collections. -
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes m_Position then m_Rotation to the provided writer. Uses writer.Write to serialize the float3 and quaternion values in order. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads m_Position and m_Rotation from reader into the struct fields. After reading it performs sanity checks: - Ensures each component of m_Position lies within [-100000f, 100000f].
- Ensures rotation quaternion components are finite and not all zero. If any check fails, the transform is reset to defaults: m_Position = default(float3) and m_Rotation = quaternion.identity. These guards protect against corrupted or out-of-range saved data.
Usage Example
// Constructing a Transform and adding it to an entity (ECS usage)
using Unity.Mathematics;
using Unity.Entities;
using Game.Objects;
public void Example(EntityManager entityManager, Entity entity)
{
var t = new Transform(new float3(10f, 0f, 5f), quaternion.EulerXYZ(new float3(0f, math.radians(45f), 0f)));
entityManager.AddComponentData(entity, t);
}
// Serializing manually with a hypothetical writer
public void SaveTransform<TWriter>(TWriter writer, Transform t) where TWriter : Colossal.Serialization.Entities.IWriter
{
t.Serialize(writer);
}
// Deserializing with a hypothetical reader (will auto-sanitize invalid data)
public Transform LoadTransform<TReader>(TReader reader) where TReader : Colossal.Serialization.Entities.IReader
{
var t = default(Transform);
t.Deserialize(reader);
return t;
}
Notes: - Because this is an ECS component (IComponentData), instances are typically stored in component arrays managed by the EntityManager/World rather than used as standalone classes. - The Deserialize guards are important to prevent pathological positions/rotations from being loaded into the simulation (very large coordinates, NaNs/Infinities, or zero quaternions). Adjustments to these checks should be made with care.