(Feat) Add Build
This commit is contained in:
@@ -24,8 +24,9 @@ namespace Ashwild.Building
|
||||
/// 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.
|
||||
/// occupied sockets (so two pieces never stack on the same connection) and its gizmo turns red
|
||||
/// in the Scene view; while free it takes the colour of its category, so a glance at a prefab
|
||||
/// tells which sockets can ever link together.
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
public class BuildSnapPoint : MonoBehaviour
|
||||
@@ -61,19 +62,42 @@ namespace Ashwild.Building
|
||||
|
||||
#region Gizmos
|
||||
|
||||
private static readonly Color OccupiedColor = new Color(1f, 0.3f, 0.3f, 0.9f);
|
||||
private static readonly Color FloorColor = new Color(0.3f, 0.8f, 1f, 0.9f);
|
||||
private static readonly Color WallColor = new Color(0.4f, 1f, 0.5f, 0.9f);
|
||||
private static readonly Color RoofColor = new Color(1f, 0.75f, 0.25f, 0.9f);
|
||||
private static readonly Color PillarColor = new Color(0.8f, 0.5f, 1f, 0.9f);
|
||||
private static readonly Color CustomColor = new Color(1f, 1f, 1f, 0.9f);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// Draws the socket in the editor: a sphere 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 arrow outward toward where the neighbour should sit.
|
||||
/// </summary>
|
||||
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.color = occupied ? OccupiedColor : GetCategoryColor(category);
|
||||
Gizmos.DrawWireSphere(transform.position, 0.12f);
|
||||
Gizmos.DrawRay(transform.position, transform.forward * 0.35f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a connection category to its Scene-view colour. Sockets that can link share a
|
||||
/// category, so same-coloured gizmos are exactly the ones that may ever snap together —
|
||||
/// mismatched colours on two pieces mean they will never connect.
|
||||
/// </summary>
|
||||
private static Color GetCategoryColor(SnapCategory value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case SnapCategory.Floor: return FloorColor;
|
||||
case SnapCategory.Wall: return WallColor;
|
||||
case SnapCategory.Roof: return RoofColor;
|
||||
case SnapCategory.Pillar: return PillarColor;
|
||||
default: return CustomColor;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user