SDK Feature Lab
A neon rooftop plaza with one bay for each of the newer SDK features. Walk up to a bay, press its device and read the panel above it. Most bays are more fun with a friend: dice, fireworks and props show up for everyone in the room.
Get it from the StageTime-Worlds-Examples repository: copy
the Worlds/FeatureLab folder into a Unity project that has the StageTime World SDK, and open its scene. The world's
18 scripts are in Worlds/FeatureLab/Scripts.
| Bay | What to try | Built with |
|---|---|---|
| Hub | Post a line and an emote; sign the guestbook | Announcer (below), Guestbook |
| 01 Clock | A daily reward with a streak | Clock board, LabRewards (below), Date and time |
| 02 Saved data | Visits, a best score and a colour locker kept between visits | Save board, LabRewards, Player data |
| 03 Inventory | Collect, sort and count items | Inventory |
| 04 Dice | Roll; everyone sees who rolled what | Dice roller |
| 05 Scanner | Scan the crates; move one and scan again; pulse the radar | Area scanner, PulseRadar (below), Physics queries |
| 06 Party | Confetti and fireworks for the whole room | Confetti spawner, FireworkLauncher (below) |
| 07 Props | Deal props everyone can pick up; return them | Pool deck, ST Networked Pool |
| 08 Vault | Guess today's code; check a typed number | KeypadLock (below), Score input |
More stations stand on the open floor between the bays:
| Station | What to try | Built with |
|---|---|---|
| High five | Touch hands with another player: your controllers buzz | High five |
| Launch pad | Step on it to fly; click it to go back to the spawn | Launch pad |
| Goal | Throw the ball at the board; the button brings the ball back | Goal counter, RespawnButton |
| Forecast race | Press the button while a friend watches: the Forecast ball leads, the other trails | Forecast race |
| Beach volleyball | Hit the big ball over the net with your hands (click it on desktop) | Beach ball |
The ball's owner reports each goal to the goal's owner, so everyone sees the same score.
Saved data is kept per player and per world. In a published world it is saved on StageTime's servers; in Play Mode and Build & Test it is saved on your device. If saving is off, the panels say so.
Daily reward and locker
LabRewards serves two bays. Claim gives 10 coins once per UTC day (STTime.utcDay) and grows a streak when you
come back the next day. The locker spends coins on badge colours. Coins, the streak, the unlocked colours (a bitmask)
and the chosen colour are all PlayerData ints.
using StageTime.SDK;
using TMPro;
using UnityEngine;
/// <summary>
/// A daily reward and a cosmetics locker kept in <c>PlayerData</c>. <c>Claim</c> gives coins once per UTC day
/// (<c>STTime.utcDay</c>), more for a streak of days in a row. <c>Unlock0</c> to <c>Unlock2</c> buy a badge colour with
/// coins the first time and wear it after that; the colour shows on <c>badge</c> for this player. Hook the methods to
/// Buttons' On Click (UI calls methods without parameters, so there is one per colour).
/// </summary>
public class LabRewards : StageTimeBehaviour
{
public TMP_Text claimLabel;
public TMP_Text lockerLabel;
public Renderer badge;
public string[] colourNames = { "Cyan", "Gold", "Magenta" };
public Color[] tints = { new Color(0.2f, 0.9f, 1f), new Color(1f, 0.75f, 0.2f), new Color(1f, 0.3f, 0.85f) };
public int[] costs = { 0, 30, 60 };
private int coins;
private int streak;
private int unlocked; // one bit per colour
private int equipped;
private string claimStatus = "";
private string lockerStatus = "";
private void Start()
{
coins = PlayerData.GetInt("coins");
streak = PlayerData.GetInt("streak");
unlocked = PlayerData.GetInt("unlocked", 1); // the first colour is free
equipped = PlayerData.GetInt("equipped");
if (equipped < 0 || equipped >= tints.Length) equipped = 0;
claimStatus = PlayerData.GetInt("claimDay", -1) == STTime.utcDay ? "Claimed today" : "Your reward is ready";
Show();
}
public void Claim()
{
int today = STTime.utcDay;
int last = PlayerData.GetInt("claimDay", -1);
if (last == today)
{
claimStatus = "Come back after the reset";
Show();
return;
}
streak = last == today - 1 ? streak + 1 : 1;
int reward = 10 * Mathf.Min(streak, 5);
coins += reward;
PlayerData.SetInt("claimDay", today);
PlayerData.SetInt("streak", streak);
PlayerData.SetInt("coins", coins);
claimStatus = "+" + reward + " coins, streak " + streak;
Show();
}
public void Unlock0() => Unlock(0);
public void Unlock1() => Unlock(1);
public void Unlock2() => Unlock(2);
private void Unlock(int index)
{
if (index < 0 || index >= tints.Length) return;
int bit = 1 << index;
if ((unlocked & bit) == 0)
{
if (coins < costs[index])
{
lockerStatus = colourNames[index] + " costs " + costs[index] + " coins";
Show();
return;
}
coins -= costs[index];
unlocked |= bit;
PlayerData.SetInt("coins", coins);
PlayerData.SetInt("unlocked", unlocked);
lockerStatus = "Unlocked " + colourNames[index];
}
else
{
lockerStatus = "Wearing " + colourNames[index];
}
equipped = index;
PlayerData.SetInt("equipped", equipped);
Show();
}
public override void OnPlayerDataSaveFailed()
{
lockerStatus = "Not saved: " + PlayerData.lastError;
Show();
}
private void Show()
{
string saving = PlayerData.isAvailable ? "" : "\n<size=80%>Saving is off in this world</size>";
if (claimLabel != null)
claimLabel.text = $"Coins: {coins} Streak: {streak}\n{claimStatus}{saving}";
if (lockerLabel != null)
{
string owned = "";
for (int i = 0; i < tints.Length; i++)
owned += (i > 0 ? " " : "") + colourNames[i] + ((unlocked & (1 << i)) != 0 ? (i == equipped ? " (on)" : " (owned)") : " " + costs[i] + "c");
lockerLabel.text = $"Coins: {coins}\n{owned}\n{lockerStatus}{saving}";
}
if (badge != null) badge.material.color = tints[equipped];
}
}
Announcer
A text field and three emote buttons. The text goes to everyone as a value of a
[NetworkCallable] event, at most once a second per player. Each
device checks the value again (length and emote number) before it shows it, and the board keeps the last four lines.
using StageTime.SDK;
using TMPro;
/// <summary>
/// A shared announcement board: type a message and press Send, or press an emote button, and everyone sees it with
/// the sender's name. The text and an emote number travel as the values of one network event (a string and an int);
/// <c>Show</c> checks them, because they come from another player's device. Each player can post once a second.
/// </summary>
public class Announcer : StageTimeBehaviour
{
public TMP_InputField input;
public TMP_Text board;
public int maxLength = 48;
private readonly string[] lines = new string[4];
private void Start() => Refresh();
public void Send()
{
if (input == null) return;
string text = input.text.Trim();
if (text.Length == 0) return;
if (text.Length > maxLength) text = text.Substring(0, maxLength);
input.text = "";
SendCustomNetworkEvent(NetworkEventTarget.All, nameof(Show), text, 0);
}
public void Wave() => SendCustomNetworkEvent(NetworkEventTarget.All, nameof(Show), "", 1);
public void Cheer() => SendCustomNetworkEvent(NetworkEventTarget.All, nameof(Show), "", 2);
public void Clap() => SendCustomNetworkEvent(NetworkEventTarget.All, nameof(Show), "", 3);
[NetworkCallable(maxEventsPerSecond: 1)]
public void Show(string text, int emote)
{
if (emote < 0 || emote > 3 || text.Length > maxLength) return; // check values from other devices
if (emote == 0 && text.Length == 0) return;
StageTimePlayer sender = NetworkCalling.CallingPlayer;
string name = sender != null ? sender.displayName : "Someone";
string line;
switch (emote)
{
case 1: line = $"<color=#7FE7FF>{name}</color> waves"; break;
case 2: line = $"<color=#7FE7FF>{name}</color> cheers!"; break;
case 3: line = $"<color=#7FE7FF>{name}</color> applauds"; break;
default: line = $"<color=#7FE7FF>{name}:</color> <noparse>{text}</noparse>"; break;
}
for (int i = lines.Length - 1; i > 0; i--) lines[i] = lines[i - 1];
lines[0] = line;
Refresh();
}
private void Refresh()
{
if (board == null) return;
string text = "";
for (int i = 0; i < lines.Length; i++)
if (lines[i] != null) text += (text.Length > 0 ? "\n" : "") + lines[i];
board.text = text.Length > 0 ? text : "Say hello to everyone here";
}
}
Radar
Press the radar and every device lists the players within six metres, nearest first, with
STPhysics.OverlapPlayers, while a ring sweeps out.
using StageTime.SDK;
using TMPro;
using UnityEngine;
/// <summary>
/// A radar: press it and every player's device sends out a pulse that lists the players within <c>radius</c> metres,
/// nearest first, with their distance (<c>STPhysics.OverlapPlayers</c>). Only the press is sent; each device runs its
/// own query. <c>ring</c> grows outwards for a second to show the pulse.
/// </summary>
public class PulseRadar : StageTimeBehaviour
{
public TMP_Text label;
public Transform ring;
public float radius = 6f;
public float pulseSeconds = 1f;
private readonly StageTimePlayer[] found = new StageTimePlayer[16];
private float pulseStart = -10f;
private float lastPress = -10f;
private bool pulsing;
private void Start()
{
if (ring != null) ring.localScale = Vector3.zero;
if (label != null) label.text = "Press the radar to scan " + radius.ToString("0") + " m";
}
public override void Interact()
{
if (Time.time - lastPress < 1f) return; // one pulse a second
lastPress = Time.time;
SendCustomNetworkEvent(NetworkEventTarget.All, nameof(Pulse));
}
public void Pulse()
{
Vector3 center = transform.position;
int count = STPhysics.OverlapPlayers(center, radius, found);
StageTimePlayer sender = NetworkCalling.CallingPlayer;
string text = (sender != null ? sender.displayName : "Someone") + " pulsed: " + count + (count == 1 ? " player" : " players");
for (int i = 0; i < count && i < 4; i++)
{
Vector3 offset = found[i].GetPosition() - center;
offset.y = 0f;
text += "\n" + (i + 1) + ". " + found[i].displayName + " " + offset.magnitude.ToString("0.0") + " m";
}
if (count > 4) text += "\n+" + (count - 4) + " more";
if (label != null) label.text = text;
pulseStart = Time.time;
pulsing = true;
}
private void Update()
{
if (!pulsing || ring == null) return;
float t = (Time.time - pulseStart) / pulseSeconds;
if (t >= 1f)
{
ring.localScale = Vector3.zero;
pulsing = false;
return;
}
float size = radius * 2f * t;
ring.localScale = new Vector3(size, 1f, size);
}
}
Fireworks
The presser's device picks a point in the sky and a shell, and sends both as event values. Each device makes its own
local copy of that shell with Instantiate and destroys it three seconds later, so nothing about the fireworks is
synced after the event.
using StageTime.SDK;
using TMPro;
using UnityEngine;
/// <summary>
/// Fireworks (local Instantiate with network event values): press the launcher and it picks a point in the sky and a
/// shell, and sends both to everyone with <c>SendCustomNetworkEvent(All, nameof(Fire), position, kind)</c>. Each device
/// makes its own copy of that shell (an inactive Particle System burst with Play On Awake) at the same place, and
/// destroys it a few seconds later. <c>Fire</c> checks the values, since they come from another player's device.
/// </summary>
public class FireworkLauncher : StageTimeBehaviour
{
public GameObject[] shells;
public TMP_Text label;
public float lifetime = 3f;
public float spread = 5f;
public float minHeight = 6f;
public float maxHeight = 9f;
private const int MaxLive = 8;
private readonly GameObject[] live = new GameObject[MaxLive];
private int oldest;
private int count;
private int launched;
private void Start() => Show("Press the launcher");
public override void Interact()
{
Vector3 pos = transform.position + new Vector3(Random.Range(-spread, spread), Random.Range(minHeight, maxHeight), Random.Range(-spread, spread));
SendCustomNetworkEvent(NetworkEventTarget.All, nameof(Fire), pos, Random.Range(0, shells.Length));
}
[NetworkCallable(maxEventsPerSecond: 2)]
public void Fire(Vector3 pos, int kind)
{
if (kind < 0 || kind >= shells.Length || (pos - transform.position).sqrMagnitude > 400f) return;
if (count == MaxLive) RemoveOldest(); // keep our own cap well under the world's
GameObject fx = Instantiate(shells[kind], pos, Quaternion.identity);
if (fx == null) return; // a limit stopped it; the log says which
live[(oldest + count) % MaxLive] = fx;
count++;
launched++;
SendCustomEventDelayedSeconds(nameof(RemoveOldest), lifetime);
StageTimePlayer sender = NetworkCalling.CallingPlayer;
Show((sender != null ? sender.displayName : "Someone") + " launched one");
}
public void RemoveOldest()
{
if (count == 0) return;
Destroy(live[oldest]);
live[oldest] = null;
oldest = (oldest + 1) % MaxLive;
count--;
}
private void Show(string last)
{
if (label != null) label.text = last + "\nFireworks so far: " + launched;
}
}
Vault keypad
Today's three-digit code comes from STTime.utcDay, so it is the same for everyone and changes at midnight UTC. Each
wrong guess says Higher or Lower. The vault opens only for the player who guessed it, and the fewest tries is saved
with PlayerData.
using StageTime.SDK;
using TMPro;
using UnityEngine;
/// <summary>
/// A vault with a three-digit code that changes every UTC day. Key0 to Key9 type a digit, Clear starts again and
/// Enter tries the code: a wrong guess says Higher or Lower, the right one slides the door open for this player.
/// <c>TryCheck</c> returns the guess and a hint through <c>out</c> parameters; the fewest tries is kept in
/// <c>PlayerData</c>. Hook every method to a Button's On Click.
/// </summary>
public class KeypadLock : StageTimeBehaviour
{
public TMP_Text display;
public TMP_Text label;
public Transform door;
public Vector3 openOffset = new Vector3(0f, 2.2f, 0f);
public float openSeconds = 1.2f;
private string entered = "";
private int tries;
private int best;
private bool open;
private Vector3 closedPos;
private float moveStart = -10f;
private bool moving;
private void Start()
{
if (door != null) closedPos = door.localPosition;
best = PlayerData.GetInt("vaultBest");
label.text = "Today's code is new. Guess it!" + Best();
ShowDisplay();
}
public void Key0() => Type("0");
public void Key1() => Type("1");
public void Key2() => Type("2");
public void Key3() => Type("3");
public void Key4() => Type("4");
public void Key5() => Type("5");
public void Key6() => Type("6");
public void Key7() => Type("7");
public void Key8() => Type("8");
public void Key9() => Type("9");
public void Clear()
{
entered = "";
if (open)
{
open = false; // close the vault again for another go
tries = 0;
StartMove();
label.text = "Locked again." + Best();
}
ShowDisplay();
}
public void Enter()
{
if (open) return;
if (!TryCheck(entered, out int guess, out string hint))
{
label.text = hint + Best();
entered = "";
ShowDisplay();
return;
}
open = true;
StartMove();
if (best == 0 || tries < best)
{
best = tries;
PlayerData.SetInt("vaultBest", best);
}
label.text = $"Open! Code {guess} in {tries} {(tries == 1 ? "try" : "tries")}" + Best();
ShowDisplay();
}
/// <summary>True when <paramref name="text"/> is today's code; otherwise a hint for the player.</summary>
private bool TryCheck(string text, out int guess, out string hint)
{
hint = "";
if (!int.TryParse(text, out guess))
{
hint = "Type 3 digits first";
return false;
}
int code = STTime.utcDay * 7919 % 1000;
tries++;
if (guess != code)
{
hint = guess + "? " + (guess < code ? "Higher" : "Lower") + " (try " + tries + ")";
return false;
}
return true;
}
private void Type(string digit)
{
if (open || entered.Length >= 3) return;
entered += digit;
ShowDisplay();
}
private void ShowDisplay()
{
if (display == null) return;
if (open) { display.text = "OPEN"; return; }
string text = entered;
while (text.Length < 3) text += "_";
display.text = text;
}
private string Best() => best > 0 ? "\nYour best: " + best + (best == 1 ? " try" : " tries") : "";
private void StartMove()
{
moveStart = Time.time;
moving = door != null;
}
private void Update()
{
if (!moving) return;
float t = Mathf.Clamp01((Time.time - moveStart) / openSeconds);
float eased = t * t * (3f - 2f * t);
Vector3 from = open ? closedPos : closedPos + openOffset;
Vector3 to = open ? closedPos + openOffset : closedPos;
door.localPosition = Vector3.Lerp(from, to, eased);
if (t >= 1f) moving = false;
}
}