From 4caeb12ddd8e0608bb65cb6200e557f143939c28 Mon Sep 17 00:00:00 2001 From: Xavier Arpa Date: Fri, 4 Oct 2024 08:19:27 +0000 Subject: [PATCH] GITBOOK-28: change request with no subject merged in GitBook --- .wiki/components/monoflux.md | 23 ++++++++++++++++++ .wiki/getting-started/setup.md | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/.wiki/components/monoflux.md b/.wiki/components/monoflux.md index a439b2a..95ce0da 100644 --- a/.wiki/components/monoflux.md +++ b/.wiki/components/monoflux.md @@ -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 %} diff --git a/.wiki/getting-started/setup.md b/.wiki/getting-started/setup.md index cea65a8..4af5682 100644 --- a/.wiki/getting-started/setup.md +++ b/.wiki/getting-started/setup.md @@ -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 %}