Scoring and stuff.

This commit is contained in:
Khauvinkh
2024-08-18 18:42:01 +02:00
parent 1946669e64
commit 5bcc96a4a0
17 changed files with 587 additions and 42 deletions

View File

@@ -6,7 +6,6 @@ using quaternion = Unity.Mathematics.quaternion;
public static class Grid
{
public static float CellSize = 0.25f;
public static float HalfCellSize => CellSize / 2;

View File

@@ -5,39 +5,36 @@ using static Unity.Mathematics.math;
using static Grid;
using Color = UnityEngine.Color;
#if UNITY_EDITOR
[ExecuteAlways]
[SelectionBase]
[DisallowMultipleComponent]
public class GridUnit : MonoBehaviour
{
public int3 Size = new (1, 1, 1);
private Vector3 SizeInMeters => new (Size.x * CellSize, Size.y * CellSize, Size.z * CellSize);
public int3 Size = new(1, 1, 1);
private Vector3 SizeInMeters => new(Size.x * CellSize, Size.y * CellSize, Size.z * CellSize);
public float3 CenterOffset;
[SerializeField, HideInInspector]
private int3 cachedSize = new (1, 1, 1);
[SerializeField, HideInInspector]
private float3 cachedOffset;
private bool isDirty => transform.hasChanged ||
!all(cachedOffset != CenterOffset) ||
[SerializeField, HideInInspector] private int3 cachedSize = new(1, 1, 1);
[SerializeField, HideInInspector] private float3 cachedOffset;
private bool isDirty => transform.hasChanged ||
!all(cachedOffset != CenterOffset) ||
!all(cachedSize == Size);
#if UNITY_EDITOR
public void Update()
{
if (!isDirty)
{
return;
}
SnapUnit(transform, Size, CenterOffset);
transform.hasChanged = false;
cachedOffset = CenterOffset;
cachedSize = Size;
}
@@ -48,11 +45,10 @@ public class GridUnit : MonoBehaviour
Transform t = unit.transform;
quaternion rotation = t.rotation;
var position = (float3)t.position + mul(rotation, unit.CenterOffset);
Gizmos.color = Color.white;
Gizmos.matrix = Matrix4x4.TRS(position, rotation, Vector3.one);
Gizmos.DrawWireCube(Vector3.zero, unit.SizeInMeters);
}
}
#endif
}