Game.Prefabs.FloatingObject
Assembly:
Game (assembly containing game prefab components)
Namespace:
Game.Prefabs
Type:
Class
Base:
ComponentBase
Summary:
Component used by placeable prefabs to mark them as "floating" objects (e.g., buoys, floating props). Controls placement offset, whether the object can be placed on dry land, whether it is fixed to the bottom, and whether sway/transform interpolation components should be added to the entity archetype. The class updates PlaceableObjectData on initialization and conditionally requests Swaying and InterpolatedTransform components for static prefabs that are not fixed to bottom. This component is exposed in the component menu for StaticObjectPrefab and MarkerObjectPrefab.
Fields
-
public float m_FloatingOffset
Distance (vertical) offset applied to placement. In Initialize this value is assigned to PlaceableObjectData.m_PlacementOffset.y so the prefab appears above/below default placement height. -
public bool m_FixedToBottom
When true, the prefab is considered fixed to the seabed/bottom and will NOT receive Swaying/InterpolatedTransform components. When false and the base prefab is a StaticObjectPrefab, Swaying and InterpolatedTransform are added to the archetype (allowing runtime swaying/interpolation). -
public bool m_AllowDryland
When true, the prefab allows placement on ground (dry land) as well as water. Affects PlacementFlags set on PlaceableObjectData during Initialize.
Properties
- (no public properties declared)
This class uses public fields for configuration and overrides methods from ComponentBase to modify ECS components. The important ECS data is stored/modified in PlaceableObjectData on the entity.
Constructors
public FloatingObject()
Default parameterless constructor inherited from ComponentBase (no explicit constructor defined in source). Instances are typically created via Unity's prefab/component system.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds required component types for the prefab. Implementation adds ComponentType.ReadWrite() so each prefab entity will include placeable placement data. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Conditionally adds archetype components: if m_FixedToBottom is false and base.prefab is a StaticObjectPrefab, this adds ComponentType.ReadWrite() and ComponentType.ReadWrite () to the requested archetype. This ensures entities for non-fixed static floating prefabs can sway and have interpolated transforms. -
public override void Initialize(EntityManager entityManager, Entity entity)
Updates the entity's PlaceableObjectData: - Sets placement offset Y to m_FloatingOffset.
- If m_AllowDryland is true, sets PlacementFlags.OnGround and PlacementFlags.Floating.
- If m_AllowDryland is false, clears PlacementFlags.OnGround and sets PlacementFlags.Floating.
- If m_FixedToBottom is false, sets PlacementFlags.Swaying.
- Writes the modified PlaceableObjectData back to the entity via entityManager.SetComponentData.
Notes: Bitwise flag operations are used to set/clear PlacementFlags (OnGround, Floating, Swaying).
Usage Example
// Configure a FloatingObject on a prefab (typically via inspector).
// Example: programmatically create/configure before prefab registration.
var floating = new FloatingObject {
m_FloatingOffset = 1.2f,
m_AllowDryland = false,
m_FixedToBottom = false
};
// When the prefab spawns, Initialize will set PlaceableObjectData.m_PlacementOffset.y = 1.2f,
// ensure the Floating flag is set, and because m_FixedToBottom == false will request Swaying
// and InterpolatedTransform on the prefab archetype so the instance can sway at runtime.