A lightweight, engine-agnostic C# foundation for reliable gameplay systems.
Built for clarity, determinism, and extensibility, with optional Unity/Burst layers for performance and debugging.
- 🤖 PRNG Utilities
- ⚡ Global EventX
- 🧠 StateMachine System
- 🧠 Utility AI System
- 🎮 Actor–Controller Architecture
- 📐 Geometry & Math Utilities
- 📦 Installation
- 🗺️ Roadmap
- 📄 License
Deterministic pseudorandom generators for reproducible gameplay, procedural generation, and testing.
Pseudorandom Number Generator (PRNG) Readme
Why Not to Use UnityEngine.Random Readme
- XorShift128Plus — fast, high-quality PRNG
- SplitMix64 — robust seeding algorithm for initializing PRNG states
- PCG32 — statistically sound PRNG with excellent distribution properties
A zero-allocation, thread-safe, strongly-typed event system for com.xfg.corelib. Designed for high-performance, engine-agnostic gameplay code without reflection, params object[], DynamicInvoke, or per-broadcast allocations.
- Supports any KeyType (string, enum, struct, EventId, etc.)
- Strongly-typed delegates (Action, Action, Action<T1,T2>, Action<T1,T2,T3>, Action<T1,T2,T3,T4>)
- Zero allocations during broadcast
- Thread-safe via ConcurrentDictionary
- Up to 4 parameters per event
- Engine-agnostic C# core with optional Unity integration
A flexible, engine-agnostic framework for gameplay, AI, UI flow, and asynchronous logic, with optional Unity Inspector serialization for debugging and authoring.
- StateMachine — simple, predictable synchronous FSM
- AsyncStateMachine — async/await support for loading, networking, cutscenes
- HFSM (Hierarchical FSM) — parent/child states for layered behaviors
- Pushdown FSM — stack-based states with PushState(), PopState(), ReplaceState()
- Unity Inspector Serialization — FSMs and states can be serialized and visualized in the Unity Editor
- Explicit Enter/Exit — clean lifecycle boundaries
- Strong typing — explicit, testable state classes
- FSMs implement ISerializableStateMachine for Unity-friendly serialization
- States implement ISerializableState to expose internal data in the Inspector
- Supports serialization of:
- Active state
- HFSM hierarchy
- Pushdown stack contents
- State-specific fields
- Enables:
- Inspector debugging
- Authoring workflows
- Live state visualization
- Editor tooling and extensions
This system is designed for Unity workflows but remains engine-agnostic at its core.
- Nested states with shared parent logic
- Automatic Enter/Exit bubbling
- Ideal for AI, combat, UI, and multi-layered systems
- PushState() — push a new state on the stack
- PopState() — pop and resume the previous state
- ReplaceState() — atomic replace without resuming underlying state
- Perfect for menus, modal UI, pause screens, nested gameplay modes
A modular, designer-friendly Utility AI framework built for scalable decision-making in gameplay and AI systems.
- Action-based architecture — each action defines its own scoring logic
- Weighted scoring — combine multiple considerations into a final utility value
- Considerations — reusable scoring components (curves, clamps, multipliers, timers)
- Temporal control — cooldowns, score decay, and gating logic
- Deterministic evaluation — stable, predictable decision outcomes
- Engine-agnostic core — pure C# logic with optional Unity Inspector integration
- Fully serializable actions, considerations, and AI agents
- Designer-friendly inspector layout for tuning and debugging
- Optional live score visualization
- Supports nested consideration graphs
- Scalable for large AI systems
- Easy to author and debug
- Predictable and deterministic
- Extensible for custom scoring logic
A deterministic, engine-agnostic gameplay pattern built around a clear separation of responsibilities: Controllers decide what should happen, and Actors execute those decisions through a strongly-typed state machine and command buffer.
Inspired by Unreal Engine’s Actor–Controller model, adapted for explicit, portable C# workflows.
-
Actor
- Owns the FSM and executes commands deterministically
- Uses a command buffer to prevent mid-frame state changes
- Sends Inform() messages back to the Controller
- Defines behavior through polymorphic state classes
-
Controller
- Decides what the Actor should do
- Issues typed commands (no direct state mutation)
- Reacts to Actor feedback via Inform()
- Can be swapped at runtime
Supported Controller Types
- Player Input Controller
- Behavior Tree (B3) Controller
- Utility AI Controller
- FSM-driven AI Controller
- Network/Remote Controller
- Scripted/Cutscene Controller
- Replay/Deterministic Playback Controller
-
Command Buffer
- FIFO buffer ensuring deterministic behavior
- Prevents unpredictable mid-frame transitions
- Works consistently across AI, player, and network input
- Deterministic and testable gameplay
- Clean separation of decision vs execution
- Scales to AI, networking, cutscenes, and tools
- Familiar to Unreal developers but simpler and engine-agnostic
A clean, engine-agnostic geometry layer providing collision-ready primitives and spatial reasoning tools.
- Line
- Ray
- Line Segment
- Triangle
- AABB
- OBB
- Frustum
- Cone
- Cylinder
- Capsule
- Sphere
Design Philosophy:
Pure C# core → optional Unity/Burst layers → optional debug layer.
Modular, deterministic, and future-proof for higher-level collision systems.
- BoundingSphereBurst — SIMD-friendly, Unity.Mathematics-based version for high-throughput jobs
- ShapeDebug — optional Unity-only visualization layer (editor-only, zero-cost in builds)
Install via Unity Package Manager using Git URL:
https://github.com/vidextreme/com.xfg.corelib.git
Or clone the repository directly into your project’s Packages/ folder.
Planned additions include:
- PRNG
- Additional PRNG algorithms (Xoshiro256**, Xoshiro128++, Mersenne Twister, PCG64)
- Collision
- Expanded collision/intersection tests (Ray–Triangle, Capsule–Capsule, SAT)
- Additional Burst-optimized variants
- Systems
- Templated Global Event System
- Action System
- UI Manager
- Game Mode System
- Math
- Curve
- Statistics
- A*
- Extensions
- Unity types extensions (Component, Transform, etc.)
This project is released under the MIT License.
John David Uy (https://www.linkedin.com/in/johndaviduy/ >> Connect with me!)

