diff --git a/CHANGELOG.md b/CHANGELOG.md index b4cfe22..86d923b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ Minor UX updates and bug fixes. - More logging which shows that a scene is being currently loaded. - Methods to access in `loadingCollection` and `loadedCollection` in `ScriptableSceneController`. - Exposed `IsLoading` property in `ScriptableSceneController`. -- Events in `BaseScriptableSceneTransition`. +- Events which are fired when transitions are entered and exited. ### Changed - Updated Scene Manager Window to support reordering and to provide more info. diff --git a/Runtime/Events/CollectionEventHandler.cs b/Runtime/Events/CollectionEventHandler.cs index bcff8e9..e9fbc40 100644 --- a/Runtime/Events/CollectionEventHandler.cs +++ b/Runtime/Events/CollectionEventHandler.cs @@ -32,6 +32,18 @@ internal sealed class CollectionEventHandler : ICollectionEventHandler private UnityEvent onUnloadExited = new UnityEvent(); + [SerializeField] + private UnityEvent onShowTransitionEntered = new UnityEvent(); + + [SerializeField] + private UnityEvent onShowTransitionExited = new UnityEvent(); + + [SerializeField] + private UnityEvent onHideTransitionEntered = new UnityEvent(); + + [SerializeField] + private UnityEvent onHideTransitionExited = new UnityEvent(); + #endregion #region Public Events @@ -46,6 +58,14 @@ internal sealed class CollectionEventHandler : ICollectionEventHandler public event CollectionUnloadEvent OnUnloadExited; + public event CollectionTransitionEvent OnShowTransitionEntered; + + public event CollectionTransitionEvent OnShowTransitionExited; + + public event CollectionTransitionEvent OnHideTransitionEntered; + + public event CollectionTransitionEvent OnHideTransitionExited; + #endregion #region Internal Methods @@ -156,6 +176,59 @@ internal void RaiseUnloadExited(CollectionUnloadEventArgs args) } } + // TODO: these events below are not tested + internal void RaiseShowTransitionEntered() + { + try + { + onShowTransitionEntered.Invoke(); + OnShowTransitionEntered?.Invoke(); + } + catch (Exception exception) + { + Debug.LogError(exception); + } + } + + internal void RaiseShowTransitionExited() + { + try + { + onShowTransitionExited.Invoke(); + OnShowTransitionExited?.Invoke(); + } + catch (Exception exception) + { + Debug.LogError(exception); + } + } + + internal void RaiseHideTransitionEntered() + { + try + { + onHideTransitionEntered.Invoke(); + OnHideTransitionEntered?.Invoke(); + } + catch (Exception exception) + { + Debug.LogError(exception); + } + } + + internal void RaiseHideTransitionExited() + { + try + { + onHideTransitionExited.Invoke(); + OnHideTransitionExited?.Invoke(); + } + catch (Exception exception) + { + Debug.LogError(exception); + } + } + #endregion } } diff --git a/Runtime/Events/CollectionEventHandlerDelegates.cs b/Runtime/Events/CollectionEventHandlerDelegates.cs index a23922a..7258fb5 100644 --- a/Runtime/Events/CollectionEventHandlerDelegates.cs +++ b/Runtime/Events/CollectionEventHandlerDelegates.cs @@ -14,4 +14,10 @@ /// Invoked when starts to unload or is unloaded. /// public delegate void CollectionUnloadEvent(CollectionUnloadEventArgs args); + + /// + /// Invoked when starts to show or hides the + /// transition. + /// + public delegate void CollectionTransitionEvent(); // TODO: add args } diff --git a/Runtime/Events/ICollectionEventHandler.cs b/Runtime/Events/ICollectionEventHandler.cs index c234729..1d371ad 100644 --- a/Runtime/Events/ICollectionEventHandler.cs +++ b/Runtime/Events/ICollectionEventHandler.cs @@ -29,6 +29,26 @@ public interface ICollectionEventHandler /// public event CollectionUnloadEvent OnUnloadExited; + /// + /// Called when transition of starts to show. + /// + public event CollectionTransitionEvent OnShowTransitionEntered; + + /// + /// Called when transition of is shown. + /// + public event CollectionTransitionEvent OnShowTransitionExited; + + /// + /// Called when transition of starts to hide. + /// + public event CollectionTransitionEvent OnHideTransitionEntered; + + /// + /// Called when transition of is hidden. + /// + public event CollectionTransitionEvent OnHideTransitionExited; + #endregion } } diff --git a/Runtime/ScriptableSceneCollection.cs b/Runtime/ScriptableSceneCollection.cs index db5de50..c84f183 100644 --- a/Runtime/ScriptableSceneCollection.cs +++ b/Runtime/ScriptableSceneCollection.cs @@ -97,7 +97,9 @@ public override IEnumerator ShowTransitionRoutine() { if (transition) { + collectionEvents.RaiseShowTransitionEntered(); yield return transition.ShowRoutine(); + collectionEvents.RaiseShowTransitionExited(); } } @@ -105,7 +107,9 @@ public override IEnumerator HideTransitionRoutine() { if (transition) { + collectionEvents.RaiseHideTransitionEntered(); yield return transition.HideRoutine(); + collectionEvents.RaiseHideTransitionExited(); } } diff --git a/Runtime/Utilities/ScriptableSceneUtilities.cs b/Runtime/Utilities/ScriptableSceneUtilities.cs index e6ec88c..8210cca 100644 --- a/Runtime/Utilities/ScriptableSceneUtilities.cs +++ b/Runtime/Utilities/ScriptableSceneUtilities.cs @@ -180,6 +180,10 @@ CollectionEventHandler otherHandler handler.OnLoadProgress += otherHandler.RaiseLoadProgress; handler.OnUnloadEntered += otherHandler.RaiseUnloadEntered; handler.OnUnloadExited += otherHandler.RaiseUnloadExited; + handler.OnShowTransitionEntered += otherHandler.RaiseShowTransitionEntered; + handler.OnShowTransitionExited += otherHandler.RaiseShowTransitionExited; + handler.OnHideTransitionEntered += otherHandler.RaiseHideTransitionEntered; + handler.OnHideTransitionExited += otherHandler.RaiseHideTransitionExited; } // TODO: how can we avoid this? @@ -193,6 +197,10 @@ CollectionEventHandler otherHandler handler.OnLoadProgress -= otherHandler.RaiseLoadProgress; handler.OnUnloadEntered -= otherHandler.RaiseUnloadEntered; handler.OnUnloadExited -= otherHandler.RaiseUnloadExited; + handler.OnShowTransitionEntered -= otherHandler.RaiseShowTransitionEntered; + handler.OnShowTransitionExited -= otherHandler.RaiseShowTransitionExited; + handler.OnHideTransitionEntered -= otherHandler.RaiseHideTransitionEntered; + handler.OnHideTransitionExited -= otherHandler.RaiseHideTransitionExited; } // TODO: how can we avoid this?