UI Toolbox logoUI Toolbox
Support

Factory

A plant of machines that fill orders. The machines stamp, turn and shake while they work, and their parts ride belts to a dock. An order asks for parts of each kind, and a larger order follows when it ships. A table shows the live values, a graph shows the temperatures, and a pie, a gauge, a trend line and a counter show the output. New parts rise from the machines as green numbers. A click on a machine opens a window with gauges and a temperature graph, and a notification shows when a machine gets hot. The scene uses a DataGrid, a Graph, a PieChart, Gauge controls, a Sparkline, a ResourceCounter, an ObjectiveTracker, a FloatingTextLayer, dock zones and the notifications of the workspace.

Factory: the dashboard windows Order, Machines, Temperatures, Output and Alerts around the machines and the belts

Scene: Assets/UIToolbox/Examples/Scenes/Factory.unity. Folder: Assets/UIToolbox/Examples/Factory.

Try it

  1. Look at the machines in the middle. A press stamps, a lathe and a mill turn, a welder shakes and an oven breathes. A fast machine moves more.
  2. Watch the parts. Each new part leaves its machine on a short feeder and rides the belt to the dock at the end. The color of a part tells its kind.
  3. Look at the Order window at the top. It has one line for each kind of machine. The shipped parts fill the lines. When all lines are full, the order fades out, "Order 1 shipped!" rises over the machines, and order 2 asks for twice as many parts.
  4. Look at the five windows: Order, Machines, Temperatures, Output and Alerts. The values change twice a second, and each machine with new parts shows them as a rising "+1".
  5. Click a machine cube in the 3D scene, or click Details in a row of the Machines grid. A window opens with three gauges and a temperature graph.
  6. Click Stop in the detail window. The machine cools down, stops moving and its cube turns gray. No parts leave it, so the order waits. Click Restart to start it again.
  7. Wait for a fault. Now and then a machine heats up. A warning notification shows at 80 degrees, and an error notification shows at 95. The notification has a Details button. An error also has a Stop button that pulses red.
  8. Look at the Alerts window. Each status change and each shipped order adds a line at the top.
  9. Drag a window to the left or right edge of the screen. The window docks there.
  10. Click Arrange in the toolbar. The screens return to the edges, and the machines stay in view in the middle.
  11. Click a column header in the Machines grid to sort.

What it shows

The line

FactoryLine builds a floor, a belt between the two rows of machines, a short feeder from each machine to the belt and a dock at the end. It needs no scene objects: the controller makes it at start, around the machines it finds. Each part that a machine makes rides its feeder and the belt to the dock, where it counts as shipped.

The parts are a pool of 64 small cubes that the line makes once. A new part takes a cube from the pool, and a shipped part gives it back, so the belts make no garbage. When all 64 cubes ride, a new part ships at once.

Machines at work

Each SampleMachine moves by its Kind: a press stamps down, a lathe and a mill turn, a welder shakes and the other kinds breathe. The motion follows the speed, so a slow machine moves less, and a stopped machine rests at its own size and place. The machine keeps its bottom on the floor while it stamps or breathes.

Order

An ObjectiveTracker with max-quests="1". The controller adds an order with one objective for each kind of machine, such as "Press parts 4/20". The target is 10 parts for each machine of the kind, times the order number. On each refresh the controller sets the Progress of each objective to the parts of that kind shipped since the order began. A complete order fades out of the tracker, shows a success notification and a floating "Order 1 shipped!" over the middle of the line, and the next order slides in.

Machines

A read-only DataGrid over the SampleMachine components of the scene. The columns are Machine, Status, Temp C, bar and rpm. Two button columns, Details and Restart, come at the end. The controller tells them apart by the ButtonText of the column.

Temperatures

A Graph with chart-type="Line", a fixed range of 0 to 130 and axis titles. The controller adds one series for each machine. Each series shows the last 30 seconds of its machine.

Output

A PieChart of the parts made by each machine. Next to it:

Floating numbers

A FloatingTextLayer fills the screen behind the workspace, so the windows cover the numbers. On each refresh, each machine with new parts shows them as a green Heal number over the machine, such as "+2". The layer finds the point on the screen with the main camera and takes no clicks.

Alerts

A ScrollView with one line for each status change, newest first, such as "Press 1: Running to Warning, 82 C". A shipped order adds a line such as "Order 1 shipped".

Machine detail window

