From 43f522ae26baf7466bded1eb04ed83d49270cb2b Mon Sep 17 00:00:00 2001 From: Haruki Yano Date: Sat, 18 Mar 2023 22:51:41 +0900 Subject: [PATCH 1/8] add feature to pop multiple pages --- .../Runtime/Core/Scripts/DebugSheet.cs | 7 +- .../Foundation/PageNavigator/PageContainer.cs | 117 +++++++++++++----- 2 files changed, 87 insertions(+), 37 deletions(-) diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs index 6121152..1722425 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs @@ -281,16 +281,15 @@ public AsyncProcessHandle PushPage(bool playAnimation, string titleOverri } private AsyncProcessHandle PushPage(Type pageType, string prefabName, bool playAnimation, - string titleOverride = null, - Action onLoad = null) + string titleOverride = null, Action onLoad = null) { return _pageContainer.Push(pageType, prefabName, playAnimation, onLoad: x => { - var debugPage = (DebugPageBase)x; + var debugPage = (DebugPageBase)x.page; if (titleOverride != null) debugPage.SetTitle(titleOverride); - var prefabContainer = x.GetComponent(); + var prefabContainer = debugPage.GetComponent(); prefabContainer.Prefabs.AddRange(_cellPrefabs); onLoad?.Invoke(debugPage); diff --git a/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs b/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs index 5e88a89..cb417ab 100644 --- a/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs +++ b/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs @@ -1,9 +1,11 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using UnityDebugSheet.Runtime.Foundation.PageNavigator.Modules; using UnityDebugSheet.Runtime.Foundation.PageNavigator.Modules.AssetLoader; using UnityEngine; +using UnityEngine.Assertions; using UnityEngine.UI; namespace UnityDebugSheet.Runtime.Foundation.PageNavigator @@ -20,12 +22,14 @@ public sealed class PageContainer : MonoBehaviour [SerializeField] private string _name; - private readonly Dictionary> _assetLoadHandles - = new Dictionary>(); + private readonly Dictionary> _assetLoadHandles + = new Dictionary>(); private readonly List _callbackReceivers = new List(); + private readonly Dictionary _instanceIdToPageId = new Dictionary(); + private readonly List _pages = new List(); private readonly Dictionary> _preloadedResourceHandles = @@ -79,7 +83,8 @@ private void OnDestroy() { foreach (var page in _pages) { - var pageId = page.GetInstanceID(); + var pageInstanceId = page.GetInstanceID(); + var pageId = _instanceIdToPageId[pageInstanceId]; var assetLoadHandle = _assetLoadHandles[pageId]; Destroy(page.gameObject); @@ -87,6 +92,7 @@ private void OnDestroy() } _assetLoadHandles.Clear(); + _instanceIdToPageId.Clear(); InstanceCacheByName.Remove(_name); var keysToRemove = new List(); @@ -168,14 +174,15 @@ public void RemoveCallbackReceiver(IPageContainerCallbackReceiver callbackReceiv /// /// /// - /// + /// /// + /// /// - public AsyncProcessHandle Push(string resourceKey, bool playAnimation, bool stack = true, - Action onLoad = null, bool loadAsync = true) + public AsyncProcessHandle Push(string resourceKey, bool playAnimation, bool stack = true, string pageId = null, + bool loadAsync = true, Action<(string pageId, Page page)> onLoad = null) { return CoroutineManager.Instance.Run(PushRoutine(typeof(Page), resourceKey, playAnimation, stack, onLoad, - loadAsync)); + loadAsync, pageId)); } /// @@ -185,14 +192,15 @@ public AsyncProcessHandle Push(string resourceKey, bool playAnimation, bool stac /// /// /// - /// + /// /// + /// /// public AsyncProcessHandle Push(Type pageType, string resourceKey, bool playAnimation, bool stack = true, - Action onLoad = null, bool loadAsync = true) + string pageId = null, bool loadAsync = true, Action<(string pageId, Page page)> onLoad = null) { return CoroutineManager.Instance.Run(PushRoutine(pageType, resourceKey, playAnimation, stack, onLoad, - loadAsync)); + loadAsync, pageId)); } /// @@ -201,29 +209,56 @@ public AsyncProcessHandle Push(Type pageType, string resourceKey, bool playAnima /// /// /// - /// + /// /// + /// /// /// public AsyncProcessHandle Push(string resourceKey, bool playAnimation, bool stack = true, - Action onLoad = null, bool loadAsync = true) where TPage : Page + string pageId = null, bool loadAsync = true, Action<(string pageId, Page page)> onLoad = null) + where TPage : Page { return CoroutineManager.Instance.Run(PushRoutine(typeof(TPage), resourceKey, playAnimation, stack, - x => onLoad?.Invoke((TPage)x), loadAsync)); + x => onLoad?.Invoke((x.pageId, (TPage)x.page)), loadAsync, pageId)); + } + + /// + /// Push new page. + /// + /// + /// + /// + /// + public AsyncProcessHandle Pop(bool playAnimation, string destinationPageId) + { + var popCount = 0; + foreach (var id in _instanceIdToPageId.Values.Reverse()) + { + if (id == destinationPageId) + break; + + popCount++; + } + + if (popCount == _instanceIdToPageId.Count) + throw new Exception($"The page with id '{destinationPageId}' is not found."); + + return CoroutineManager.Instance.Run(PopRoutine(playAnimation, popCount)); } /// /// Pop current page. /// /// + /// /// - public AsyncProcessHandle Pop(bool playAnimation) + public AsyncProcessHandle Pop(bool playAnimation, int popCount = 1) { - return CoroutineManager.Instance.Run(PopRoutine(playAnimation)); + return CoroutineManager.Instance.Run(PopRoutine(playAnimation, popCount)); } private IEnumerator PushRoutine(Type type, string resourceKey, bool playAnimation, bool stack = true, - Action onLoad = null, bool loadAsync = true) + Action<(string pageId, Page page)> onLoad = null, bool loadAsync = true, string pageId = null) { if (resourceKey == null) throw new ArgumentNullException(nameof(resourceKey)); @@ -249,15 +284,17 @@ private IEnumerator PushRoutine(Type type, string resourceKey, bool playAnimatio page = instance.AddComponent(type); var enterPage = (Page)page; - var pageId = enterPage.GetInstanceID(); + if (pageId == null) + pageId = Guid.NewGuid().ToString(); _assetLoadHandles.Add(pageId, assetLoadHandle); - onLoad?.Invoke(enterPage); + onLoad?.Invoke((pageId, enterPage)); var afterLoadHandle = enterPage.AfterLoad((RectTransform)transform); while (!afterLoadHandle.IsTerminated) yield return null; var exitPage = _pages.Count == 0 ? null : _pages[_pages.Count - 1]; - var exitPageId = exitPage == null ? (int?)null : exitPage.GetInstanceID(); + var exitPageInstanceId = exitPage == null ? (int?)null : exitPage.GetInstanceID(); + var exitPageId = exitPageInstanceId.HasValue ? _instanceIdToPageId[exitPageInstanceId.Value] : null; // Preprocess foreach (var callbackReceiver in _callbackReceivers) @@ -285,7 +322,7 @@ private IEnumerator PushRoutine(Type type, string resourceKey, bool playAnimatio yield return coroutineHandle; // End Transition - if (!_isActivePageStacked && exitPageId.HasValue) + if (!_isActivePageStacked && exitPageId != null) _pages.RemoveAt(_pages.Count - 1); _pages.Add(enterPage); @@ -301,27 +338,30 @@ private IEnumerator PushRoutine(Type type, string resourceKey, bool playAnimatio callbackReceiver.AfterPush(enterPage, exitPage); // Unload Unused Page - if (!_isActivePageStacked && exitPageId.HasValue) + if (!_isActivePageStacked && exitPageId != null) { var beforeReleaseHandle = exitPage.BeforeRelease(); while (!beforeReleaseHandle.IsTerminated) yield return null; - var handle = _assetLoadHandles[exitPageId.Value]; + var handle = _assetLoadHandles[exitPageId]; AssetLoader.Release(handle); Destroy(exitPage.gameObject); - _assetLoadHandles.Remove(exitPageId.Value); + _assetLoadHandles.Remove(exitPageId); + _instanceIdToPageId.Remove(exitPageInstanceId.Value); } _isActivePageStacked = stack; } - private IEnumerator PopRoutine(bool playAnimation) + private IEnumerator PopRoutine(bool playAnimation, int popCount = 1) { - if (_pages.Count == 0) + Assert.IsTrue(popCount >= 1); + + if (_pages.Count < popCount) throw new InvalidOperationException( - "Cannot transition because there are no pages loaded on the stack."); + "Cannot transition because the page count is less than the pop count."); if (IsInTransition) throw new InvalidOperationException( @@ -330,8 +370,12 @@ private IEnumerator PopRoutine(bool playAnimation) IsInTransition = true; var exitPage = _pages[_pages.Count - 1]; - var exitPageId = exitPage.GetInstanceID(); - var enterPage = _pages.Count == 1 ? null : _pages[_pages.Count - 2]; + var unusedPages = new List(); + for (var i = _pages.Count - 1; i >= _pages.Count - popCount; i--) + unusedPages.Add(_pages[i]); + + var enterPageIndex = _pages.Count - popCount - 1; + var enterPage = enterPageIndex < 0 ? null : _pages[enterPageIndex]; // Preprocess foreach (var callbackReceiver in _callbackReceivers) @@ -361,7 +405,8 @@ private IEnumerator PopRoutine(bool playAnimation) yield return coroutineHandle; // End Transition - _pages.RemoveAt(_pages.Count - 1); + for (var i = 0; i < popCount; i++) + _pages.RemoveAt(_pages.Count - 1); IsInTransition = false; // Postprocess @@ -377,10 +422,16 @@ private IEnumerator PopRoutine(bool playAnimation) while (!beforeReleaseHandle.IsTerminated) yield return null; - var loadHandle = _assetLoadHandles[exitPageId]; - Destroy(exitPage.gameObject); - AssetLoader.Release(loadHandle); - _assetLoadHandles.Remove(exitPageId); + foreach (var unusedPage in unusedPages) + { + var unusedPageInstanceId = unusedPage.GetInstanceID(); + var unusedPageId = _instanceIdToPageId[unusedPageInstanceId]; + var loadHandle = _assetLoadHandles[unusedPageId]; + Destroy(unusedPage.gameObject); + AssetLoader.Release(loadHandle); + _assetLoadHandles.Remove(unusedPageId); + _instanceIdToPageId.Remove(unusedPageInstanceId); + } _isActivePageStacked = true; } From f3fd26ef5b0d72a01e02869a959711df44b5ff47 Mon Sep 17 00:00:00 2001 From: Haruki Yano Date: Sat, 18 Mar 2023 23:02:15 +0900 Subject: [PATCH 2/8] Refactor --- .../Runtime/Core/Scripts/DebugSheet.cs | 2 +- .../Foundation/PageNavigator/PageContainer.cs | 70 +++++++++++-------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs index 1722425..408d6b0 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs @@ -51,7 +51,7 @@ public sealed class DebugSheet : MonoBehaviour, IPageContainerCallbackReceiver public DebugPageBase CurrentDebugPage { get; private set; } public DebugPageBase EnteringDebugPage { get; private set; } public DebugPageBase ExitingDebugPage { get; private set; } - public IReadOnlyList Pages => _pageContainer.Pages; + public IReadOnlyDictionary Pages => _pageContainer.Pages; public IList CellPrefabs => _cellPrefabs; public FlickToOpenMode FlickToOpen diff --git a/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs b/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs index cb417ab..98bf192 100644 --- a/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs +++ b/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; using UnityDebugSheet.Runtime.Foundation.PageNavigator.Modules; using UnityDebugSheet.Runtime.Foundation.PageNavigator.Modules.AssetLoader; using UnityEngine; @@ -28,9 +27,9 @@ private readonly Dictionary> _assetLoadHandl private readonly List _callbackReceivers = new List(); - private readonly Dictionary _instanceIdToPageId = new Dictionary(); + private readonly List _orderedPageIds = new List(); - private readonly List _pages = new List(); + private readonly Dictionary _pages = new Dictionary(); private readonly Dictionary> _preloadedResourceHandles = new Dictionary>(); @@ -57,9 +56,14 @@ public IAssetLoader AssetLoader public bool IsInTransition { get; private set; } /// - /// Stacked pages. + /// List of PageIDs sorted in the order they are stacked. /// - public IReadOnlyList Pages => _pages; + public IReadOnlyList OrderedPageIds => _orderedPageIds; + + /// + /// Map of PgaeID to Page. + /// + public IReadOnlyDictionary Pages => _pages; public bool Interactable { @@ -81,10 +85,9 @@ private void Awake() private void OnDestroy() { - foreach (var page in _pages) + foreach (var pageId in _orderedPageIds) { - var pageInstanceId = page.GetInstanceID(); - var pageId = _instanceIdToPageId[pageInstanceId]; + var page = _pages[pageId]; var assetLoadHandle = _assetLoadHandles[pageId]; Destroy(page.gameObject); @@ -92,7 +95,8 @@ private void OnDestroy() } _assetLoadHandles.Clear(); - _instanceIdToPageId.Clear(); + _pages.Clear(); + _orderedPageIds.Clear(); InstanceCacheByName.Remove(_name); var keysToRemove = new List(); @@ -232,15 +236,16 @@ public AsyncProcessHandle Push(string resourceKey, bool playAnimation, bo public AsyncProcessHandle Pop(bool playAnimation, string destinationPageId) { var popCount = 0; - foreach (var id in _instanceIdToPageId.Values.Reverse()) + for (var i = _orderedPageIds.Count - 1; i >= 0; i--) { - if (id == destinationPageId) + var pageId = _orderedPageIds[i]; + if (pageId == destinationPageId) break; popCount++; } - if (popCount == _instanceIdToPageId.Count) + if (popCount == _orderedPageIds.Count) throw new Exception($"The page with id '{destinationPageId}' is not found."); return CoroutineManager.Instance.Run(PopRoutine(playAnimation, popCount)); @@ -292,9 +297,8 @@ private IEnumerator PushRoutine(Type type, string resourceKey, bool playAnimatio while (!afterLoadHandle.IsTerminated) yield return null; - var exitPage = _pages.Count == 0 ? null : _pages[_pages.Count - 1]; - var exitPageInstanceId = exitPage == null ? (int?)null : exitPage.GetInstanceID(); - var exitPageId = exitPageInstanceId.HasValue ? _instanceIdToPageId[exitPageInstanceId.Value] : null; + var exitPageId = _orderedPageIds.Count == 0 ? null : _orderedPageIds[_pages.Count - 1]; + var exitPage = exitPageId == null ? null : _pages[exitPageId]; // Preprocess foreach (var callbackReceiver in _callbackReceivers) @@ -322,10 +326,14 @@ private IEnumerator PushRoutine(Type type, string resourceKey, bool playAnimatio yield return coroutineHandle; // End Transition - if (!_isActivePageStacked && exitPageId != null) - _pages.RemoveAt(_pages.Count - 1); + if (!_isActivePageStacked && exitPage != null) + { + _pages.Remove(exitPageId); + _orderedPageIds.Remove(exitPageId); + } - _pages.Add(enterPage); + _pages.Add(pageId, enterPage); + _orderedPageIds.Add(pageId); IsInTransition = false; // Postprocess @@ -338,7 +346,7 @@ private IEnumerator PushRoutine(Type type, string resourceKey, bool playAnimatio callbackReceiver.AfterPush(enterPage, exitPage); // Unload Unused Page - if (!_isActivePageStacked && exitPageId != null) + if (!_isActivePageStacked && exitPage != null) { var beforeReleaseHandle = exitPage.BeforeRelease(); while (!beforeReleaseHandle.IsTerminated) @@ -349,7 +357,6 @@ private IEnumerator PushRoutine(Type type, string resourceKey, bool playAnimatio Destroy(exitPage.gameObject); _assetLoadHandles.Remove(exitPageId); - _instanceIdToPageId.Remove(exitPageInstanceId.Value); } _isActivePageStacked = stack; @@ -369,13 +376,15 @@ private IEnumerator PopRoutine(bool playAnimation, int popCount = 1) IsInTransition = true; - var exitPage = _pages[_pages.Count - 1]; - var unusedPages = new List(); - for (var i = _pages.Count - 1; i >= _pages.Count - popCount; i--) - unusedPages.Add(_pages[i]); + var exitPageId = _orderedPageIds[_orderedPageIds.Count - 1]; + var exitPage = _pages[exitPageId]; + var unusedPageIds = new List(); + for (var i = _orderedPageIds.Count - 1; i >= _orderedPageIds.Count - popCount; i--) + unusedPageIds.Add(_orderedPageIds[i]); - var enterPageIndex = _pages.Count - popCount - 1; - var enterPage = enterPageIndex < 0 ? null : _pages[enterPageIndex]; + var enterPageIndex = _orderedPageIds.Count - popCount - 1; + var enterPageId = enterPageIndex < 0 ? null : _orderedPageIds[enterPageIndex]; + var enterPage = enterPageId == null ? null : _pages[enterPageId]; // Preprocess foreach (var callbackReceiver in _callbackReceivers) @@ -406,7 +415,7 @@ private IEnumerator PopRoutine(bool playAnimation, int popCount = 1) // End Transition for (var i = 0; i < popCount; i++) - _pages.RemoveAt(_pages.Count - 1); + _orderedPageIds.RemoveAt(_orderedPageIds.Count - 1); IsInTransition = false; // Postprocess @@ -422,15 +431,14 @@ private IEnumerator PopRoutine(bool playAnimation, int popCount = 1) while (!beforeReleaseHandle.IsTerminated) yield return null; - foreach (var unusedPage in unusedPages) + foreach (var unusedPageId in unusedPageIds) { - var unusedPageInstanceId = unusedPage.GetInstanceID(); - var unusedPageId = _instanceIdToPageId[unusedPageInstanceId]; + var unusedPage = _pages[unusedPageId]; var loadHandle = _assetLoadHandles[unusedPageId]; Destroy(unusedPage.gameObject); AssetLoader.Release(loadHandle); _assetLoadHandles.Remove(unusedPageId); - _instanceIdToPageId.Remove(unusedPageInstanceId); + _pages.Remove(unusedPageId); } _isActivePageStacked = true; From a7aa64ab484eae366ccc5a6f51e5019a9a2afb21 Mon Sep 17 00:00:00 2001 From: Haruki Yano Date: Sat, 18 Mar 2023 23:42:49 +0900 Subject: [PATCH 3/8] fix pop --- .../Foundation/PageNavigator/PageContainer.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs b/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs index 98bf192..ce80be1 100644 --- a/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs +++ b/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs @@ -379,8 +379,13 @@ private IEnumerator PopRoutine(bool playAnimation, int popCount = 1) var exitPageId = _orderedPageIds[_orderedPageIds.Count - 1]; var exitPage = _pages[exitPageId]; var unusedPageIds = new List(); + var unusedPages = new List(); for (var i = _orderedPageIds.Count - 1; i >= _orderedPageIds.Count - popCount; i--) + { + var unusedPageId = _orderedPageIds[i]; unusedPageIds.Add(_orderedPageIds[i]); + unusedPages.Add(_pages[unusedPageId]); + } var enterPageIndex = _orderedPageIds.Count - popCount - 1; var enterPageId = enterPageIndex < 0 ? null : _orderedPageIds[enterPageIndex]; @@ -414,8 +419,13 @@ private IEnumerator PopRoutine(bool playAnimation, int popCount = 1) yield return coroutineHandle; // End Transition - for (var i = 0; i < popCount; i++) + for (var i = 0; i < unusedPageIds.Count; i++) + { + var unusedPageId = unusedPageIds[i]; + _pages.Remove(unusedPageId); _orderedPageIds.RemoveAt(_orderedPageIds.Count - 1); + } + IsInTransition = false; // Postprocess @@ -431,14 +441,14 @@ private IEnumerator PopRoutine(bool playAnimation, int popCount = 1) while (!beforeReleaseHandle.IsTerminated) yield return null; - foreach (var unusedPageId in unusedPageIds) + for (var i = 0; i < unusedPageIds.Count; i++) { - var unusedPage = _pages[unusedPageId]; + var unusedPageId = unusedPageIds[i]; + var unusedPage = unusedPages[i]; var loadHandle = _assetLoadHandles[unusedPageId]; Destroy(unusedPage.gameObject); AssetLoader.Release(loadHandle); _assetLoadHandles.Remove(unusedPageId); - _pages.Remove(unusedPageId); } _isActivePageStacked = true; From e11180bc65c4f347ba773de8788f33420484f5aa Mon Sep 17 00:00:00 2001 From: Haruki Yano Date: Sat, 18 Mar 2023 23:43:02 +0900 Subject: [PATCH 4/8] buck button interactable --- Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs index 408d6b0..c5e4ced 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs @@ -138,6 +138,7 @@ private void OnDestroy() void IPageContainerCallbackReceiver.BeforePush(Page enterPage, Page exitPage) { + _backButton.interactable = false; EnteringDebugPage = enterPage.GetComponent(); ExitingDebugPage = exitPage == null ? null : exitPage.GetComponent(); _enterTitleText.text = EnteringDebugPage.GetTitle(); @@ -156,6 +157,7 @@ void IPageContainerCallbackReceiver.AfterPush(Page enterPage, Page exitPage) void IPageContainerCallbackReceiver.BeforePop(Page enterPage, Page exitPage) { + _backButton.interactable = false; EnteringDebugPage = enterPage.GetComponent(); ExitingDebugPage = exitPage.GetComponent(); _enterTitleText.text = EnteringDebugPage.GetTitle(); From cffe6455b59cb67aa387801e1548bed27171c60b Mon Sep 17 00:00:00 2001 From: Haruki Yano Date: Sun, 19 Mar 2023 00:27:11 +0900 Subject: [PATCH 5/8] Change interfaces of the DebugSheet --- .../Runtime/Core/Scripts/DebugSheet.cs | 60 ++++++++++--------- .../Core/Scripts/DefaultDebugPageBase.cs | 52 +++++++++------- .../DefaultImpl/Cells/EnumMultiPickerCell.cs | 3 +- .../DefaultImpl/Cells/EnumPickerCell.cs | 2 +- .../DefaultImpl/Cells/MultiPickerCell.cs | 2 +- .../DefaultImpl/Cells/PageLinkButtonCell.cs | 17 +++--- .../Scripts/DefaultImpl/Cells/PickerCell.cs | 2 +- 7 files changed, 80 insertions(+), 58 deletions(-) diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs index c5e4ced..85adcf3 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs @@ -47,6 +47,7 @@ public sealed class DebugSheet : MonoBehaviour, IPageContainerCallbackReceiver public static DebugSheet Instance { get; private set; } + public string InitialPageId { get; private set; } public DebugPageBase InitialDebugPage { get; private set; } public DebugPageBase CurrentDebugPage { get; private set; } public DebugPageBase EnteringDebugPage { get; private set; } @@ -207,7 +208,8 @@ public static DebugSheet Of(RectTransform rectTransform, bool useCache = true) return null; } - public TInitialPage Initialize(string titleOverride = null, Action onLoad = null) + public TInitialPage Initialize(string titleOverride = null, + Action<(string pageId, TInitialPage page)> onLoad = null, string pageId = null) where TInitialPage : DebugPageBase { if (_isInitialized) @@ -223,69 +225,68 @@ public TInitialPage Initialize(string titleOverride = null, Action PushPage(false, titleOverride, x => { - InitialDebugPage = x; - onLoad?.Invoke(x); - }); + InitialPageId = x.pageId; + InitialDebugPage = x.page; + onLoad?.Invoke((x.pageId, x.page)); + }, pageId); _isInitialized = true; return (TInitialPage)InitialDebugPage; } - /// - /// - /// - /// - /// public TInitialPage GetOrCreateInitialPage(string titleOverride = null, - Action onLoad = null) where TInitialPage : DebugPageBase + Action<(string pageId, TInitialPage page)> onLoad = null, string pageId = null) + where TInitialPage : DebugPageBase { if (_isInitialized) return (TInitialPage)InitialDebugPage; - return Initialize(titleOverride, onLoad); + return Initialize(titleOverride, onLoad, pageId); } - public DebugPage GetOrCreateInitialPage(string titleOverride = null, Action onLoad = null) + public DebugPage GetOrCreateInitialPage(string titleOverride = null, string pageId = null, + Action<(string pageId, DebugPage page)> onLoad = null) { - return GetOrCreateInitialPage(titleOverride, onLoad); + return GetOrCreateInitialPage(titleOverride, onLoad, pageId); } public AsyncProcessHandle PushPage(Type pageType, DebugPageBase prefab, bool playAnimation, - string titleOverride = null, - Action onLoad = null) + string titleOverride = null, Action<(string pageId, DebugPageBase page)> onLoad = null, + string pageId = null) { if (!_preloadedAssetLoader.PreloadedObjects.ContainsValue(prefab.gameObject)) _preloadedAssetLoader.AddObject(prefab.gameObject); - return PushPage(pageType, prefab.gameObject.name, playAnimation, titleOverride, onLoad); + return PushPage(pageType, prefab.gameObject.name, playAnimation, titleOverride, onLoad, pageId); } public AsyncProcessHandle PushPage(TPage prefab, bool playAnimation, string titleOverride = null, - Action onLoad = null) where TPage : DebugPageBase + Action<(string pageId, TPage page)> onLoad = null, string pageId = null) where TPage : DebugPageBase { if (!_preloadedAssetLoader.PreloadedObjects.ContainsValue(prefab.gameObject)) _preloadedAssetLoader.AddObject(prefab.gameObject); return PushPage(typeof(TPage), prefab.gameObject.name, playAnimation, titleOverride, - x => onLoad?.Invoke((TPage)x)); + x => onLoad?.Invoke((pageId, (TPage)x.page)), pageId); } public AsyncProcessHandle PushPage(Type pageType, bool playAnimation, string titleOverride = null, - Action onLoad = null) + Action<(string pageId, DebugPageBase page)> onLoad = null, string pageId = null) { - return PushPage(pageType, _pagePrefab.gameObject.name, playAnimation, titleOverride, onLoad); + return PushPage(pageType, _pagePrefab.gameObject.name, playAnimation, titleOverride, onLoad, pageId); } public AsyncProcessHandle PushPage(bool playAnimation, string titleOverride = null, - Action onLoad = null) where TPage : DebugPageBase + Action<(string pageId, TPage page)> onLoad = null, string pageId = null) where TPage : DebugPageBase { return PushPage(typeof(TPage), _pagePrefab.gameObject.name, playAnimation, titleOverride, - x => onLoad?.Invoke((TPage)x)); + x => onLoad?.Invoke((x.pageId, (TPage)x.page)), pageId); } private AsyncProcessHandle PushPage(Type pageType, string prefabName, bool playAnimation, - string titleOverride = null, Action onLoad = null) + string titleOverride = null, Action<(string pageId, DebugPageBase page)> onLoad = null, + string pageId = null) { - return _pageContainer.Push(pageType, prefabName, playAnimation, onLoad: x => + return _pageContainer.Push(pageType, prefabName, playAnimation, pageId: pageId, onLoad: x => { var debugPage = (DebugPageBase)x.page; if (titleOverride != null) @@ -294,13 +295,18 @@ private AsyncProcessHandle PushPage(Type pageType, string prefabName, bool playA var prefabContainer = debugPage.GetComponent(); prefabContainer.Prefabs.AddRange(_cellPrefabs); - onLoad?.Invoke(debugPage); + onLoad?.Invoke((x.pageId, debugPage)); }, loadAsync: false); } - public AsyncProcessHandle PopPage(bool playAnimation) + public AsyncProcessHandle PopPage(bool playAnimation, int popCount = 1) + { + return _pageContainer.Pop(playAnimation, popCount); + } + + public AsyncProcessHandle PopPage(bool playAnimation, string destinationPageId) { - return _pageContainer.Pop(playAnimation); + return _pageContainer.Pop(playAnimation, destinationPageId); } public void Show() diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultDebugPageBase.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultDebugPageBase.cs index 0b99158..6c69f30 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultDebugPageBase.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultDebugPageBase.cs @@ -240,15 +240,15 @@ public int AddPickerOption(PickerOptionCellModel model, int priority = 0) public int AddPageLinkButton(string text, string subText = null, Color? textColor = null, Color? subTextColor = null, Sprite icon = null, Color? iconColor = null, string titleOverride = null, - Action onLoad = null, int priority = 0) + Action<(string pageId, DebugPage page)> onLoad = null, string pageId = null, int priority = 0) { return AddPageLinkButton(text, subText, textColor, subTextColor, icon, iconColor, - titleOverride, onLoad, priority); + titleOverride, onLoad, pageId, priority); } public int AddPageLinkButton(Type pageType, string text, string subText = null, Color? textColor = null, Color? subTextColor = null, Sprite icon = null, Color? iconColor = null, string titleOverride = null, - Action onLoad = null, int priority = 0) + Action<(string pageId, DebugPageBase page)> onLoad = null, string pageId = null, int priority = 0) { var textModel = new CellTextsModel(); textModel.Text = text; @@ -258,12 +258,13 @@ public int AddPageLinkButton(Type pageType, string text, string subText = null, var iconModel = new CellIconModel(); iconModel.Sprite = icon; if (iconColor != null) iconModel.Color = iconColor.Value; - return AddPageLinkButton(pageType, textModel, iconModel, titleOverride, onLoad, priority); + return AddPageLinkButton(pageType, textModel, iconModel, titleOverride, onLoad, pageId, priority); } public int AddPageLinkButton(string text, string subText = null, Color? textColor = null, Color? subTextColor = null, Sprite icon = null, Color? iconColor = null, string titleOverride = null, - Action onLoad = null, int priority = 0) where TPage : DebugPageBase + Action<(string pageId, TPage page)> onLoad = null, string pageId = null, int priority = 0) + where TPage : DebugPageBase { var textModel = new CellTextsModel(); textModel.Text = text; @@ -273,30 +274,35 @@ public int AddPageLinkButton(string text, string subText = null, Color? t var iconModel = new CellIconModel(); iconModel.Sprite = icon; if (iconColor != null) iconModel.Color = iconColor.Value; - return AddPageLinkButton(textModel, iconModel, titleOverride, onLoad, priority); + return AddPageLinkButton(textModel, iconModel, titleOverride, onLoad, pageId, priority); } public int AddPageLinkButton(CellTextsModel textModel, CellIconModel iconModel = null, - string titleOverride = null, Action onLoad = null, int priority = 0) + string titleOverride = null, Action<(string pageId, DebugPage page)> onLoad = null, string pageId = null, + int priority = 0) { - return AddPageLinkButton(textModel, iconModel, titleOverride, onLoad, priority); + return AddPageLinkButton(textModel, iconModel, titleOverride, onLoad, pageId, priority); } public int AddPageLinkButton(Type pageType, CellTextsModel textModel, CellIconModel iconModel = null, - string titleOverride = null, Action onLoad = null, int priority = 0) + string titleOverride = null, Action<(string pageId, DebugPageBase page)> onLoad = null, + string pageId = null, int priority = 0) { - return AddPageLinkButton(pageType, null, textModel, iconModel, titleOverride, onLoad, priority); + return AddPageLinkButton(pageType, null, textModel, iconModel, titleOverride, onLoad, pageId, priority); } public int AddPageLinkButton(CellTextsModel textModel, CellIconModel iconModel = null, - string titleOverride = null, Action onLoad = null, int priority = 0) where TPage : DebugPageBase + string titleOverride = null, Action<(string pageId, TPage page)> onLoad = null, string pageId = null, + int priority = 0) + where TPage : DebugPageBase { - return AddPageLinkButton(null, textModel, iconModel, titleOverride, onLoad, priority); + return AddPageLinkButton(null, textModel, iconModel, titleOverride, onLoad, pageId, priority); } public int AddPageLinkButton(Type pageType, DebugPageBase prefab, string text, string subText = null, Color? textColor = null, Color? subTextColor = null, Sprite icon = null, Color? iconColor = null, - string titleOverride = null, Action onLoad = null, int priority = 0) + string titleOverride = null, Action<(string pageId, DebugPageBase page)> onLoad = null, + string pageId = null, int priority = 0) { var textModel = new CellTextsModel(); textModel.Text = text; @@ -306,12 +312,13 @@ public int AddPageLinkButton(Type pageType, DebugPageBase prefab, string text, s var iconModel = new CellIconModel(); iconModel.Sprite = icon; if (iconColor != null) iconModel.Color = iconColor.Value; - return AddPageLinkButton(pageType, prefab, textModel, iconModel, titleOverride, onLoad, priority); + return AddPageLinkButton(pageType, prefab, textModel, iconModel, titleOverride, onLoad, pageId, priority); } public int AddPageLinkButton(TPage prefab, string text, string subText = null, Color? textColor = null, Color? subTextColor = null, Sprite icon = null, Color? iconColor = null, string titleOverride = null, - Action onLoad = null, int priority = 0) where TPage : DebugPageBase + Action<(string pageId, TPage page)> onLoad = null, string pageId = null, int priority = 0) + where TPage : DebugPageBase { var textModel = new CellTextsModel(); textModel.Text = text; @@ -321,12 +328,13 @@ public int AddPageLinkButton(TPage prefab, string text, string subText = var iconModel = new CellIconModel(); iconModel.Sprite = icon; if (iconColor != null) iconModel.Color = iconColor.Value; - return AddPageLinkButton(prefab, textModel, iconModel, titleOverride, onLoad, priority); + return AddPageLinkButton(prefab, textModel, iconModel, titleOverride, onLoad, pageId, priority); } public int AddPageLinkButton(Type pageType, DebugPageBase prefab, CellTextsModel textModel, - CellIconModel iconModel = null, string titleOverride = null, Action onLoad = null, - int priority = 0) + CellIconModel iconModel = null, string titleOverride = null, + Action<(string pageId, DebugPageBase page)> onLoad = null, + string pageId = null, int priority = 0) { var useSubText = textModel != null && !string.IsNullOrEmpty(textModel.SubText); var useIcon = iconModel != null && iconModel.Sprite != null; @@ -355,11 +363,14 @@ public int AddPageLinkButton(Type pageType, DebugPageBase prefab, CellTextsModel buttonModel.PageTitleOverride = titleOverride; buttonModel.OnLoad += onLoad; buttonModel.ShowArrow = true; + buttonModel.PageId = pageId; return AddPageLinkButton(buttonModel, priority); } public int AddPageLinkButton(TPage prefab, CellTextsModel textModel, CellIconModel iconModel = null, - string titleOverride = null, Action onLoad = null, int priority = 0) where TPage : DebugPageBase + string titleOverride = null, Action<(string pageId, TPage page)> onLoad = null, string pageId = null, + int priority = 0) + where TPage : DebugPageBase { var useSubText = textModel != null && !string.IsNullOrEmpty(textModel.SubText); var useIcon = iconModel != null && iconModel.Sprite != null; @@ -386,8 +397,9 @@ public int AddPageLinkButton(TPage prefab, CellTextsModel textModel, Cell buttonModel.PageType = typeof(TPage); buttonModel.Prefab = prefab; buttonModel.PageTitleOverride = titleOverride; - buttonModel.OnLoad += x => onLoad?.Invoke((TPage)x); + buttonModel.OnLoad += x => onLoad?.Invoke((x.pageId, (TPage)x.page)); buttonModel.ShowArrow = true; + buttonModel.PageId = pageId; return AddPageLinkButton(buttonModel, priority); } diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/EnumMultiPickerCell.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/EnumMultiPickerCell.cs index 78e8b9b..0ece838 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/EnumMultiPickerCell.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/EnumMultiPickerCell.cs @@ -149,7 +149,8 @@ void OnDidPopExit() }; } - DebugSheet.Of(transform).PushPage(true, model.Text, OnLoadPickingPage); + DebugSheet.Of(transform) + .PushPage(true, model.Text, x => OnLoadPickingPage(x.page)); model.InvokeClicked(); } diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/EnumPickerCell.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/EnumPickerCell.cs index 22de6eb..94e0a01 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/EnumPickerCell.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/EnumPickerCell.cs @@ -119,7 +119,7 @@ void OnDidPopExit() }; } - DebugSheet.Of(transform).PushPage(true, model.Text, OnLoadPickingPage); + DebugSheet.Of(transform).PushPage(true, model.Text, x => OnLoadPickingPage(x.page)); model.InvokeClicked(); } } diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/MultiPickerCell.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/MultiPickerCell.cs index 283ff78..da5a159 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/MultiPickerCell.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/MultiPickerCell.cs @@ -100,7 +100,7 @@ void OnDidPopExit() }; } - DebugSheet.Of(transform).PushPage(true, model.Text, OnLoadPickingPage); + DebugSheet.Of(transform).PushPage(true, model.Text, x => OnLoadPickingPage(x.page)); model.InvokeClicked(); } diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/PageLinkButtonCell.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/PageLinkButtonCell.cs index edbe544..ceb81c2 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/PageLinkButtonCell.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/PageLinkButtonCell.cs @@ -38,11 +38,12 @@ protected override void SetModel(PageLinkButtonCellModel model) button.onClick.AddListener(() => { if (model.Prefab == null) - DebugSheet.Of(transform).PushPage(pageType, true, onLoad: model.InvokeOnLoad, - titleOverride: model.PageTitleOverride); + DebugSheet.Of(transform).PushPage(pageType, true, onLoad: x => model.InvokeOnLoad(x.pageId, x.page), + titleOverride: model.PageTitleOverride, pageId: model.PageId); else - DebugSheet.Of(transform).PushPage(pageType, model.Prefab, true, onLoad: model.InvokeOnLoad, - titleOverride: model.PageTitleOverride); + DebugSheet.Of(transform).PushPage(pageType, model.Prefab, true, + onLoad: x => model.InvokeOnLoad(x.pageId, x.page), + titleOverride: model.PageTitleOverride, pageId: model.PageId); }); // Height @@ -77,11 +78,13 @@ public PageLinkButtonCellModel(bool useSubTextOrIcon) public DebugPageBase Prefab { get; set; } - public event Action OnLoad; + public event Action<(string pageId, DebugPageBase page)> OnLoad; - internal void InvokeOnLoad(DebugPageBase debugPage) + public string PageId { get; set; } + + internal void InvokeOnLoad(string pageId, DebugPageBase debugPage) { - OnLoad?.Invoke(debugPage); + OnLoad?.Invoke((pageId, debugPage)); } } } diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/PickerCell.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/PickerCell.cs index 65f77d5..7556fff 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/PickerCell.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultImpl/Cells/PickerCell.cs @@ -101,7 +101,7 @@ void OnDidPopExit() }; } - DebugSheet.Of(transform).PushPage(true, model.Text, OnLoadPickingPage); + DebugSheet.Of(transform).PushPage(true, model.Text, x => OnLoadPickingPage(x.page)); model.InvokeClicked(); } } From 9230fbd8a5d306475232ace3282e2ae0f86d33ec Mon Sep 17 00:00:00 2001 From: Haruki Yano Date: Sun, 19 Mar 2023 00:27:45 +0900 Subject: [PATCH 6/8] fix demo script --- .../Demo/01_CharacterViewer/Scripts/CharacterViewerDemo.cs | 2 +- .../Scripts/CharacterViewerDemoDebugPage.cs | 2 +- Assets/Demo/02_DefaultCells/Scripts/DefaultCellsDemo.cs | 3 ++- Assets/Demo/03_CustomCells/Scripts/CustomCellsDemo.cs | 3 ++- Assets/Demo/99_Shared/Scripts/DebugTools/DebugToolsPage.cs | 6 ++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Assets/Demo/01_CharacterViewer/Scripts/CharacterViewerDemo.cs b/Assets/Demo/01_CharacterViewer/Scripts/CharacterViewerDemo.cs index dc4a30e..018a9e7 100644 --- a/Assets/Demo/01_CharacterViewer/Scripts/CharacterViewerDemo.cs +++ b/Assets/Demo/01_CharacterViewer/Scripts/CharacterViewerDemo.cs @@ -23,7 +23,7 @@ private void Start() var initialPage = DebugSheet.Instance.GetOrCreateInitialPage(); var linkButtonId = initialPage.AddPageLinkButton("Character Viewer", icon: DemoSprites.Icon.CharacterViewer, - onLoad: page => page.Setup(_spawner, _standController), + onLoad: x => { x.page.Setup(_spawner, _standController); }, priority: 0); _itemDisposer = new PageItemDisposer(initialPage); diff --git a/Assets/Demo/01_CharacterViewer/Scripts/CharacterViewerDemoDebugPage.cs b/Assets/Demo/01_CharacterViewer/Scripts/CharacterViewerDemoDebugPage.cs index 2fd8df1..4e057fb 100644 --- a/Assets/Demo/01_CharacterViewer/Scripts/CharacterViewerDemoDebugPage.cs +++ b/Assets/Demo/01_CharacterViewer/Scripts/CharacterViewerDemoDebugPage.cs @@ -90,7 +90,7 @@ private void OnDebugToolsButtonClicked() private void OnCharacterViewerButtonClicked() { DebugSheet.Of(transform) - .PushPage(true, onLoad: x => x.Setup(_characterSpawner, _standController)); + .PushPage(true, onLoad: x => x.page.Setup(_characterSpawner, _standController)); } } } diff --git a/Assets/Demo/02_DefaultCells/Scripts/DefaultCellsDemo.cs b/Assets/Demo/02_DefaultCells/Scripts/DefaultCellsDemo.cs index b56c5bd..a696352 100644 --- a/Assets/Demo/02_DefaultCells/Scripts/DefaultCellsDemo.cs +++ b/Assets/Demo/02_DefaultCells/Scripts/DefaultCellsDemo.cs @@ -31,8 +31,9 @@ private void Start() var initialPage = DebugSheet.Instance.GetOrCreateInitialPage(); var linkButtonId = initialPage.AddPageLinkButton("Default Cells Demo", - onLoad: page => + onLoad: x => { + var page = x.page; _demoDebugPage = page; page.AddLifecycleEvent(onDidPushEnter: OnDidPushEnter, onWillPopExit: OnWillPopExit); }, priority: 0); diff --git a/Assets/Demo/03_CustomCells/Scripts/CustomCellsDemo.cs b/Assets/Demo/03_CustomCells/Scripts/CustomCellsDemo.cs index 7ad993f..c05df2c 100644 --- a/Assets/Demo/03_CustomCells/Scripts/CustomCellsDemo.cs +++ b/Assets/Demo/03_CustomCells/Scripts/CustomCellsDemo.cs @@ -22,8 +22,9 @@ private void Start() { var initialPage = DebugSheet.Instance.GetOrCreateInitialPage(); var pageLinkButtonId = initialPage.AddPageLinkButton("Custom Cells Demo", - onLoad: page => + onLoad: x => { + var page = x.page; page.Setup(30); _demoDebugPage = page; page.AddLifecycleEvent(onDidPushEnter: OnDidPushEnter, onWillPopExit: OnWillPopExit); diff --git a/Assets/Demo/99_Shared/Scripts/DebugTools/DebugToolsPage.cs b/Assets/Demo/99_Shared/Scripts/DebugTools/DebugToolsPage.cs index 9e1f8a9..cdc4d53 100644 --- a/Assets/Demo/99_Shared/Scripts/DebugTools/DebugToolsPage.cs +++ b/Assets/Demo/99_Shared/Scripts/DebugTools/DebugToolsPage.cs @@ -1,10 +1,8 @@ #if !EXCLUDE_UNITY_DEBUG_SHEET -using System; using System.Collections; using IngameDebugConsole; using Tayx.Graphy; using UnityDebugSheet.Runtime.Core.Scripts; -using UnityDebugSheet.Runtime.Core.Scripts.DefaultImpl.Cells; using UnityDebugSheet.Runtime.Extensions.Graphy; using UnityDebugSheet.Runtime.Extensions.IngameDebugConsole; using UnityDebugSheet.Runtime.Extensions.Unity; @@ -28,12 +26,12 @@ public override IEnumerator Initialize() // Graphy AddPageLinkButton("Graphy", icon: Resources.Load(AssetKeys.Resources.Icon.FPS), - onLoad: x => x.Setup(GraphyManager.Instance)); + onLoad: x => x.page.Setup(GraphyManager.Instance)); // In-Game Debug Console AddPageLinkButton("In-Game Debug Console", icon: Resources.Load(AssetKeys.Resources.Icon.Console), - onLoad: x => x.Setup(DebugLogManager.Instance)); + onLoad: x => x.page.Setup(DebugLogManager.Instance)); // System Info AddPageLinkButton("System Info", From b39c2555a81a3c072061d14006657548d0a80e75 Mon Sep 17 00:00:00 2001 From: Haruki Yano Date: Sun, 19 Mar 2023 16:46:35 +0900 Subject: [PATCH 7/8] README --- README.md | 35 +++++++++++++++++++++++++++++++++-- README_JA.md | 31 ++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dcecafc..59ae04f 100644 --- a/README.md +++ b/README.md @@ -534,6 +534,37 @@ Unity Debug Sheet consists of uGUI, so you can freely customize the look by adju The design of each cell can be freely customized by creating a custom cell. See the Custom Cells section for more information on this. +### Pop multiple screens at once +You can pop multiple pages at once. +To do this, specify the number of pages to be popped in the second argument of `DebugSheet.PopPage()`. + +```cs +DebugSheet debugSheet; +debugSheet.PopPage(true, 2); +``` + +You can also specify the destination `PageID`. +`PageID` can be obtained using the `onLoad` callback of `PushPage()` as shown below. + + +```cs +DebugSheet debugSheet; +debugSheet.PushPage(true, onLoad: x => +{ + var pageId = x.pageId; +}); +``` + +In addition, you can specify any ID by specifying the `pageId` argument of `PushPage()`. + +```cs +DebugSheet debugSheet; +debugSheet.PushPage(true, pageId: "MyPageId"); +``` + +In addition, for the pages that are skipped when popping multiple pages, the lifecycle events before and after transition will not be called, only the event before destroying will be called. +And the transition animation of the skipping pages will not be played. + ## Extension Packages ### Display the system information of Unity @@ -565,7 +596,7 @@ Usage is as follows. 1. Install [**In-game Debug Console**](https://github.com/yasirkula/UnityIngameDebugConsole). (There are several ways to install.) 2. (Only if you install 1. not via Package Manager) Add `UDS_INGAMEDEBUGCOSOLE_SUPPORT` to Scripting Define Symbols and restart Unity. 3. (Only if you use your own assembly) Add [UnityDebugSheet.IngameDebugConsole](Assets/UnityDebugSheet/Runtime/Extensions/IngameDebugConsole/UnityDebugSheet.IngameDebugConsole.asmdef) to the referenced assemblies. -4. Write as `DefaultDebugPageBase.AddPageLinkButton("In-Game Debug Console", onLoad: x => x.Setup(DebugLogManager.Instance));` to add page link cell. +4. Write as `DefaultDebugPageBase.AddPageLinkButton("In-Game Debug Console", onLoad: x => x.page.Setup(DebugLogManager.Instance));` to add page link cell. ### Graphy This is an extension package that links the **Unity Debug Sheet** with [**Graphy**](https://github.com/Tayx94/graphy) that is the OSS to display FPS, Memory, etc... @@ -579,7 +610,7 @@ Usage is as follows. 1. Install [**Graphy**](https://github.com/Tayx94/graphy). (There are several ways to install.) 2. (Only if you install 1. not via Package Manager) Add `UDS_GRAPHY_SUPPORT` to Scripting Define Symbols and restart Unity. 3. (Only if you use your own assembly) Add [UnityDebugSheet.Graphy](Assets/UnityDebugSheet/Runtime/Extensions/Graphy/UnityDebugSheet.Graphy.asmdef) to the referenced assemblies. -4. Write as `DefaultDebugPageBase.AddPageLinkButton("Graphy", onLoad: x => x.Setup(GraphyManager.Instance));` to add page link cell. +4. Write as `DefaultDebugPageBase.AddPageLinkButton("Graphy", onLoad: x => x.page.Setup(GraphyManager.Instance));` to add page link cell. ## Licenses This software is released under the MIT License. diff --git a/README_JA.md b/README_JA.md index 2404703..074e179 100644 --- a/README_JA.md +++ b/README_JA.md @@ -532,6 +532,35 @@ Unity Debug Sheet は uGUI で構成されているので、プロパティを 各セルのデザインはカスタムセルを作成することで自由に作成できます。 これについての詳細はカスタムセルの項目を参照してください。 +### まとめて戻る +複数のページをまとめて戻るには、`DebugSheet.PopPage()`の第二引数に戻る画面数を指定します。 + +```cs +DebugSheet debugSheet; +debugSheet.PopPage(true, 2); +``` + +また、戻り先の PageID を指定してまとめて戻ることもできます。 +PageID は、以下のように `PushPage()` の `onLoad` コールバックを使うことで取得できます。 + +```cs +DebugSheet debugSheet; +debugSheet.PushPage(true, onLoad: x => +{ + var pageId = x.pageId; +}); +``` + +また、`PushPage()` の `pageId` 引数を指定することで、任意の ID を指定することもできます。 + +```cs +DebugSheet debugSheet; +debugSheet.PushPage(true, pageId: "MyPageId"); +``` + +なお、まとめて戻る際にスキップされるページについては、遷移前後のライフサイクルイベントは呼ばれず、破棄前のイベントだけ呼ばれます。 +またスキップされるページの遷移アニメーションは再生されません。 + ## 拡張パッケージ Unity Debug Sheet はどんなアプリケーションでも汎用的に使う機能を拡張パッケージとして提供しています。 @@ -578,7 +607,7 @@ FPSやメモリなどの情報を表示するOSS [**Graphy**](https://github.com 1. [**Graphy**](https://github.com/Tayx94/graphy) をインストールする(複数のインストール方法があります) 2. (Package Managerを経由しない方法で1.をインストールした場合のみ)Scripting Define Symbols に `UDS_GRAPHY_SUPPORT` を追加して Unity を再起動する 3. (独自のアセンブリで使用する場合)[UnityDebugSheet.Graphy](Assets/UnityDebugSheet/Runtime/Extensions/Graphy/UnityDebugSheet.Graphy.asmdef) を参照アセンブリに加える -4. `DefaultDebugPageBase.AddPageLinkButton("Graphy", onLoad: x => x.Setup(GraphyManager.Instance));` のようにしてページへのリンクセルを追加する +4. `DefaultDebugPageBase.AddPageLinkButton("Graphy", onLoad: x => x.page.Setup(GraphyManager.Instance));` のようにしてページへのリンクセルを追加する ## ライセンス From d45f229281d8f0526f3b9089fdb524e9725c9a44 Mon Sep 17 00:00:00 2001 From: Haruma-K Date: Sun, 19 Mar 2023 07:47:05 +0000 Subject: [PATCH 8/8] chore(docs): update TOC --- README.md | 1 + README_JA.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 59ae04f..f276b0a 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Hierarchical debug menu system for Unity that makes it easy to create intuitive - [Work within the safe area](#work-within-the-safe-area) - [Change the min/max size of the debug menu](#change-the-minmax-size-of-the-debug-menu) - [Customize the look](#customize-the-look) + - [Pop multiple screens at once](#pop-multiple-screens-at-once) - [Extension Packages](#extension-packages) - [Display the system information of Unity](#display-the-system-information-of-unity) - [In-game Debug Console](#in-game-debug-console) diff --git a/README_JA.md b/README_JA.md index 074e179..902cabe 100644 --- a/README_JA.md +++ b/README_JA.md @@ -44,6 +44,7 @@ - [セーフエリア内で動作させる](#%E3%82%BB%E3%83%BC%E3%83%95%E3%82%A8%E3%83%AA%E3%82%A2%E5%86%85%E3%81%A7%E5%8B%95%E4%BD%9C%E3%81%95%E3%81%9B%E3%82%8B) - [最小・最大サイズの調整](#%E6%9C%80%E5%B0%8F%E3%83%BB%E6%9C%80%E5%A4%A7%E3%82%B5%E3%82%A4%E3%82%BA%E3%81%AE%E8%AA%BF%E6%95%B4) - [デザインをカスタムする](#%E3%83%87%E3%82%B6%E3%82%A4%E3%83%B3%E3%82%92%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%A0%E3%81%99%E3%82%8B) + - [まとめて戻る](#%E3%81%BE%E3%81%A8%E3%82%81%E3%81%A6%E6%88%BB%E3%82%8B) - [拡張パッケージ](#%E6%8B%A1%E5%BC%B5%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8) - [Unityのシステム情報を表示する](#unity%E3%81%AE%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E6%83%85%E5%A0%B1%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B) - [In-game Debug Console](#in-game-debug-console)