Skip to content

Commit

Permalink
Merge pull request #18 from Haruma-K/feature/bulk_backing
Browse files Browse the repository at this point in the history
Feature/bulk backing
  • Loading branch information
Haruma-K authored Mar 19, 2023
2 parents 96fccd5 + d45f229 commit fafab53
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private void Start()
var initialPage = DebugSheet.Instance.GetOrCreateInitialPage();
var linkButtonId = initialPage.AddPageLinkButton<CharacterViewerPage>("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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void OnDebugToolsButtonClicked()
private void OnCharacterViewerButtonClicked()
{
DebugSheet.Of(transform)
.PushPage<CharacterViewerPage>(true, onLoad: x => x.Setup(_characterSpawner, _standController));
.PushPage<CharacterViewerPage>(true, onLoad: x => x.page.Setup(_characterSpawner, _standController));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Assets/Demo/02_DefaultCells/Scripts/DefaultCellsDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ private void Start()

var initialPage = DebugSheet.Instance.GetOrCreateInitialPage();
var linkButtonId = initialPage.AddPageLinkButton<DefaultCellsDemoDebugPage>("Default Cells Demo",
onLoad: page =>
onLoad: x =>
{
var page = x.page;
_demoDebugPage = page;
page.AddLifecycleEvent(onDidPushEnter: OnDidPushEnter, onWillPopExit: OnWillPopExit);
}, priority: 0);
Expand Down
3 changes: 2 additions & 1 deletion Assets/Demo/03_CustomCells/Scripts/CustomCellsDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ private void Start()
{
var initialPage = DebugSheet.Instance.GetOrCreateInitialPage();
var pageLinkButtonId = initialPage.AddPageLinkButton<CustomCellsDemoDebugPage>("Custom Cells Demo",
onLoad: page =>
onLoad: x =>
{
var page = x.page;
page.Setup(30);
_demoDebugPage = page;
page.AddLifecycleEvent(onDidPushEnter: OnDidPushEnter, onWillPopExit: OnWillPopExit);
Expand Down
6 changes: 2 additions & 4 deletions Assets/Demo/99_Shared/Scripts/DebugTools/DebugToolsPage.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,12 +26,12 @@ public override IEnumerator Initialize()
// Graphy
AddPageLinkButton<GraphyDebugPage>("Graphy",
icon: Resources.Load<Sprite>(AssetKeys.Resources.Icon.FPS),
onLoad: x => x.Setup(GraphyManager.Instance));
onLoad: x => x.page.Setup(GraphyManager.Instance));

// In-Game Debug Console
AddPageLinkButton<IngameDebugConsoleDebugPage>("In-Game Debug Console",
icon: Resources.Load<Sprite>(AssetKeys.Resources.Icon.Console),
onLoad: x => x.Setup(DebugLogManager.Instance));
onLoad: x => x.page.Setup(DebugLogManager.Instance));

// System Info
AddPageLinkButton<SystemInfoDebugPage>("System Info",
Expand Down
69 changes: 38 additions & 31 deletions Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ 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; }
public DebugPageBase ExitingDebugPage { get; private set; }
public IReadOnlyList<Page> Pages => _pageContainer.Pages;
public IReadOnlyDictionary<string, Page> Pages => _pageContainer.Pages;
public IList<GameObject> CellPrefabs => _cellPrefabs;

public FlickToOpenMode FlickToOpen
Expand Down Expand Up @@ -138,6 +139,7 @@ private void OnDestroy()

void IPageContainerCallbackReceiver.BeforePush(Page enterPage, Page exitPage)
{
_backButton.interactable = false;
EnteringDebugPage = enterPage.GetComponent<DebugPageBase>();
ExitingDebugPage = exitPage == null ? null : exitPage.GetComponent<DebugPageBase>();
_enterTitleText.text = EnteringDebugPage.GetTitle();
Expand All @@ -156,6 +158,7 @@ void IPageContainerCallbackReceiver.AfterPush(Page enterPage, Page exitPage)

void IPageContainerCallbackReceiver.BeforePop(Page enterPage, Page exitPage)
{
_backButton.interactable = false;
EnteringDebugPage = enterPage.GetComponent<DebugPageBase>();
ExitingDebugPage = exitPage.GetComponent<DebugPageBase>();
_enterTitleText.text = EnteringDebugPage.GetTitle();
Expand Down Expand Up @@ -205,7 +208,8 @@ public static DebugSheet Of(RectTransform rectTransform, bool useCache = true)
return null;
}

public TInitialPage Initialize<TInitialPage>(string titleOverride = null, Action<TInitialPage> onLoad = null)
public TInitialPage Initialize<TInitialPage>(string titleOverride = null,
Action<(string pageId, TInitialPage page)> onLoad = null, string pageId = null)
where TInitialPage : DebugPageBase
{
if (_isInitialized)
Expand All @@ -221,85 +225,88 @@ public TInitialPage Initialize<TInitialPage>(string titleOverride = null, Action

PushPage<TInitialPage>(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;
}

/// <summary>
/// </summary>
/// <param name="titleOverride"></param>
/// <param name="onLoad"></param>
/// <returns></returns>
public TInitialPage GetOrCreateInitialPage<TInitialPage>(string titleOverride = null,
Action<TInitialPage> 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<DebugPage> onLoad = null)
public DebugPage GetOrCreateInitialPage(string titleOverride = null, string pageId = null,
Action<(string pageId, DebugPage page)> onLoad = null)
{
return GetOrCreateInitialPage<DebugPage>(titleOverride, onLoad);
return GetOrCreateInitialPage(titleOverride, onLoad, pageId);
}

public AsyncProcessHandle PushPage(Type pageType, DebugPageBase prefab, bool playAnimation,
string titleOverride = null,
Action<DebugPageBase> 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>(TPage prefab, bool playAnimation, string titleOverride = null,
Action<TPage> 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<DebugPageBase> 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<TPage>(bool playAnimation, string titleOverride = null,
Action<TPage> 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<DebugPageBase> 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;
var debugPage = (DebugPageBase)x.page;
if (titleOverride != null)
debugPage.SetTitle(titleOverride);

var prefabContainer = x.GetComponent<PrefabContainer>();
var prefabContainer = debugPage.GetComponent<PrefabContainer>();
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()
Expand Down
52 changes: 32 additions & 20 deletions Assets/UnityDebugSheet/Runtime/Core/Scripts/DefaultDebugPageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DebugPage> onLoad = null, int priority = 0)
Action<(string pageId, DebugPage page)> onLoad = null, string pageId = null, int priority = 0)
{
return AddPageLinkButton<DebugPage>(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<DebugPageBase> 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;
Expand All @@ -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<TPage>(string text, string subText = null, Color? textColor = null,
Color? subTextColor = null, Sprite icon = null, Color? iconColor = null, string titleOverride = null,
Action<TPage> 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;
Expand All @@ -273,30 +274,35 @@ public int AddPageLinkButton<TPage>(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<DebugPage> onLoad = null, int priority = 0)
string titleOverride = null, Action<(string pageId, DebugPage page)> onLoad = null, string pageId = null,
int priority = 0)
{
return AddPageLinkButton<DebugPage>(textModel, iconModel, titleOverride, onLoad, priority);
return AddPageLinkButton<DebugPage>(textModel, iconModel, titleOverride, onLoad, pageId, priority);
}

public int AddPageLinkButton(Type pageType, CellTextsModel textModel, CellIconModel iconModel = null,
string titleOverride = null, Action<DebugPageBase> 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<TPage>(CellTextsModel textModel, CellIconModel iconModel = null,
string titleOverride = null, Action<TPage> 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<DebugPageBase> 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;
Expand All @@ -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>(TPage prefab, string text, string subText = null, Color? textColor = null,
Color? subTextColor = null, Sprite icon = null, Color? iconColor = null, string titleOverride = null,
Action<TPage> 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;
Expand All @@ -321,12 +328,13 @@ public int AddPageLinkButton<TPage>(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<DebugPageBase> 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;
Expand Down Expand Up @@ -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>(TPage prefab, CellTextsModel textModel, CellIconModel iconModel = null,
string titleOverride = null, Action<TPage> 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;
Expand All @@ -386,8 +397,9 @@ public int AddPageLinkButton<TPage>(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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ void OnDidPopExit()
};
}

DebugSheet.Of(transform).PushPage<MultiPickingPage>(true, model.Text, OnLoadPickingPage);
DebugSheet.Of(transform)
.PushPage<MultiPickingPage>(true, model.Text, x => OnLoadPickingPage(x.page));
model.InvokeClicked();
}

Expand Down
Loading

0 comments on commit fafab53

Please sign in to comment.