An open API service indexing awesome lists of open source software.

https://github.com/bcoffeedev/game-core-architecture-modular-singleton

A lightweight modular initialization framework for Unity.
https://github.com/bcoffeedev/game-core-architecture-modular-singleton

design-patterns framework modular singleton unity unity-package

Last synced: 10 months ago
JSON representation

A lightweight modular initialization framework for Unity.

Awesome Lists containing this project

README

          

# ๐Ÿงฑ Modular Singleton Architecture for Unity

A lightweight and extensible modular architecture framework for Unity projects.
This package provides a centralized `BaseContainer` system that manages the lifecycle of self-contained modules derived from `BaseModule`.

## โœจ Features

- ๐Ÿงฉ **Modular Design** โ€“ Create independent components by inheriting from `BaseModule`.
- ๐Ÿ“ฆ **Centralized Access** โ€“ Retrieve modules via `BaseContainer.Instance.GetModule()`.
- ๐Ÿ” **Lifecycle Control** โ€“ Built-in initialization flow with callback registration.
- ๐ŸŒ **Cross-Scene Support** โ€“ Optional `DontDestroyOnLoad` singleton pattern.
- ๐Ÿ” **Type-Safe Access** โ€“ Generic module resolution without casting.

## ๐Ÿ“ฆ Installation

To install this package in your Unity project using the Unity Package Manager:

1. Open your Unity project.
2. Go to `Window > Package Manager`.
3. Click the `+` button in the top-left corner and select `Add package from Git URL...`
4. Paste the following URL and click `Add`:

```
https://github.com/BcoffeeDev/game-core-architecture-modular-singleton.git
```

Alternatively, you can add it directly to your `manifest.json`:

```json
"dependencies": {
"com.bcoffee-dev.architecture.modular.singleton": "https://github.com/BcoffeeDev/game-core-architecture-modular-singleton.git"
}
```

## ๐Ÿš€ Getting Started

1. Create a container by inheriting from `BaseContainer`, and add it to your scene:
```csharp
public class MyGameContainer : BaseContainer { }
```
2. Implement your own modules by inheriting from `BaseModule`, and add them to the `modules` list in your container (either via the Inspector).
3. Access modules in code:
```csharp
var myModule = MyGameContainer.Instance.GetModule();
myModule.DoSomething();
```
4. Optionally, register a callback to wait for module initialization:
```csharp
MyGameContainer.RegisterInitializeCallback(() => {
Debug.Log("All modules initialized!");
});
```

## ๐Ÿงช Use Case

Perfect for:
- Small to mid-sized Unity games or apps
- Prototyping tools or internal systems
- Projects needing clean and maintainable module organization

## ๐Ÿ“œ License

MIT License ยฉ 2025 [bcoffee](https://github.com/bcoffee0630)