Skip to content

Commit d03217b

Browse files
committed
Add collection transition events
1 parent 0481da3 commit d03217b

File tree

6 files changed

+112
-1
lines changed

6 files changed

+112
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Minor UX updates and bug fixes.
1111
- More logging which shows that a scene is being currently loaded.
1212
- Methods to access in `loadingCollection` and `loadedCollection` in `ScriptableSceneController`.
1313
- Exposed `IsLoading` property in `ScriptableSceneController`.
14-
- Events in `BaseScriptableSceneTransition`.
14+
- Events which are fired when transitions are entered and exited.
1515

1616
### Changed
1717
- Updated Scene Manager Window to support reordering and to provide more info.

Runtime/Events/CollectionEventHandler.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ internal sealed class CollectionEventHandler : ICollectionEventHandler
3232
private UnityEvent<CollectionUnloadEventArgs> onUnloadExited =
3333
new UnityEvent<CollectionUnloadEventArgs>();
3434

35+
[SerializeField]
36+
private UnityEvent onShowTransitionEntered = new UnityEvent();
37+
38+
[SerializeField]
39+
private UnityEvent onShowTransitionExited = new UnityEvent();
40+
41+
[SerializeField]
42+
private UnityEvent onHideTransitionEntered = new UnityEvent();
43+
44+
[SerializeField]
45+
private UnityEvent onHideTransitionExited = new UnityEvent();
46+
3547
#endregion
3648

3749
#region Public Events
@@ -46,6 +58,14 @@ internal sealed class CollectionEventHandler : ICollectionEventHandler
4658

4759
public event CollectionUnloadEvent OnUnloadExited;
4860

61+
public event CollectionTransitionEvent OnShowTransitionEntered;
62+
63+
public event CollectionTransitionEvent OnShowTransitionExited;
64+
65+
public event CollectionTransitionEvent OnHideTransitionEntered;
66+
67+
public event CollectionTransitionEvent OnHideTransitionExited;
68+
4969
#endregion
5070

5171
#region Internal Methods
@@ -156,6 +176,59 @@ internal void RaiseUnloadExited(CollectionUnloadEventArgs args)
156176
}
157177
}
158178

179+
// TODO: these events below are not tested
180+
internal void RaiseShowTransitionEntered()
181+
{
182+
try
183+
{
184+
onShowTransitionEntered.Invoke();
185+
OnShowTransitionEntered?.Invoke();
186+
}
187+
catch (Exception exception)
188+
{
189+
Debug.LogError(exception);
190+
}
191+
}
192+
193+
internal void RaiseShowTransitionExited()
194+
{
195+
try
196+
{
197+
onShowTransitionExited.Invoke();
198+
OnShowTransitionExited?.Invoke();
199+
}
200+
catch (Exception exception)
201+
{
202+
Debug.LogError(exception);
203+
}
204+
}
205+
206+
internal void RaiseHideTransitionEntered()
207+
{
208+
try
209+
{
210+
onHideTransitionEntered.Invoke();
211+
OnHideTransitionEntered?.Invoke();
212+
}
213+
catch (Exception exception)
214+
{
215+
Debug.LogError(exception);
216+
}
217+
}
218+
219+
internal void RaiseHideTransitionExited()
220+
{
221+
try
222+
{
223+
onHideTransitionExited.Invoke();
224+
OnHideTransitionExited?.Invoke();
225+
}
226+
catch (Exception exception)
227+
{
228+
Debug.LogError(exception);
229+
}
230+
}
231+
159232
#endregion
160233
}
161234
}

Runtime/Events/CollectionEventHandlerDelegates.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@
1414
/// Invoked when <see cref="BaseScriptableSceneCollection"/> starts to unload or is unloaded.
1515
/// </summary>
1616
public delegate void CollectionUnloadEvent(CollectionUnloadEventArgs args);
17+
18+
/// <summary>
19+
/// Invoked when <see cref="BaseScriptableSceneCollection"/> starts to show or hides the
20+
/// transition.
21+
/// </summary>
22+
public delegate void CollectionTransitionEvent(); // TODO: add args
1723
}

Runtime/Events/ICollectionEventHandler.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ public interface ICollectionEventHandler
2929
/// </summary>
3030
public event CollectionUnloadEvent OnUnloadExited;
3131

32+
/// <summary>
33+
/// Called when transition of <see cref="BaseScriptableSceneCollection"/> starts to show.
34+
/// </summary>
35+
public event CollectionTransitionEvent OnShowTransitionEntered;
36+
37+
/// <summary>
38+
/// Called when transition of <see cref="BaseScriptableSceneCollection"/> is shown.
39+
/// </summary>
40+
public event CollectionTransitionEvent OnShowTransitionExited;
41+
42+
/// <summary>
43+
/// Called when transition of <see cref="BaseScriptableSceneCollection"/> starts to hide.
44+
/// </summary>
45+
public event CollectionTransitionEvent OnHideTransitionEntered;
46+
47+
/// <summary>
48+
/// Called when transition of <see cref="BaseScriptableSceneCollection"/> is hidden.
49+
/// </summary>
50+
public event CollectionTransitionEvent OnHideTransitionExited;
51+
3252
#endregion
3353
}
3454
}

Runtime/ScriptableSceneCollection.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,19 @@ public override IEnumerator ShowTransitionRoutine()
9797
{
9898
if (transition)
9999
{
100+
collectionEvents.RaiseShowTransitionEntered();
100101
yield return transition.ShowRoutine();
102+
collectionEvents.RaiseShowTransitionExited();
101103
}
102104
}
103105

104106
public override IEnumerator HideTransitionRoutine()
105107
{
106108
if (transition)
107109
{
110+
collectionEvents.RaiseHideTransitionEntered();
108111
yield return transition.HideRoutine();
112+
collectionEvents.RaiseHideTransitionExited();
109113
}
110114
}
111115

Runtime/Utilities/ScriptableSceneUtilities.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ CollectionEventHandler otherHandler
180180
handler.OnLoadProgress += otherHandler.RaiseLoadProgress;
181181
handler.OnUnloadEntered += otherHandler.RaiseUnloadEntered;
182182
handler.OnUnloadExited += otherHandler.RaiseUnloadExited;
183+
handler.OnShowTransitionEntered += otherHandler.RaiseShowTransitionEntered;
184+
handler.OnShowTransitionExited += otherHandler.RaiseShowTransitionExited;
185+
handler.OnHideTransitionEntered += otherHandler.RaiseHideTransitionEntered;
186+
handler.OnHideTransitionExited += otherHandler.RaiseHideTransitionExited;
183187
}
184188

185189
// TODO: how can we avoid this?
@@ -193,6 +197,10 @@ CollectionEventHandler otherHandler
193197
handler.OnLoadProgress -= otherHandler.RaiseLoadProgress;
194198
handler.OnUnloadEntered -= otherHandler.RaiseUnloadEntered;
195199
handler.OnUnloadExited -= otherHandler.RaiseUnloadExited;
200+
handler.OnShowTransitionEntered -= otherHandler.RaiseShowTransitionEntered;
201+
handler.OnShowTransitionExited -= otherHandler.RaiseShowTransitionExited;
202+
handler.OnHideTransitionEntered -= otherHandler.RaiseHideTransitionEntered;
203+
handler.OnHideTransitionExited -= otherHandler.RaiseHideTransitionExited;
196204
}
197205

198206
// TODO: how can we avoid this?

0 commit comments

Comments
 (0)