Game.Prefabs.ShorelineObject
Assembly: Assembly-CSharp (Game)
Namespace: Game.Prefabs
Type: public class ShorelineObject
Base: ComponentBase
Summary:
ShorelineObject is a prefab component used to configure placement behavior for objects that must align with shorelines. It adjusts the placement Z offset and sets placement flags (Shoreline and optionally OnGround) on the PlaceableObjectData component when the prefab entity is initialized. The class is exposed in the component menu for StaticObjectPrefab and MarkerObjectPrefab types via the ComponentMenu attribute.
Fields
-
public float m_ShorelineOffset
Specifies the Z offset applied to the object's placement offset (PlaceableObjectData.m_PlacementOffset.z). Use this to move the placed object in or out relative to the shoreline surface. -
public bool m_AllowDryland
When true, the object is allowed to be placed on dry land as well as shoreline. Controls whether the PlacementFlags.OnGround flag is added. When false, the OnGround flag is cleared and only the Shoreline flag is enforced.
Properties
- (none)
This component does not define any public properties; it exposes two public fields for configuration.
Constructors
public ShorelineObject()
Default constructor (no custom initialization). Instances are typically created/managed by the prefab/component system rather than being instantiated manually.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds required component types for the prefab. Adds ReadWrite access to PlaceableObjectData to ensure the entity has and can be modified for placement-related data:-
Adds ComponentType.ReadWrite
() -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
No additional archetype components are added by this component (method intentionally empty). -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab entity is initialized. Implementation: - Retrieves the PlaceableObjectData component for the entity.
- Sets componentData.m_PlacementOffset.z = m_ShorelineOffset.
- If m_AllowDryland is true, sets PlacementFlags.OnGround | PlacementFlags.Shoreline on componentData.m_Flags.
- If m_AllowDryland is false, ensures PlacementFlags.OnGround is cleared and PlacementFlags.Shoreline is set.
- Writes the modified PlaceableObjectData back to the entity using entityManager.SetComponentData. This ensures the entity will be placed with the correct vertical offset and placement rules for shoreline behavior.
Usage Example
// Example showing the effect after the prefab's Initialize runs.
//
// Assume 'entity' is the prefab entity and ShorelineObject is configured in the prefab asset:
// m_ShorelineOffset = 0.5f, m_AllowDryland = false
PlaceableObjectData data = entityManager.GetComponentData<PlaceableObjectData>(entity);
// After initialization:
Debug.Assert(Math.Abs(data.m_PlacementOffset.z - 0.5f) < 0.0001f);
Debug.Assert((data.m_Flags & PlacementFlags.Shoreline) != 0);
Debug.Assert((data.m_Flags & PlacementFlags.OnGround) == 0);
Additional notes: - The class is decorated with [ComponentMenu("Objects/", typeof(StaticObjectPrefab), typeof(MarkerObjectPrefab))], making it selectable for those prefab types in the editor tooling. - Relevant types: PlaceableObjectData, PlacementFlags, ComponentType, EntityManager, Entity (Unity.Entities).