From 7d5ba68d8312a3ad117a0547f5f68db6db28fd1b Mon Sep 17 00:00:00 2001 From: Alexandre Coirier Date: Tue, 7 Jul 2026 22:22:22 +0200 Subject: [PATCH] feat: OctoSceneFadeEvent --- .../Scripts/Navigation/OctoSceneFade.cs | 13 ++++++ .../Scripts/Navigation/OctoSceneFadeEvent.cs | 46 +++++++++++++++++++ .../Navigation/OctoSceneFadeEvent.cs.meta | 2 + 3 files changed, 61 insertions(+) create mode 100644 Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFadeEvent.cs create mode 100644 Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFadeEvent.cs.meta diff --git a/Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFade.cs b/Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFade.cs index 451b0dee..dbdd8c80 100644 --- a/Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFade.cs +++ b/Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFade.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using UnityEngine; using UnityEngine.UI; @@ -9,12 +10,22 @@ namespace OctoCore.Navigation /// public class OctoSceneFade : MonoBehaviour { + public static OctoSceneFade Instance { get; private set; } + + public Action OnFadeIn; + public Action OnFadeOut; + private Canvas _canvas; private Image _fadeImage; private IEnumerator fadeOutCoroutine; private IEnumerator fadeInCoroutine; + private void Awake() + { + Instance = this; + } + /// /// Initialize the fade canvas and image. /// @@ -54,6 +65,7 @@ namespace OctoCore.Navigation StopCoroutine(fadeInCoroutine); StartCoroutine(fadeOutCoroutine = FadeOutCoroutine(duration, color)); + OnFadeOut?.Invoke(); } } @@ -68,6 +80,7 @@ namespace OctoCore.Navigation StopCoroutine(fadeOutCoroutine); StartCoroutine(fadeInCoroutine = FadeInCoroutine(duration)); + OnFadeIn?.Invoke(); } } diff --git a/Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFadeEvent.cs b/Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFadeEvent.cs new file mode 100644 index 00000000..09b3f778 --- /dev/null +++ b/Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFadeEvent.cs @@ -0,0 +1,46 @@ +using System.Collections; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.UI; + +namespace OctoCore.Navigation +{ + public class OctoSceneFadeEvent : MonoBehaviour + { + public UnityEvent _onFadeIn; + public UnityEvent _onFadeOut; + + void Start() + { + if (!OctoSceneFade.Instance) + { + Debug.Log($"[OctoSceneFadeEvent] No OctoSceneFade.Instance found"); + return; + } + + OctoSceneFade.Instance.OnFadeIn += OnFadeIn; + OctoSceneFade.Instance.OnFadeOut += OnFadeOut; + } + + void OnDestroy() + { + if (!OctoSceneFade.Instance) + return; + + OctoSceneFade.Instance.OnFadeIn -= OnFadeIn; + OctoSceneFade.Instance.OnFadeOut -= OnFadeOut; + } + + private void OnFadeIn() + { + Debug.Log("FadeIn"); + _onFadeIn?.Invoke(); + } + + private void OnFadeOut() + { + Debug.Log("FadeOut"); + _onFadeOut?.Invoke(); + } + } +} diff --git a/Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFadeEvent.cs.meta b/Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFadeEvent.cs.meta new file mode 100644 index 00000000..c392d3df --- /dev/null +++ b/Packages/OctoCore/Runtime/Scripts/Navigation/OctoSceneFadeEvent.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 96fe0220e4b4ae44e85d33ec8749979c