// PanelCounter.cs // The simplest custom panel (CreatePanel): just an ICON and a NUMBER floating on the screen, with no card or background // behind it. Every time the object this script is on (or ClickTarget) is clicked by ANY player, the number goes up for // EVERYONE at once, and players who join later see the current number. Place it anywhere on screen with ScreenX / ScreenY // (a percent of the screen's width and height) and a Pivot. A good fit for a shared tally, a team score, a "people here" // count, a collectible counter, and so on. using IHXR.Simulation; public class PanelCounter : ScriptBase { [Header("Icon + number")] [Tooltip("The little picture shown before the number (optional: leave empty for just a number).")] public TextureItem Icon; [Tooltip("Words before the number (optional), e.g. \"Score\". Empty = just the number.")] public string Label = ""; public int StartValue = 0; [Tooltip("How much each click adds.")] public int Step = 1; [Range(12, 72)] public int TextSize = 30; [Tooltip("How big the icon is, in pixels.")] [Range(16, 128)] public int IconSize = 36; public Color TextColor = new Color(1f, 1f, 1f); [Header("Where on screen (percent)")] [Tooltip("Which point of the icon + number is pinned to the position below.")] public PanelAnchor Pivot = PanelAnchor.TopCenter; [Tooltip("Across the screen: 0 = left edge, 50 = middle, 100 = right edge.")] [Range(0f, 100f)] public float ScreenX = 70f; [Tooltip("Down the screen: 0 = top, 100 = bottom.")] [Range(0f, 100f)] public float ScreenY = 6f; [Header("What players click")] [Tooltip("The object players click to add one. Empty = the object this script is on.")] public SceneObject ClickTarget; public string ClickHint = "Add one"; private ScriptPanel panel; private PanelItem counter; private int count; public override void Start() { count = StartValue; panel = CreatePanel("counter", 240); panel.SetMode(PanelMode.Overlay) .SetScreenPosition(ScreenX, ScreenY, Pivot) .SetBackgroundColor(Color.clear) // no card / background: just the icon and number show .SetBorder(Color.clear, 0) .SetClosable(false) .SetLayout(1, 4, 6, PanelAlign.Center) .SetFont(PanelFont.Heavy, TextSize) .SetTextColor(TextColor); counter = panel.AddCounter(Text(), Icon); counter.SetFontSize(TextSize) .SetImageSize(IconSize) // the row grows to fit the icon automatically .SetAlign(PanelAlign.Center); panel.ShowToEveryone(); // everyone sees it; players who join later get the current number too // Any player clicking the object adds to the shared count (the callback runs once, on the server). if (ClickTarget != null && !ClickTarget.IsNull) MakeInteractable(ClickTarget, click => Add(), true, null, true, 12f, ClickHint); else MakeInteractable(click => Add(), true, null, true, 12f, ClickHint); } private string Text() { return string.IsNullOrEmpty(Label) ? count.ToString() : Label + " " + count; } private void Add() { count += Step; counter.SetText(Text()); // no username = for everyone, and kept for players who join later } }