using Unity.Entities;
using Unity.Mathematics;
using Unity.Collections;
namespace AutomaticDoorSystem
{
public struct DoorComponent : IComponentData
{
public int DoorId;
public DoorType Type;
public float AnimationDuration;
public float AutoCloseDelay;
public FixedString128Bytes RegionId;
///
/// A point on the doorway plane in the door root's local space (the mean of the panel
/// pivots). Approach-side detection measures depth along local +Z from THIS point, not from
/// the root origin, so a root that sits off the doorway still splits front/back correctly.
/// See .
///
public float3 SidePlaneLocalOrigin;
/// 1 = the FRONT is local -Z instead of +Z (DoorConfig.invertForwardSide XOR the door's override).
public byte InvertForwardSide;
}
public struct DoorStateComponent : IComponentData
{
public DoorState CurrentState;
public DoorState PreviousState;
public float StateTimer;
public int EntitiesInTrigger;
public byte IsLocked; // 0 = unlocked, 1 = locked
public byte ShouldPlayOpenSound; // 0 = no, 1 = yes
public byte ShouldPlayCloseSound; // 0 = no, 1 = yes
///
/// Side the nearest triggerable approached from when the door last left Closed:
/// 1 = FRONT (door root local +Z, unless inverted), 0 = BACK. Rotating doors with the
/// Forward style swing AWAY from this side. Only rewritten while the door is Closed, so a
/// closing door always retraces the swing it opened with.
///
public byte DirectionForward;
}
public struct DoorTransformData : IComponentData
{
public float3 SlideOffset;
public float3 InitialPosition;
public quaternion ClosedRotation;
public quaternion OpenRotationForward;
public quaternion OpenRotationBackward;
public OpeningStyle OpeningStyle;
public float3 OneWayDirection;
public SlidingStyle SlidingStyle;
/// Telescopic only: travel of the right (leading) panel, door-root local.
public float3 RightSlideOffset;
/// Telescopic only: 1 = right door stops where the left door sits (partial opening).
public byte OpenRightDoorOnly;
}
public struct DoorTriggerVolume : IComponentData
{
public float3 Size;
public float3 Center;
public int LayerMask; // Bitmask for entities that can trigger door
}
///
/// Per-door audio settings, baked from .
/// A survives subscene serialization, so the pooled
/// AudioSources in the main scene can read the ScriptableObject straight off the door
/// entity - no companion GameObject is needed in the main scene.
///
public struct DoorAudioConfigReference : IComponentData
{
public UnityObjectRef Config;
///
/// Where the pooled AudioSource is placed, relative to the door root. Baked from
/// when assigned, otherwise the trigger volume centre.
///
public float3 AnchorLocalPosition;
}
public struct DoorTriggerableTag : IComponentData { }
public struct DoorInitialPositionComponent : IComponentData
{
public float3 InitialPosition;
}
public struct DoorDebugComponent : IComponentData { }
public struct DoubleDoorBuffer : IBufferElementData
{
public Entity DoorEntity;
public byte IsLeftDoor; // 0 = right, 1 = left
public float3 ColliderSize; // BoxCollider size from prefab
public float3 ColliderCenter; // BoxCollider center from prefab
public byte HasColliderData; // 1 if collider data was extracted from prefab
///
/// The panel's authored closed local position. Sliding animation adds its travel on top of
/// this instead of overwriting the whole position, so the panel's placement on the other
/// axes (e.g. parallel-rail Z offsets) survives the first animation frame.
///
public float3 InitialLocalPosition;
///
/// Steam Audio geometry exported from the panel's SteamAudioDynamicObject (null ref when
/// the panel has none). The collider pool attaches it to the pooled panel proxy so the
/// moving door occludes and reflects sound at runtime — the baked SteamAudio components
/// themselves are stripped with the rest of the SubScene GameObjects.
///
public UnityObjectRef AudioGeometry;
}
public struct DoorAudioEventComponent : IComponentData
{
public int DoorId;
public AudioEventType EventType;
public int SoundId;
public FixedString64Bytes ClipName;
public float3 Position; // World position of the door for 3D audio (legacy, may be removed)
}
public struct DoorLockEventComponent : IComponentData
{
public int DoorId;
public byte ShouldLock; // 0 = unlock, 1 = lock
}
public struct EntityLayerComponent : IComponentData
{
public int Layer; // GameObject layer (0-31)
}
///
/// Where this door drops a player who has to leave the room it closes. Baked from the
/// DoorAuthoring's exit anchor; only doors that have one carry it.
///
/// The room itself is not stored: a door's IS the number of
/// the room it closes, so DoorZoneEvacuationProvider asks the WorldManager which zone carries
/// that number. Doors whose id matches no zone (corridor-to-corridor doors) simply never
/// answer an evacuation query.
///
///
/// The pose is door-root local, so the provider composes it with the entity's LocalToWorld
/// exactly like the trigger volume.
///
///
public struct DoorZoneExit : IComponentData
{
public float3 ExitLocalPosition;
/// Direction the player faces once placed (door-root local, horizontal).
public float3 ExitLocalForward;
}
public enum DoorType : byte
{
RotatingSingle = 0,
RotatingDouble = 1,
SlidingSingle = 2,
SlidingDouble = 3
}
public enum DoorState : byte
{
Closed = 0,
Opening = 1,
Open = 2,
Closing = 3
}
public enum AudioEventType : byte
{
Open = 0,
Close = 1,
Lock = 2,
Unlock = 3
}
public enum OpeningStyle : byte
{
Forward = 0, // Both doors open away from player (default behavior)
BothWay = 1, // Right door opens forward, left door opens backward
OneWay = 2 // Both doors always open in a specific direction
}
public enum SlidingStyle : byte
{
Mirrored = 0, // Panels part in opposite directions (default)
Telescopic = 1 // Both panels slide the same direction, right door leads, panels stack
}
}