Skip to content

Game.Prefabs.Effects.RandomTransform

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

Type: class

Base: ComponentBase

Summary:
RandomTransform is a prefab component used by effect prefabs to supply randomized transform ranges to the ECS world. It exposes min/max rotation (in degrees) and min/max position (in world units) as float3 fields. During initialization it converts the rotation ranges from degrees to radians and writes a RandomTransformData component to the entity so runtime systems can sample random rotations/positions for spawned effects.


Fields

  • public Unity.Mathematics.float3 m_MinAngle
    Minimum Euler angles (degrees) used for the randomized rotation range. Default: (0, 0, 0). Values are converted to radians in Initialize before being written to RandomTransformData.

  • public Unity.Mathematics.float3 m_MaxAngle
    Maximum Euler angles (degrees) used for the randomized rotation range. Default: (0, 0, 360). Used together with m_MinAngle to form an angle range per axis; converted to radians for storage.

  • public Unity.Mathematics.float3 m_MinPosition
    Minimum position offset (world units) used for the randomized position range. Default: (0, 0, 0). Used to form the PositionRange.min in RandomTransformData.

  • public Unity.Mathematics.float3 m_MaxPosition
    Maximum position offset (world units) used for the randomized position range. Default: (0, 0, 0). Used to form the PositionRange.max in RandomTransformData.

Properties

  • None declared on this type. The component exposes configuration via public fields and pushes data into an ECS component (RandomTransformData) during Initialize.

Constructors

  • public RandomTransform()
    No explicit constructors are defined in the source; the default parameterless constructor is used. Initialization of runtime data is performed in the override of Initialize rather than a constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Registers the ECS components that this prefab will add to entities created from the prefab. This implementation adds RandomTransformData as a ReadWrite component so runtime systems can read/write the randomized transform data.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Left empty in this implementation. Typically used to add components that should be part of the entity archetype; RandomTransform instead adds data at Initialize.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab is instantiated into the entity world. Builds a RandomTransformData instance:

  • Converts m_MinAngle and m_MaxAngle from degrees to radians via math.radians(...)
  • Copies m_MinPosition / m_MaxPosition to the PositionRange fields
  • Writes the populated RandomTransformData to the entity with EntityManager.SetComponentData(entity, componentData) Notes: The method relies on the shape of RandomTransformData (expected to have m_AngleRange and m_PositionRange with min/max fields).

Usage Example

// Typical implementation is already present in the prefab component.
// This is effectively the Initialize override used to write runtime data.

public override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);

    // Build RandomTransformData using inspector-configured fields
    RandomTransformData componentData = default;
    componentData.m_AngleRange.min = math.radians(m_MinAngle);
    componentData.m_AngleRange.max = math.radians(m_MaxAngle);
    componentData.m_PositionRange.min = m_MinPosition;
    componentData.m_PositionRange.max = m_MaxPosition;

    // Write the component to the entity so runtime systems can sample random transforms
    entityManager.SetComponentData(entity, componentData);
}

Additional notes: - The component is attributed with [ComponentMenu("Effects/", typeof(EffectPrefab))], so it appears under Effects in the prefab component menu. - RandomTransform writes into RandomTransformData; review that struct to confirm field names/types and sampling behavior at runtime. - Angles are configured in degrees in the inspector but converted to radians for use with Unity.Mathematics and typical ECS math operations.