snap fix
This commit is contained in:
@@ -108,14 +108,31 @@ namespace Darkmatter.Features.ShapeBuilder.Systems
|
||||
|
||||
_bus.Publish(new ShapeBuilderStartedSignal(template.Id));
|
||||
|
||||
CreateShapePieceInstances(template, preSnappedIds, count, slots, pitch, trayW);
|
||||
var colorByShapeId = BuildColorMap(template, slots);
|
||||
foreach (var s in slots)
|
||||
if (s != null && s.Shape != null && colorByShapeId.TryGetValue(s.Shape.Id, out var c))
|
||||
s.SetColor(c);
|
||||
|
||||
CreateShapePieceInstances(template, preSnappedIds, count, slots, pitch, trayW, colorByShapeId);
|
||||
|
||||
CheckIfShapeAssembled();
|
||||
}
|
||||
|
||||
private static Dictionary<string, Color> BuildColorMap(IDrawingTemplate template, SlotMarker[] slots)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
private void CreateShapePieceInstances(IDrawingTemplate template, IReadOnlyCollection<string> preSnappedIds,
|
||||
int count,
|
||||
SlotMarker[] slots, float pitch, float trayW)
|
||||
SlotMarker[] slots, float pitch, float trayW, Dictionary<string, Color> colorByShapeId)
|
||||
{
|
||||
var preSnapCounts = new Dictionary<string, int>();
|
||||
if (preSnappedIds != null)
|
||||
@@ -137,6 +154,8 @@ namespace Darkmatter.Features.ShapeBuilder.Systems
|
||||
|
||||
var trayPos = new Vector2(pitch * (i + 1) - trayW * 0.5f, 0f);
|
||||
var piece = _factory.Create(_piecePrefab, shape, candidates, trayPos);
|
||||
if (colorByShapeId != null && colorByShapeId.TryGetValue(shape.Id, out var c))
|
||||
piece.SetColor(c);
|
||||
_pieces.Add(piece);
|
||||
|
||||
if (preSnapCounts.TryGetValue(shape.Id, out var remaining) && remaining > 0)
|
||||
|
||||
@@ -59,6 +59,11 @@ namespace Darkmatter.Features.ShapeBuilder.UI
|
||||
|
||||
public void ReassignActiveSlot(SlotMarker slot) => _activeSlot = slot;
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
if (image != null) image.color = color;
|
||||
}
|
||||
|
||||
public void Setup(
|
||||
ShapeSO shape,
|
||||
SlotMarker[] candidateSlots,
|
||||
@@ -227,27 +232,18 @@ namespace Darkmatter.Features.ShapeBuilder.UI
|
||||
{
|
||||
StopPreviewTweens();
|
||||
Lock();
|
||||
var slot = _activeSlot.RectTransform;
|
||||
|
||||
Sequence.Create()
|
||||
.Group(Tween.Position(RectTransform, slot.position, _cfg.SnapDuration, Ease.OutBack))
|
||||
.Group(Tween.Rotation(RectTransform, slot.rotation, _cfg.SnapDuration, Ease.OutBack))
|
||||
.Group(Tween.LocalScale(RectTransform, slot.localScale, _cfg.SnapDuration, Ease.OutBack))
|
||||
.Group(Tween.UISizeDelta(RectTransform, slot.sizeDelta, _cfg.SnapDuration, Ease.OutBack))
|
||||
.ChainCallback(AlignRectToSlot);
|
||||
FillSlot();
|
||||
|
||||
_sfx.Play(SfxId.ShapeSnap);
|
||||
_bus.Publish(new PieceSnappedSignal(_shape.Id));
|
||||
}
|
||||
|
||||
private void AlignRectToSlot()
|
||||
private void FillSlot()
|
||||
{
|
||||
if (this == null || _activeSlot == null) return;
|
||||
var rt = RectTransform;
|
||||
var slot = _activeSlot.RectTransform;
|
||||
rt.anchorMin = Vector2.zero;
|
||||
rt.anchorMax = Vector2.one;
|
||||
rt.pivot = slot.pivot;
|
||||
rt.pivot = new Vector2(0.5f, 0.5f);
|
||||
rt.anchoredPosition = Vector2.zero;
|
||||
rt.sizeDelta = Vector2.zero;
|
||||
rt.localRotation = Quaternion.identity;
|
||||
@@ -283,7 +279,7 @@ namespace Darkmatter.Features.ShapeBuilder.UI
|
||||
{
|
||||
_activeSlot = slot;
|
||||
Lock();
|
||||
AlignRectToSlot();
|
||||
FillSlot();
|
||||
}
|
||||
|
||||
private void ReturnToTray()
|
||||
|
||||
@@ -20,5 +20,10 @@ namespace Darkmatter.Features.ShapeBuilder.UI
|
||||
{
|
||||
if (outline != null) outline.enabled = visible;
|
||||
}
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
if (outline != null) outline.color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user