UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Utility Systems / Counter System Completed

Utility Systems — UGTK

Counter System

Summary

The Counter System is a runtime integer counter (Mn_Counter) with clamping, a target value and per-threshold callbacks. It exposes CurrentValue = startFrom + counter (clamped to maxValue) and fires UnityEvents on increase, decrease, target reached, and when specific thresholds are hit.


Content


Modules Dependencies


Setup

Drop the Counter prefab into the scene — a GameObject with Mn_Counter ready to configure:

Or add the component to any GameObject. Configure startFrom, targetValue and maxValue in the Inspector; optionally add threshold entries. The custom inspector adds buttons to increment/decrement/reset and shows the live runtime value.


How To Use

counter.IncrementCounter();      // +1 (clamped to maxValue)
counter.IncrementCounter(5);     // +5
counter.DecrementCounter();      // -1 (clamped to startFrom)
counter.ResetCounter();          // back to startFrom
counter.SetToMaxInstant();       // jump to maxValue
counter.SetMaxValue(20);         // change the clamp
counter.SetTargetValue(15);      // change the target
int v = counter.CurrentValue;    // read the exposed value

Wire OnIncreased(counter, currentValue), OnDecreased(counter, currentValue) and OnReachedTarget(currentValue) in the Inspector. The threshold dictionary fires its event once each time CurrentValue lands exactly on a key (re-armed when you leave that value).

Good to know:


Testing Scene

Open Debug/CounterScene.unity and press Play: use the inspector buttons to increment and decrement and watch the live value, the target event and the thresholds fire.


Technical Info

Path Content
Scripts/Runtime/Mn_Counter.cs The component: public API, clamping invariants, target/threshold event logic
Scripts/Editor/Mn_Counter_Editor.cs Custom inspector: action buttons and read-only runtime value
Prefabs/Counter.prefab GameObject with the component
Debug/CounterScene.unity Test scene

© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Depends on 1

Used by 1

Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 1 module in total.