Skip to content

Game.Prefabs.DestructibleObject

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: public class

Base: ComponentBase

Summary:
DestructibleObject is a component intended for prefabs that can be damaged or destroyed. It exposes two tunable floats for fire hazard and structural integrity and integrates with the Unity.Entities-based ECS via a DestructibleObjectData component. The component registers the ECS component required for prefab conversion and writes initial component data to the entity during initialization. It is exposed in the editor under the "Objects/" component menu (see ComponentMenu attribute).


Fields

  • public float m_FireHazard = 100f
    Numeric value representing how prone the object is to catching/propagating fire. Default: 100f.

  • public float m_StructuralIntegrity = 15000f
    Numeric value representing the object's hitpoints or structural resistance to damage/destruction. Default: 15000f.

Properties

  • None.

Constructors

  • public DestructibleObject()
    No explicit constructor is defined in code; the default parameterless constructor is used. Field defaults are m_FireHazard = 100f and m_StructuralIntegrity = 15000f.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the ECS component type required by this prefab to the provided set. Specifically adds ComponentType.ReadWrite() so that instances of this prefab will include the DestructibleObjectData component at conversion time.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Left empty in this implementation. No additional archetype components are declared here.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called during entity initialization. Calls base.Initialize, then creates a DestructibleObjectData struct populated from the component's m_FireHazard and m_StructuralIntegrity fields, and writes it to the entity via entityManager.SetComponentData(entity, componentData). Requires that DestructibleObjectData is defined elsewhere with corresponding fields (m_FireHazard, m_StructuralIntegrity).

Usage Example

// This demonstrates how initialization writes the ECS component data for the prefab.
// The class already does this in Initialize; shown here is the relevant logic.
public override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);

    DestructibleObjectData componentData = default(DestructibleObjectData);
    componentData.m_FireHazard = m_FireHazard;
    componentData.m_StructuralIntegrity = m_StructuralIntegrity;

    entityManager.SetComponentData(entity, componentData);
}

Additional notes: - The ComponentMenu attribute registers this component under "Objects/" in the Unity Add Component menu, with an ObjectPrefab type link. - Ensure DestructibleObjectData exists and is compatible with the values assigned here (fields and types). The ECS component must be declared as a struct implementing IComponentData (or similar) for SetComponentData to work.