Each machine has one window, made from the template machine. The window title is the name of the machine. The window id is machine plus the name, so a second click shows the same window. The content has:

Notifications and docking

The workspace shows the alerts as notification bubbles. An error stays for 10 seconds. A warning or a success stays for 5. A success ("back to normal", "Order 1 shipped") has no buttons. The left and right edges are DockZone elements 420 px wide. The top and bottom zones are off.

How it is built

File Does
Factory.uxml The floating text layer, the workspace, the dock zones, the toolbar, the five windows and the machine template.
Factory.uss The red Stop button of an overheat alarm and its soft pulse.
MachineDetail.uxml The content of a machine window, bound to a SampleMachine.
FactoryController.cs Finds the machines, builds the line, refreshes the screens, fills the orders, raises the alerts and wires the buttons.
FactoryLine.cs The floor, the belts, the dock and the pool of parts that ride to the dock.
SampleMachine.cs A machine with fake sensor values, a status, a history and a motion by kind.

The theme and Samples.uss give the look. Factory.uss only makes the Stop button of an overheat alarm red. AttentionFlash pulses that button until the machine stops or cools down.

The machine template makes one window for each machine. The formats come from the data:

<tb:WindowTemplateElement
    id="machine"
    content="project://database/.../MachineDetail.uxml?..."
    title-format="{Name}"
    id-format="machine{Name}"
    width="460"
    height="440"
    category="Machines" />

A gauge binds to a property of the machine. A binding sees only the [CreateProperty] properties of SampleMachine:

<tb:Gauge
    display-mode="Needle"
    min-value="0"
    max-value="120"
    format-string="0' C'"
    animate="false"
    style="width: 130px; height: 130px;">
  <Bindings>
    <ui:DataBinding
        property="Value"
        data-source-path="Temperature"
        binding-mode="ToTarget" />
  </Bindings>
</tb:Gauge>

A timer reads the machines again twice a second. Refresh redraws the grid rows, SetData replaces the graph and chart values, and the output and the order follow:

private void tick()
{
    _grid.Refresh();
    for (var i = 0; i < _machines.Count; i++)
        _series[i].SetData(_machines[i].TemperatureHistory);
    _output.SetData(_machines, m => m.Name, m => m.PartsMade);
    showParts();
    fillOrder();
    CheckAlerts();
}

The belts move each frame. Update puts the new parts of each machine on the line and moves the line:

private void Update()
{
    if (_line == null) return;
    for (var i = 0; i < _machines.Count; i++)
        for (var made = _machines[i].PartsMade;
            _spawned[i] < made; _spawned[i]++)
            _line.Spawn(i);
    _line.Advance(Time.deltaTime);
}

An order is a quest of the tracker. Each kind of machine adds one objective with a target:

Order = _tracker.AddQuest($"Order {OrderNumber}");
_goals = new TrackedObjective[_kinds.Count];
for (var k = 0; k < _kinds.Count; k++)
    _goals[k] =
        Order.Add($"{_kinds[k]} parts",
            ORDER_PARTS * OrderNumber * _machinesOfKind[k]);

The new parts of a machine rise from the top of its cube:

var top =
    machine.transform.position + Vector3.up * (
        machine.transform.lossyScale.y / 2 + 0.2f);
_floating.Show(top, "+" + fresh, FloatingTextKind.Heal);

A small function maps a change of status to a severity. It returns null for no notification:

public static Severity? AlertFor(MachineStatus before,
    MachineStatus now) => now switch
{
    _ when now == before => null,
    MachineStatus.Alarm => Severity.Error,
    MachineStatus.Warning when before == MachineStatus.Running =>
        Severity.Warning,
    MachineStatus.Running
        when before is MachineStatus.Warning or MachineStatus.Alarm =>
            Severity.Success,
    _ => null
};

The notification is a bubble with actions:

var bubble =
    _workspace.Notifications.Show(text, severity,
        severity == Severity.Error ? 10000 : 5000);
if (severity == Severity.Success) return;
bubble.AddAction("Details", () => ShowMachine(machine));
if (severity == Severity.Error) bubble.AddAction("Stop", machine.Stop);

The arrangement needs the size of the workspace, so it waits for the first layout. It puts the Machines and Alerts windows on the left, the Temperatures and Output windows on the right and the Order window at the top in the middle, so the machines and the belts stay in view:

_workspace.schedule.Execute(arrange).StartingIn(100);

Use it in your game

See also