Skip to content

Commit 01d8de2

Browse files
committed
Added README
1 parent 56688ce commit 01d8de2

File tree

7 files changed

+100
-6
lines changed

7 files changed

+100
-6
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# This .gitignore file should be placed at the root of your Unity project directory
2-
#
3-
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
4-
#
1+
**.idea/
52
/[Ll]ibrary/
63
/[Tt]emp/
74
/[Oo]bj/

DocsMaterials/img.png

65.1 KB
Loading

DocsMaterials/img_1.png

68.2 KB
Loading

DocsMaterials/img_2.png

49.5 KB
Loading

DocsMaterials/img_3.png

19.1 KB
Loading

DocsMaterials/img_4.png

82.2 KB
Loading

README.md

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,99 @@
1-
# Unity-ActionUpdaterService
2-
1+
# ActionUpdaterService for Unity
2+
3+
## Overview
4+
5+
`IActionUpdaterService` is a flexible and easy-to-use service for Unity, designed to manage and dispatch update-related
6+
actions (`FixedUpdate`, `Update`, `LateUpdate`) outside of `MonoBehaviour`. It allows for a more modular approach to
7+
handling updates, especially useful in projects using dependency injection frameworks like Zenject.
8+
9+
## Features
10+
11+
- Separate update methods (`FixedUpdate`, `Update`, `LateUpdate`) outside `MonoBehaviour`.
12+
- Easy subscription and unsubscription of actions.
13+
- Pause functionality to control the execution of update actions.
14+
- Automatic cleanup to prevent memory leaks.
15+
16+
## Getting Started
17+
18+
### Installation
19+
20+
1. Import the `IActionUpdaterService` package into your Unity project.
21+
2. Add `ActionUpdaterService` and `ActionUpdateDispatcher` scripts to your project.
22+
23+
### Zenject Binding
24+
25+
Bind the `IActionUpdaterService` in your Zenject installer like this:
26+
27+
```csharp
28+
public sealed class ServicesInstaller : MonoInstaller
29+
{
30+
public override void InstallBindings()
31+
{
32+
Container.Bind<IActionUpdaterService>().To<ActionUpdaterService>().AsSingle();
33+
}
34+
}
35+
```
36+
Don't forget to add to the ProjectContext:
37+
38+
![DocsMaterials/img.png](DocsMaterials/img.png)
39+
![DocsMaterials/img_1.png](DocsMaterials/img_1.png)
40+
41+
# Dispatcher
42+
Add the `ActionUpdateDispatcher` class to the ProjectContext prefab, Bootstrupper or any other object that will be the only one in the game.
43+
44+
![img_2.png](DocsMaterials/img_2.png)
45+
46+
# Usage
47+
48+
Inject IActionUpdaterService into your classes and subscribe to the desired update methods:
49+
50+
```csharp
51+
public sealed class YourClass
52+
{
53+
private IActionUpdaterService actionUpdater;
54+
55+
[Inject]
56+
private void Constructor(IActionUpdaterService actionUpdater) =>
57+
this.actionUpdater = actionUpdater;
58+
59+
public void SomeMethod()
60+
{
61+
actionUpdater.Subscribe(MyUpdateMethod, UpdateType.Update);
62+
}
63+
64+
private void MyUpdateMethod()
65+
{
66+
// Your update logic here
67+
}
68+
}
69+
```
70+
71+
Remember to unsubscribe from the service to prevent memory leaks:
72+
73+
```csharp
74+
public void OnDestroy()
75+
{
76+
actionUpdater.Unsubscribe(MyUpdateMethod, UpdateType.Update);
77+
}
78+
```
79+
80+
# Pausing Updates
81+
82+
You can pause and resume the execution of update methods:
83+
84+
```csharp
85+
actionUpdater.SetPause(true); // Pauses updates
86+
actionUpdater.SetPause(false); // Resumes updates
87+
```
88+
89+
# Example
90+
![DocsMaterials/img_4.png](DocsMaterials/img_4.png)
91+
![DocsMaterials/img_3.png](DocsMaterials/img_3.png)
92+
93+
# License
94+
95+
This project is licensed under the MIT License - see the LICENSE file for details.
96+
97+
## Credits
98+
99+
Developed by RimuruDev.

0 commit comments

Comments
 (0)