Skip to content

GameFrameX/com.gameframex.unity.mono

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Game Frame X Logo

Game Frame X Mono

License Version Unity Version Documentation

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


Documentation · Quick Start · QQ Group: 467608841 / 233840761


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

Choose one of the following methods:

  1. 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.3"
      }
    }

    scopes controls which packages are resolved through this registry. Only packages whose names start with com.gameframex will be fetched from it.

  2. Add to manifest.json dependencies:

    {
       "com.gameframex.unity.mono": "https://github.com/gameframex/com.gameframex.unity.mono.git"
    }
  3. Use Package Manager in Unity with Git URL: https://github.com/gameframex/com.gameframex.unity.mono.git

  4. Clone the repository into your Unity project's Packages directory. It will be loaded automatically.

Usage Examples

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

Dependencies

Package Description
com.gameframex.unity.event 1.1.0

Community & Support

  • QQ Group: 467608841 / 233840761

Changelog

See Releases for changelog.

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

0 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages