UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Utility Systems / Codes Generator Completed

Utility Systems — UGTK

Codes Generator System

Summary

The Codes Generator System builds a random access code of configurable length and charset (numeric / alphabetic / alphanumeric), keeps it, and validates what the player types against it — firing UnityEvents on generation, match and mismatch. It is the building block for ticket codes, lobby PINs, redeem codes and "type the code you see on the other screen" flows.


Content


Modules Dependencies

None. A single MonoBehaviour with its custom inspector: no UGTK reference.


Setup

The module ships no prefab and no scene: add Mn_Code to any GameObject (Add Component ▸ Mn_Code) and configure it in the inspector:


How To Use

mnCode.GenerateCode();               // builds a new code, fires onCodeGenerated(code)
mnCode.WriteCode(inputField.text);   // stores what the player typed (no comparison yet)
mnCode.CheckCode();                  // compares -> onCodeMatch or onCodeMismatch

string current = mnCode.GetCode();   // the code in memory
mnCode.SetCharsetMode(Mn_Code.E_CodeCharsetMode.Alphanumeric);
mnCode.IncreaseCodeLength();         // +1
mnCode.DecreaseCodeLength();         // -1, never below 1

The typical wiring needs no code at all: put WriteCode on the InputField's On Value Changed, CheckCode on the confirm Button's On Click, and let onCodeMatch / onCodeMismatch drive the UI. onCodeGenerated carries the string, so it can be plugged straight into a TextMeshProUGUI.text or into the QR Generator.

The charset excludes ambiguous characters: digits are 123456789 (no 0) and letters are ABCDEFGHIJKLMNPQRSTUVWXYZ minus O. A code read aloud or off a screen can never be confused between zero and letter O — and there are no lowercase letters, so codes are shown and typed in uppercase.

Good to know:


Inspector Controls

The custom inspector adds an Editor Controls block: 🎟 Generate Code (works on the whole multi-selection, with Undo support) and 📋 Copy Code, which copies the current code to the system clipboard, plus a read-only Current Code preview that shows <none> until the first generation.


Testing Scene

This module ships no scene of its own, and does not need one: add Mn_Code to any object and its Editor Controls block works with the editor stopped.

What to do, in order:

  1. Press Generate Code a few times and watch Current Code. Look for repeats.
  2. Raise Code Length and generate again: with Numeric Only and four digits there are ten thousand possible codes, with twelve there are a thousand billion.
  3. Generate a much larger batch from the same alphabet and length.
  4. Change Charset Mode and shorten the length until collisions appear.

Step 4 is worth doing once, deliberately: the collision rate depends on alphabet size and length, and finding the threshold on purpose is far better than discovering it when two players are handed the same code.


Technical Info

Path Content
Scripts/Runtime/Mn_Code.cs The component: configuration, BuildRandomCode, stored input, validation and the three UnityEvents. Declares E_CodeCharsetMode
Scripts/Editor/Mn_CodeGenerator_Editor.cs Custom inspector: Generate / Copy buttons and the current-code preview

Mn_Code API: GenerateCode(), WriteCode(string), CheckCode(), GetCode(), SetCharsetMode(E_CodeCharsetMode), IncreaseCodeLength(), DecreaseCodeLength(). E_CodeCharsetMode: NumericOnly / AlphabeticOnly / Alphanumeric.


© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Depends on 0

  • Standalone: no other module required.

Used by 2

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