Skip to content

Commit

Permalink
GITBOOK-28: change request with no subject merged in GitBook
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierarpa authored and gitbook-bot committed Oct 4, 2024
1 parent 1cea80e commit 4caeb12
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .wiki/components/monoflux.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,26 @@ public sealed class TestFlux : MonoFlux
}
```
{% endcode %}

In Case you want to keep using MonoBehaviour as inherit class you can handle it using onEnable and OnDisable

{% code fullWidth="true" %}
```csharp
using UniFlux;
public sealed class TestFlux : MonoBehaviour
{
private void OnEnable()
{
"KEY".Store(true, OnExampleMethodIsCalled)
}
private void OnDisable()
{
"KEY".Store(false, OnExampleMethodIsCalled)
}
private void OnExampleMethodIsCalled()
{
Debug.Log("Hello World");
}
}
```
{% endcode %}
43 changes: 43 additions & 0 deletions .wiki/getting-started/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,46 @@ public class Test_2 : MonoFlux
You can put both in a scene and see if they both receive the event

That's all !

Here another sample making subscriptions manually

{% code fullWidth="true" %}
```csharp
using UniFlux;
public class Test : MonoBehaviour
{
private void Start()
{
"KEY".Dispatch();
}
private void OnEnable()
{
"KEY".Store(true, OnExampleMethodIsCalled)
}
private void OnDisable()
{
"KEY".Store(false, OnExampleMethodIsCalled)
}
private void OnExampleMethodIsCalled()
{
Debug.Log("Hello World");
}
}

public class Test_2 : MonoBehaviour
{
private void OnEnable()
{
"KEY".Store(true, Tester_2)
}
private void OnDisable()
{
"KEY".Store(false, Tester_2)
}
private void Tester_2()
{
Debug.Log("Hello world 2");
}
}
```
{% endcode %}

0 comments on commit 4caeb12

Please sign in to comment.