This commit is contained in:
Savya Bikram Shah
2026-06-07 16:07:30 +05:45
parent 521b5c3b7d
commit 0b9d0ca8f2
5 changed files with 372 additions and 101 deletions

View File

@@ -107,31 +107,32 @@ namespace Darkmatter.Features.ShapeBuilder.Systems
_bus.Publish(new ShapeBuilderStartedSignal(template.Id));
var colorByShapeId = BuildColorMap(template, slots);
// Distinct color per element — every piece and slot gets its own color,
// even when two pieces share the same shape. Hues are stepped by the
// golden ratio so successive colors land far apart on the wheel.
float hue = UnityEngine.Random.value;
foreach (var s in slots)
if (s != null && s.Shape != null && colorByShapeId.TryGetValue(s.Shape.Id, out var c))
s.SetColor(c);
if (s != null)
s.SetColor(NextDistinctColor(ref hue));
CreateShapePieceInstances(template, preSnappedIds, count, slots, colorByShapeId);
CreateShapePieceInstances(template, preSnappedIds, count, slots, ref hue);
CheckIfShapeAssembled();
}
private static Dictionary<string, Color> BuildColorMap(IDrawingTemplate template, SlotMarker[] slots)
// Conjugate of the golden ratio; adding it (mod 1) to a hue each step
// produces a maximally-spread, low-collision sequence of distinct colors.
private const float GoldenHueStep = 0.61803398875f;
private static Color NextDistinctColor(ref float hue)
{
var map = new Dictionary<string, Color>();
foreach (var p in template.Pieces)
if (p != null && !string.IsNullOrEmpty(p.Id) && !map.ContainsKey(p.Id))
map[p.Id] = Color.HSVToRGB(UnityEngine.Random.value, 0.7f, 0.95f);
foreach (var s in slots)
if (s != null && s.Shape != null && !string.IsNullOrEmpty(s.Shape.Id) && !map.ContainsKey(s.Shape.Id))
map[s.Shape.Id] = Color.HSVToRGB(UnityEngine.Random.value, 0.7f, 0.95f);
return map;
hue = Mathf.Repeat(hue + GoldenHueStep, 1f);
return Color.HSVToRGB(hue, 0.7f, 0.95f);
}
private void CreateShapePieceInstances(IDrawingTemplate template, IReadOnlyCollection<string> preSnappedIds,
int count,
SlotMarker[] slots, Dictionary<string, Color> colorByShapeId)
SlotMarker[] slots, ref float hue)
{
var preSnapCounts = new Dictionary<string, int>();
if (preSnappedIds != null)
@@ -152,8 +153,7 @@ namespace Darkmatter.Features.ShapeBuilder.Systems
}
var piece = _factory.Create(_piecePrefab, shape, candidates, Vector2.zero);
if (colorByShapeId != null && colorByShapeId.TryGetValue(shape.Id, out var c))
piece.SetColor(c);
piece.SetColor(NextDistinctColor(ref hue));
_pieces.Add(piece);
if (preSnapCounts.TryGetValue(shape.Id, out var remaining) && remaining > 0)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -759,7 +759,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0}
m_AnchorMax: {x: 0.5, y: 0}
m_AnchoredPosition: {x: 180.83, y: 121}
m_AnchoredPosition: {x: 227, y: 189}
m_SizeDelta: {x: 416.99, y: 163}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &176415042
@@ -1039,7 +1039,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0}
m_AnchorMax: {x: 0.5, y: 0}
m_AnchoredPosition: {x: -188, y: 123}
m_AnchoredPosition: {x: -251, y: 191}
m_SizeDelta: {x: 452.9619, y: 188}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &281513991
@@ -2411,6 +2411,7 @@ MonoBehaviour:
reloadDelaySeconds: 5
reloadMaxAttempts: 6
showWatchdogSeconds: 60
maxInterstitialsPerSession: 8
--- !u!1 &1173091301
GameObject:
m_ObjectHideFlags: 0
@@ -2445,8 +2446,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -27}
m_SizeDelta: {x: -100, y: 250}
m_AnchoredPosition: {x: 0, y: -80}
m_SizeDelta: {x: -245.3866, y: 250}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &1173091303
MonoBehaviour:
@@ -3405,7 +3406,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 812.0266, y: 475.6666}
m_SizeDelta: {x: 1258.6208, y: 649.8453}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1770001639
MonoBehaviour:
@@ -3427,7 +3428,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 9e71c03172e6fbc4695437390c3f102d, type: 3}
m_Sprite: {fileID: 21300000, guid: 0495ef6331178714baeafb47f946f3d9, type: 3}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1