Skip to content

GameFrameX/com.gameframex.unity.mono

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Game Frame X Logo

Game Frame X Mono

GitHub release License Documentation

All-in-One Solution for Indie Game Development · Empowering Indie Developers' Dreams

Documentation · Quick Start · QQ Group

Language: English | 简体中文 | 繁體中文 | 日本語 | 한국어


Project Overview

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.

Quick Start

Installation

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:

  1. Add the following to the dependencies section in your project's manifest.json:

    {"com.gameframex.unity.mono": "https://github.com/GameFrameX/com.gameframex.unity.mono.git"}
  2. Use Git URL in Unity's Package Manager:

    https://github.com/GameFrameX/com.gameframex.unity.mono.git
    
  3. Download the repository and place it in your Unity project's Packages directory. It will be loaded automatically.

Usage

Getting the Component

var monoComponent = GameEntry.GetComponent<MonoComponent>();

Registering Lifecycle Listeners

MonoComponent allows registering callbacks for Unity's MonoBehaviour lifecycle events. All listeners can be added or removed at any time.

Update / FixedUpdate / LateUpdate

These three listeners receive two float parameters:

  • elapseSeconds — scaled delta time
  • realElapseSeconds — 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);

OnDestroy

private void OnDestroyCallback()
{
    // Called when the MonoComponent's GameObject is destroyed
}

monoComponent.AddDestroyListener(OnDestroyCallback);
monoComponent.RemoveDestroyListener(OnDestroyCallback);

OnApplicationFocus / OnApplicationPause

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
    }
}

Important Notes

  • 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 & Resources

License

This project is licensed under the MIT License. See LICENSE for details.

About

GameFrameX Mono — Unity MonoBehaviour lifecycle bridge. Exposes Update, FixedUpdate, LateUpdate, Destroy, OnApplicationPause and OnApplicationFocus events to non-MonoBehaviour systems via listener registration.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages