Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute cleanup when destroy. #35

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Assets/UnityScreenNavigator/Runtime/Core/Modal/Modal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ internal void AfterExit(bool push, Modal partnerModal)
IsTransitioning = false;
TransitionAnimationType = null;
}

internal void BeforeReleaseAndForget()
{
foreach (var lifecycleEvent in _lifecycleEvents)
lifecycleEvent.Cleanup();
}

internal AsyncProcessHandle BeforeRelease()
{
Expand Down
10 changes: 6 additions & 4 deletions Assets/UnityScreenNavigator/Runtime/Core/Modal/ModalContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class ModalContainer : MonoBehaviour
private readonly Dictionary<string, AssetLoadHandle<GameObject>> _assetLoadHandles
= new Dictionary<string, AssetLoadHandle<GameObject>>();

private readonly List<ModalBackdrop> _backdrops = new List<ModalBackdrop>();
public List<ModalBackdrop> Backdrops { get; } = new List<ModalBackdrop>();

private readonly List<IModalContainerCallbackReceiver> _callbackReceivers =
new List<IModalContainerCallbackReceiver>();
Expand Down Expand Up @@ -100,6 +100,8 @@ private void OnDestroy()
var modal = _modals[modalId];
var assetLoadHandle = _assetLoadHandles[modalId];

if (UnityScreenNavigatorSettings.Instance.CallCleanupWhenDestroy)
modal.BeforeReleaseAndForget();
Destroy(modal.gameObject);
AssetLoader.Release(assetLoadHandle);
}
Expand Down Expand Up @@ -304,7 +306,7 @@ private IEnumerator PushRoutine(Type modalType, string resourceKey, bool playAni

var backdrop = Instantiate(_backdropPrefab);
backdrop.Setup((RectTransform)transform);
_backdrops.Add(backdrop);
Backdrops.Add(backdrop);

var instance = Instantiate(assetLoadHandle.Result);
if (!instance.TryGetComponent(modalType, out var c))
Expand Down Expand Up @@ -425,7 +427,7 @@ private IEnumerator PopRoutine(bool playAnimation, int popCount = 1)
var unusedModalId = _orderedModalIds[i];
unusedModalIds.Add(unusedModalId);
unusedModals.Add(_modals[unusedModalId]);
unusedBackdrops.Add(_backdrops[i]);
unusedBackdrops.Add(Backdrops[i]);
}

var enterModalIndex = _orderedModalIds.Count - popCount - 1;
Expand Down Expand Up @@ -495,7 +497,7 @@ private IEnumerator PopRoutine(bool playAnimation, int popCount = 1)

foreach (var unusedBackdrop in unusedBackdrops)
{
_backdrops.Remove(unusedBackdrop);
Backdrops.Remove(unusedBackdrop);
Destroy(unusedBackdrop.gameObject);
}

Expand Down
6 changes: 6 additions & 0 deletions Assets/UnityScreenNavigator/Runtime/Core/Page/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ internal void AfterExit(bool push, Page partnerPage)
IsTransitioning = false;
TransitionAnimationType = null;
}

internal void BeforeReleaseAndForget()
{
foreach (var lifecycleEvent in _lifecycleEvents)
lifecycleEvent.Cleanup();
}

internal AsyncProcessHandle BeforeRelease()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ private void OnDestroy()
var page = _pages[pageId];
var assetLoadHandle = _assetLoadHandles[pageId];

if (UnityScreenNavigatorSettings.Instance.CallCleanupWhenDestroy)
page.BeforeReleaseAndForget();
Destroy(page.gameObject);
AssetLoader.Release(assetLoadHandle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ internal sealed class UnityScreenNavigatorSettings : ScriptableObject

[EnabledIf(nameof(_enableInteractionInTransition), false)] [SerializeField]
private bool _controlInteractionsOfAllContainers = true;

[SerializeField] private bool _callCleanupWhenDestroy = true;

private IAssetLoader _defaultAssetLoader;
private ModalBackdrop _defaultModalBackdrop;
Expand Down Expand Up @@ -191,6 +193,12 @@ public ITransitionAnimation GetDefaultSheetTransitionAnimation(bool enter)
{
return enter ? SheetEnterAnimation : SheetExitAnimation;
}

public bool CallCleanupWhenDestroy
{
get => _callCleanupWhenDestroy;
set => _callCleanupWhenDestroy = value;
}

#if UNITY_EDITOR

Expand Down
6 changes: 3 additions & 3 deletions Assets/UnityScreenNavigator/Runtime/Core/Sheet/Sheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ internal void AfterExit(Sheet partnerSheet)
TransitionAnimationType = null;
}

internal AsyncProcessHandle BeforeRelease()
internal void BeforeReleaseAndForget()
{
// Evaluate here because users may add/remove lifecycle events within the lifecycle events.
return CoroutineManager.Instance.Run(CreateCoroutine(_lifecycleEvents.Select(x => x.Cleanup()).ToArray()));
foreach (var lifecycleEvent in _lifecycleEvents)
lifecycleEvent.Cleanup();
}

#if USN_USE_ASYNC_METHODS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ private IEnumerator HideRoutine(bool playAnimation)
public void UnregisterAll()
{
foreach (var sheet in _sheets.Values)
{
if (UnityScreenNavigatorSettings.Instance.CallCleanupWhenDestroy)
sheet.BeforeReleaseAndForget();
Destroy(sheet.gameObject);
}

foreach (var assetLoadHandle in _assetLoadHandles.Values)
AssetLoader.Release(assetLoadHandle);
Expand Down
2 changes: 1 addition & 1 deletion Assets/UnityScreenNavigator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.harumak.unityscreennavigator",
"displayName": "UnityScreenNavigator",
"version": "1.6.5",
"unity": "2019.4",
"unity": "2021.3",
"license": "MIT",
"dependencies": {
},
Expand Down
16 changes: 8 additions & 8 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"com.harumak.unityuiplayables": "https://github.com/Haruma-K/UnityUIPlayables.git?path=/Assets/UnityUIPlayables",
"com.neuecc.unirx": "https://github.com/neuecc/UniRx.git?path=Assets/Plugins/UniRx/Scripts",
"com.unity.2d.sprite": "1.0.0",
"com.unity.addressables": "1.17.17",
"com.unity.collab-proxy": "1.6.0",
"com.unity.ide.rider": "1.2.1",
"com.unity.ide.visualstudio": "2.0.9",
"com.unity.ide.vscode": "1.2.3",
"com.unity.test-framework": "1.1.27",
"com.unity.textmeshpro": "2.1.6",
"com.unity.timeline": "1.2.18",
"com.unity.addressables": "1.19.19",
"com.unity.collab-proxy": "2.0.4",
"com.unity.ide.rider": "3.0.21",
"com.unity.ide.visualstudio": "2.0.18",
"com.unity.ide.vscode": "1.2.5",
"com.unity.test-framework": "1.1.31",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.6.5",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
Expand Down
40 changes: 26 additions & 14 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "73d86259ce31ce7f4dfe1d028ea1c3edf96c23e4"
"hash": "66de0d3a58b256b6e0194f285cc530fd0c08407b"
},
"com.harumak.unityuiplayables": {
"version": "https://github.com/Haruma-K/UnityUIPlayables.git?path=/Assets/UnityUIPlayables",
Expand All @@ -15,14 +15,14 @@
"com.unity.textmeshpro": "2.0.1",
"com.unity.timeline": "1.2.14"
},
"hash": "799efe48dc0a6990e8a1d7a2372415a11fa8dfbc"
"hash": "e61ba2931c7d57926098254e61df7d51488782e6"
},
"com.neuecc.unirx": {
"version": "https://github.com/neuecc/UniRx.git?path=Assets/Plugins/UniRx/Scripts",
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "284d5c50d3f1ddd9fa7df3d382ea904732a9c2ff"
"hash": "7cce378b3f8c8943b4cac8e847bdbb8e2e1802d1"
},
"com.unity.2d.sprite": {
"version": "1.0.0",
Expand All @@ -31,11 +31,11 @@
"dependencies": {}
},
"com.unity.addressables": {
"version": "1.17.17",
"version": "1.19.19",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.scriptablebuildpipeline": "1.17.0",
"com.unity.scriptablebuildpipeline": "1.19.6",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
Expand All @@ -45,7 +45,7 @@
"url": "https://packages.unity.com"
},
"com.unity.collab-proxy": {
"version": "1.6.0",
"version": "2.0.4",
"depth": 0,
"source": "registry",
"dependencies": {},
Expand All @@ -59,16 +59,16 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.rider": {
"version": "1.2.1",
"version": "3.0.21",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.test-framework": "1.1.1"
"com.unity.ext.nunit": "1.0.6"
},
"url": "https://packages.unity.com"
},
"com.unity.ide.visualstudio": {
"version": "2.0.9",
"version": "2.0.18",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -77,21 +77,21 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.vscode": {
"version": "1.2.3",
"version": "1.2.5",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.scriptablebuildpipeline": {
"version": "1.17.0",
"version": "1.20.1",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.27",
"version": "1.1.31",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -102,7 +102,7 @@
"url": "https://packages.unity.com"
},
"com.unity.textmeshpro": {
"version": "2.1.6",
"version": "3.0.6",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -111,7 +111,7 @@
"url": "https://packages.unity.com"
},
"com.unity.timeline": {
"version": "1.2.18",
"version": "1.6.5",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down Expand Up @@ -264,6 +264,18 @@
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.uielementsnative": "1.0.0"
}
},
"com.unity.modules.uielementsnative": {
"version": "1.0.0",
"depth": 1,
"source": "builtin",
"dependencies": {
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
}
Expand Down
35 changes: 35 additions & 0 deletions ProjectSettings/MemorySettings.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!387306366 &1
MemorySettings:
m_ObjectHideFlags: 0
m_EditorMemorySettings:
m_MainAllocatorBlockSize: -1
m_ThreadAllocatorBlockSize: -1
m_MainGfxBlockSize: -1
m_ThreadGfxBlockSize: -1
m_CacheBlockSize: -1
m_TypetreeBlockSize: -1
m_ProfilerBlockSize: -1
m_ProfilerEditorBlockSize: -1
m_BucketAllocatorGranularity: -1
m_BucketAllocatorBucketsCount: -1
m_BucketAllocatorBlockSize: -1
m_BucketAllocatorBlockCount: -1
m_ProfilerBucketAllocatorGranularity: -1
m_ProfilerBucketAllocatorBucketsCount: -1
m_ProfilerBucketAllocatorBlockSize: -1
m_ProfilerBucketAllocatorBlockCount: -1
m_TempAllocatorSizeMain: -1
m_JobTempAllocatorBlockSize: -1
m_BackgroundJobTempAllocatorBlockSize: -1
m_JobTempAllocatorReducedBlockSize: -1
m_TempAllocatorSizeGIBakingWorker: -1
m_TempAllocatorSizeNavMeshWorker: -1
m_TempAllocatorSizeAudioWorker: -1
m_TempAllocatorSizeCloudWorker: -1
m_TempAllocatorSizeGfx: -1
m_TempAllocatorSizeJobWorker: -1
m_TempAllocatorSizeBackgroundWorker: -1
m_TempAllocatorSizePreloadManager: -1
m_PlatformMemorySettings: {}
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2019.4.29f1
m_EditorVersionWithRevision: 2019.4.29f1 (0eeae20b1d82)
m_EditorVersion: 2021.3.25f1
m_EditorVersionWithRevision: 2021.3.25f1 (68ef2c4f8861)
8 changes: 8 additions & 0 deletions ProjectSettings/VersionControlSettings.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!890905787 &1
VersionControlSettings:
m_ObjectHideFlags: 0
m_Mode: Visible Meta Files
m_CollabEditorSettings:
inProgressEnabled: 1
Empty file added ProjectSettings/boot.config
Empty file.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ For more information, including copyright, please refer to the following website
## Setup

#### Requirement
* Unity 2019.4 or higher
* Unity 2021.3 or higher
* uGUI (UIElements not supported)

#### Install
Expand Down
2 changes: 1 addition & 1 deletion README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ UnityのuGUIで画面遷移、画面遷移アニメーション、遷移履歴
## セットアップ

#### 要件
* Unity 2019.4 以上
* Unity 2021.3 以上
* uGUI (UIElementsには非対応)

#### インストール
Expand Down