feat(shop): add box pickup/carry, pour-into-shelf, and package flight visuals
- Carryable: generic pickup/carry component, cosmetic per-peer follow of the carrier's HandSocket instead of NGO reparenting (camera pitch isn't networked, so root-level reparenting wouldn't tilt with the view) - PlayerCarry: mutual exclusion with PlayerHands, server-timed hold-to-pour tick (client only signals start/stop, never per-unit requests) - IPourSource/IPourTarget: decouple PlayerInteractor from concrete Shop types, same pattern as IInteractable - Lieferkarton: gains product data (productId/quantity), two-stage Interact() (open, then pick up), IPourSource - ShelfSlot: implements IPourTarget, fills the previous RefreshVisuals TODO - PackageDisplay: renders quantity as a proper column x row grid that stacks into further layers as space runs out, reused by both containers - FlyingPackage: small non-networked cosmetic visual that arcs a package from the carried box to its exact landing slot in the shelf grid on every successful pour tick, broadcast via Rpc(SendTo.Everyone) - StorageCrate: rejects pickup while the player is carrying a box Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AfterHours.Shop
|
||||
{
|
||||
/// <summary>
|
||||
/// Zeigt eine Stückzahl als einzelne Verpackungs-Prefabs unter einem
|
||||
/// Wurzel-Transform an (Regalfach, Lieferkarton) – ordentlich in einem
|
||||
/// Raster (Spalten x Reihen) gestapelt, weitere Lagen stapeln sich nach
|
||||
/// oben. Rein kosmetisch, läuft auf jedem Peer. Baut bei Mengenänderung
|
||||
/// nur das Delta neu, nicht die komplette Anzeige – wichtig beim
|
||||
/// Stück-für-Stück-Ausschütten.
|
||||
/// </summary>
|
||||
public sealed class PackageDisplay
|
||||
{
|
||||
private readonly Transform _root;
|
||||
private readonly int _columns;
|
||||
private readonly int _rows;
|
||||
private readonly Vector3 _spacing;
|
||||
private readonly List<GameObject> _instances = new();
|
||||
private GameObject _prefab;
|
||||
|
||||
public PackageDisplay(Transform root, int columns, int rows, Vector3 spacing)
|
||||
{
|
||||
_root = root;
|
||||
_columns = Mathf.Max(1, columns);
|
||||
_rows = Mathf.Max(1, rows);
|
||||
_spacing = spacing;
|
||||
}
|
||||
|
||||
/// <summary>Baut die Anzeige auf <paramref name="count"/> Instanzen an (gedeckelt bei maxVisible).</summary>
|
||||
public void SetTarget(GameObject prefab, int count, int maxVisible)
|
||||
{
|
||||
if (_root == null) return;
|
||||
|
||||
if (prefab != _prefab)
|
||||
{
|
||||
Clear();
|
||||
_prefab = prefab;
|
||||
}
|
||||
|
||||
if (_prefab == null) return;
|
||||
|
||||
int target = Mathf.Clamp(count, 0, Mathf.Max(0, maxVisible));
|
||||
|
||||
while (_instances.Count < target)
|
||||
{
|
||||
var instance = Object.Instantiate(_prefab, _root);
|
||||
instance.transform.localPosition = SlotLocalPosition(_instances.Count);
|
||||
instance.transform.localRotation = Quaternion.identity;
|
||||
_instances.Add(instance);
|
||||
}
|
||||
|
||||
while (_instances.Count > target)
|
||||
{
|
||||
int last = _instances.Count - 1;
|
||||
if (_instances[last] != null) Object.Destroy(_instances[last]);
|
||||
_instances.RemoveAt(last);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Lokale Rasterposition für einen Index – auch als Flug-Ziel genutzt (siehe PlayerCarry).</summary>
|
||||
public Vector3 SlotLocalPosition(int index)
|
||||
{
|
||||
int perLayer = _columns * _rows;
|
||||
int layer = index / perLayer;
|
||||
int rem = index % perLayer;
|
||||
int row = rem / _columns;
|
||||
int col = rem % _columns;
|
||||
return new Vector3(col * _spacing.x, layer * _spacing.y, row * _spacing.z);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
foreach (var instance in _instances)
|
||||
if (instance != null) Object.Destroy(instance);
|
||||
|
||||
_instances.Clear();
|
||||
_prefab = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user