using UnityEngine; namespace Ashwild.Building { /// /// Connection category of a snap socket — two sockets link only when their categories match. /// Authored so that connectable sockets share a value (e.g. a floor's edge and a wall's foot /// are both Floor, so a wall snaps onto a floor edge; walls meet side-to-side as Wall). /// public enum SnapCategory { Floor, Wall, Roof, Pillar, Custom } /// /// One connection socket on a buildable, placed as a child transform at an edge/corner. Its /// world position is where a matching socket clicks into place; its category decides what may /// connect. Built pieces carry an enabled trigger collider on the snap layer so the placement /// controller finds them by overlap; the ghost's own snap colliders are disabled with the rest /// of the ghost, so the ghost never snaps to itself. /// /// Once another piece connects here the socket is marked occupied — the placement snapping skips /// occupied sockets (so two pieces never stack on the same connection) and its gizmo turns from /// blue (free) to red (occupied) in the Scene view. /// [DisallowMultipleComponent] public class BuildSnapPoint : MonoBehaviour { #region Serialized Fields [Tooltip("What may connect here — a socket links only to another of the same category.")] [SerializeField] private SnapCategory category; #endregion #region State private bool occupied; #endregion #region Public API public SnapCategory Category => category; /// /// Whether another piece is already connected to this socket. /// public bool IsOccupied => occupied; /// /// Flags the socket as taken (or freed) — set when a piece connects/disconnects here. /// public void SetOccupied(bool value) => occupied = value; #endregion #region Gizmos /// /// Draws the socket in the editor: a sphere (blue when free, red once occupied) plus a ray /// along its forward (Z) axis — the direction the connecting piece attaches. Two sockets link /// only when their forwards face each other, so orient each empty's blue arrow outward toward /// where the neighbour should sit. /// private void OnDrawGizmos() { Gizmos.color = occupied ? new Color(1f, 0.3f, 0.3f, 0.9f) : new Color(0.3f, 0.8f, 1f, 0.9f); Gizmos.DrawWireSphere(transform.position, 0.12f); Gizmos.DrawRay(transform.position, transform.forward * 0.35f); } #endregion } }