A component demonstrating the design system for world pieces in the game world. It creates a marker and a label on start, and provides a Replay method to show an animated visual feedback effect.
namespace CitySim.Ui.DesignSystem.World;
/// <summary>Runtime sample for the design-system showcase. Add to an object in a lit scene.</summary>
public sealed class WorldPiecesShowcase : Component
{
GameObject marker;
GameObject label;
GameObject feedback;
float responseAge = 1;
bool responding;
protected override void OnStart()
{
marker = WorldPieces.Marker(GameObject);
marker.LocalPosition = Vector3.Zero;
label = WorldPieces.Label(GameObject, GameText.Get("ui.world_pieces_showcase.claimed_plot"));
label.LocalPosition = Vector3.Up * 30;
}
/// <summary>Replay a small, non-blocking response.</summary>
public void Replay()
{
if (!marker.IsValid()) return;
if (feedback.IsValid()) feedback.Destroy();
marker.LocalScale = Vector3.One;
responding = true;
responseAge = 0;
feedback = WorldPieces.Feedback(GameObject, "+2", marker.WorldPosition + Vector3.Up * 48, 1.1f);
}
protected override void OnUpdate()
{
if (!responding || !marker.IsValid()) return;
responseAge += Time.Delta;
var t = Math.Clamp(responseAge / 0.28f, 0, 1);
// A small ease-out pulse which returns exactly to rest.
var pulse = 0.16f * MathF.Sin(t * MathF.PI) * (1 - t);
marker.LocalScale = new Vector3(1 + pulse, 1 + pulse, 1);
if (t >= 1) { marker.LocalScale = Vector3.One; responding = false; }
}
protected override void OnDestroy()
{
if (feedback.IsValid()) feedback.Destroy();
if (marker.IsValid()) marker.Destroy();
if (label.IsValid()) label.Destroy();
}
}