Skip to content

Game.Prefabs.UnderwaterObject

Assembly:
Game

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase

Summary:
Component used by placeable prefabs to mark them as underwater objects and to control whether they are allowed on dry land as well. During prefab initialization this component adjusts the PlaceableObjectData placement flags (PlacementFlags) on the entity so the game's placement system knows the object is underwater and optionally also placeable on ground.


Fields

  • public bool m_AllowDryland
    Controls whether the prefab can be placed on dry land in addition to underwater. When true the PlaceableObjectData flags will include both PlacementFlags.OnGround and PlacementFlags.Underwater. When false the OnGround flag is removed and only PlacementFlags.Underwater is set.

Properties

  • (none)

Constructors

  • public UnderwaterObject()
    Default parameterless constructor (no special initialization in this class).

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds component types required by this prefab at runtime. This implementation adds a read/write PlaceableObjectData component so the entity will carry placement information.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    No archetype components added by this component. Left empty.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab is converted to an entity. Retrieves the PlaceableObjectData from the entity, then updates its m_Flags based on m_AllowDryland:

  • If m_AllowDryland is true: sets both PlacementFlags.OnGround and PlacementFlags.Underwater bits.
  • If m_AllowDryland is false: clears the PlacementFlags.OnGround bit and sets PlacementFlags.Underwater. Finally writes the modified PlaceableObjectData back to the entity via entityManager.SetComponentData.

Usage Example

// Example: enabling dryland placement for an underwater prefab component
UnderwaterObject uw = gameObject.GetComponent<UnderwaterObject>();
if (uw != null)
{
    // allow placement both on ground and underwater
    uw.m_AllowDryland = true;
}

// What Initialize does internally (simplified):
PlaceableObjectData data = entityManager.GetComponentData<PlaceableObjectData>(entity);
if (uw.m_AllowDryland)
{
    data.m_Flags |= PlacementFlags.OnGround | PlacementFlags.Underwater;
}
else
{
    data.m_Flags &= ~PlacementFlags.OnGround;
    data.m_Flags |= PlacementFlags.Underwater;
}
entityManager.SetComponentData(entity, data);