All-in-One Solution for Indie Game Development · Empowering Indie Developers' Dreams
Game Frame X Mono is a Mono lifecycle component for the GameFrameX framework. It manages MonoBehaviour events and update cycles in games, such as FixedUpdate, LateUpdate, OnDestroy, etc., and provides a convenient way to add and remove event listeners.
Edit your Unity project's Packages/manifest.json and add the scopedRegistries section:
{
"scopedRegistries": [
{
"name": "GameFrameX",
"url": "https://gameframex.upm.alianblank.uk",
"scopes": [
"com.gameframex"
]
}
],
"dependencies": {
"com.gameframex.unity.mono": "1.1.1"
}
}scopes controls which packages are resolved through this registry. Only packages whose names start with com.gameframex will be fetched from it.
Alternative methods:
-
Add the following to the
dependenciessection in your project'smanifest.json:{"com.gameframex.unity.mono": "https://github.com/GameFrameX/com.gameframex.unity.mono.git"} -
Use
Git URLin Unity's Package Manager:https://github.com/GameFrameX/com.gameframex.unity.mono.git -
Download the repository and place it in your Unity project's
Packagesdirectory. It will be loaded automatically.
var monoComponent = GameEntry.GetComponent<MonoComponent>();MonoComponent allows registering callbacks for Unity's MonoBehaviour lifecycle events. All listeners can be added or removed at any time.
These three listeners receive two float parameters:
elapseSeconds— scaled delta timerealElapseSeconds— unscaled delta time
private void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
// Called every frame
}
private void OnFixedUpdate(float elapseSeconds, float realElapseSeconds)
{
// Called at fixed intervals (physics)
}
private void OnLateUpdate(float elapseSeconds, float realElapseSeconds)
{
// Called after all Update calls
}
// Register
monoComponent.AddUpdateListener(OnUpdate);
monoComponent.AddFixedUpdateListener(OnFixedUpdate);
monoComponent.AddLateUpdateListener(OnLateUpdate);
// Unregister when no longer needed
monoComponent.RemoveUpdateListener(OnUpdate);
monoComponent.RemoveFixedUpdateListener(OnFixedUpdate);
monoComponent.RemoveLateUpdateListener(OnLateUpdate);private void OnDestroyCallback()
{
// Called when the MonoComponent's GameObject is destroyed
}
monoComponent.AddDestroyListener(OnDestroyCallback);
monoComponent.RemoveDestroyListener(OnDestroyCallback);These listeners receive a bool parameter and support a dual notification pattern — you can use either direct listeners or the event bus.
Direct listener approach:
private void OnApplicationFocus(bool isFocus)
{
// isFocus: true = app gained focus, false = lost focus
}
private void OnApplicationPause(bool isPause)
{
// isPause: true = app paused, false = resumed
}
monoComponent.AddOnApplicationFocusListener(OnApplicationFocus);
monoComponent.AddOnApplicationPauseListener(OnApplicationPause);
monoComponent.RemoveOnApplicationFocusListener(OnApplicationFocus);
monoComponent.RemoveOnApplicationPauseListener(OnApplicationPause);Event bus approach (via EventComponent):
var eventComponent = GameEntry.GetComponent<EventComponent>();
eventComponent.Subscribe(OnApplicationFocusChangedEventArgs.EventId, OnFocusChanged);
eventComponent.Subscribe(OnApplicationPauseChangedEventArgs.EventId, OnPauseChanged);
private void OnFocusChanged(object sender, GameEventArgs e)
{
var args = (OnApplicationFocusChangedEventArgs)e;
if (args.IsFocus)
{
// App gained focus
}
}
private void OnPauseChanged(object sender, GameEventArgs e)
{
var args = (OnApplicationPauseChangedEventArgs)e;
if (args.IsPause)
{
// App paused
}
}- Listener registration is thread-safe.
- Listeners can safely add or remove other listeners during callback invocation (snapshot dispatch).
- Exceptions in callbacks are caught and logged, and do not interrupt other listeners.
- Always unregister listeners when no longer needed to avoid memory leaks.
- Documentation: https://gameframex.doc.alianblank.com
- Repository: https://github.com/GameFrameX/com.gameframex.unity.mono
- Issues: https://github.com/GameFrameX/com.gameframex.unity.mono/issues
This project is licensed under the MIT License. See LICENSE for details.