Skip to content

Commit

Permalink
Fix transition events not being fired
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvinas01 committed Sep 28, 2022
1 parent d03217b commit 3373f69
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 26 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.3] - 2022-09-28

### Fixed
- Fixed transition events not being invoked.

## [0.0.2] - 2022-09-28
Minor UX updates and bug fixes.

Expand Down
44 changes: 27 additions & 17 deletions Runtime/ScriptableSceneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,35 +193,45 @@ private IEnumerator LoadSceneCollectionInternalRoutine(
BaseScriptableSceneCollection collection
)
{
yield return collection.ShowTransitionRoutine();
if (loadedCollection != false)
// TODO: reduce nesting
try
{
collection.CollectionEvents.AddTransitionListeners(collectionEvents);
yield return collection.ShowTransitionRoutine();

if (loadedCollection != false)
{
try
{
loadedCollection.CollectionEvents.AddListeners(collectionEvents);
loadedCollection.SceneEvents.AddListeners(sceneEvents);
yield return loadedCollection.UnloadRoutine();
}
finally
{
loadedCollection.CollectionEvents.RemoveListeners(collectionEvents);
loadedCollection.SceneEvents.RemoveListeners(sceneEvents);
}
}

try
{
loadedCollection.CollectionEvents.AddListeners(collectionEvents);
loadedCollection.SceneEvents.AddListeners(sceneEvents);
yield return loadedCollection.UnloadRoutine();
collection.CollectionEvents.AddListeners(collectionEvents);
collection.SceneEvents.AddListeners(sceneEvents);
yield return collection.LoadRoutine();
}
finally
{
loadedCollection.CollectionEvents.RemoveListeners(collectionEvents);
loadedCollection.SceneEvents.RemoveListeners(sceneEvents);
collection.CollectionEvents.RemoveListeners(collectionEvents);
collection.SceneEvents.RemoveListeners(sceneEvents);
}
}

try
{
collection.CollectionEvents.AddListeners(collectionEvents);
collection.SceneEvents.AddListeners(sceneEvents);
yield return collection.LoadRoutine();
yield return collection.HideTransitionRoutine();
}
finally
{
collection.CollectionEvents.RemoveListeners(collectionEvents);
collection.SceneEvents.RemoveListeners(sceneEvents);
collection.CollectionEvents.RemoveTransitionListeners(collectionEvents);
}

yield return collection.HideTransitionRoutine();
}

#endregion
Expand Down
32 changes: 24 additions & 8 deletions Runtime/Utilities/ScriptableSceneUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,30 @@ internal static bool TryGetLoadedScene(BaseScriptableScene scriptableScene, out
return false;
}

// TODO: how can we avoid this?
internal static void AddTransitionListeners(
this ICollectionEventHandler handler,
CollectionEventHandler otherHandler
)
{
handler.OnShowTransitionEntered += otherHandler.RaiseShowTransitionEntered;
handler.OnShowTransitionExited += otherHandler.RaiseShowTransitionExited;
handler.OnHideTransitionEntered += otherHandler.RaiseHideTransitionEntered;
handler.OnHideTransitionExited += otherHandler.RaiseHideTransitionExited;
}

// TODO: how can we avoid this?
internal static void RemoveTransitionListeners(
this ICollectionEventHandler handler,
CollectionEventHandler otherHandler
)
{
handler.OnShowTransitionEntered -= otherHandler.RaiseShowTransitionEntered;
handler.OnShowTransitionExited -= otherHandler.RaiseShowTransitionExited;
handler.OnHideTransitionEntered -= otherHandler.RaiseHideTransitionEntered;
handler.OnHideTransitionExited -= otherHandler.RaiseHideTransitionExited;
}

// TODO: how can we avoid this?
internal static void AddListeners(
this ICollectionEventHandler handler,
Expand All @@ -180,10 +204,6 @@ 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?
Expand All @@ -197,10 +217,6 @@ 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?
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "CHARK",
"url": "https://chark.io"
},
"version": "0.0.2",
"version": "0.0.3",
"unity": "2020.3",
"description": "Simple scene loading and management system for Unity Engine, implemented via scriptable objects.",
"keywords": [
Expand Down

0 comments on commit 3373f69

Please sign in to comment.