Skip to content

Commit 61fdaa7

Browse files
committed
Feature that override built-in cells
1 parent 86eb268 commit 61fdaa7

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ private AsyncProcessHandle PushPage(Type pageType, string prefabName, bool playA
296296
debugPage.SetTitle(titleOverride);
297297

298298
var prefabContainer = debugPage.GetComponent<PrefabContainer>();
299-
prefabContainer.Prefabs.AddRange(_cellPrefabs);
299+
foreach (var cellPrefab in _cellPrefabs)
300+
prefabContainer.AddPrefab(cellPrefab);
300301

301302
onLoad?.Invoke((x.pageId, debugPage));
302303
}, loadAsync: false);
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using UnityEngine;
54

65
namespace UnityDebugSheet.Runtime.Core.Scripts
76
{
87
public sealed class PrefabContainer : MonoBehaviour
98
{
9+
// For Inspector
1010
[SerializeField] private List<GameObject> _prefabs = new List<GameObject>();
1111

12-
private readonly Dictionary<string, GameObject> _prefabNames = new Dictionary<string, GameObject>();
12+
private readonly Dictionary<string, GameObject> _nameToPrefabMap = new Dictionary<string, GameObject>();
1313

14-
public List<GameObject> Prefabs => _prefabs;
15-
16-
public GameObject GetPrefab(string prefabName)
14+
private void Awake()
1715
{
18-
if (_prefabNames.TryGetValue(prefabName, out var prefab))
19-
return prefab;
16+
foreach (var prefab in _prefabs)
17+
AddPrefab(prefab);
18+
}
2019

21-
prefab = _prefabs.FirstOrDefault(x => x.name.Equals(prefabName, StringComparison.Ordinal));
20+
public void AddPrefab(GameObject prefab)
21+
{
22+
// Add prefab to the map.
23+
// If the same name prefab is already added, it will be overwritten.
24+
_nameToPrefabMap[prefab.name] = prefab;
25+
}
2226

23-
if (prefab == null)
24-
throw new ArgumentException($"Prefab \"{prefabName}\" is not found.");
27+
public GameObject GetPrefab(string prefabName)
28+
{
29+
if (!_nameToPrefabMap.TryGetValue(prefabName, out var prefab))
30+
throw new ArgumentException($"Prefab '{prefabName}' is not found.");
2531

26-
_prefabNames.Add(prefabName, prefab);
2732
return prefab;
2833
}
2934

@@ -41,4 +46,4 @@ public bool TryGetPrefab(string prefabName, out GameObject prefab)
4146
}
4247
}
4348
}
44-
}
49+
}

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,13 @@ Next, set this cell to **Cell Prefabs** on the **Debug Sheet**.
456456
All that remains is to add this cell to the page.
457457
Please refer to [the demo scene of the custom cells](Assets/Demo/03_CustomCells/Scenes/CustomCellsDemo.unity) for the actual implementation.
458458

459+
### Extending Built-in Cell Prefabs
460+
You can extend built-in cell prefabs such as LabelCell and ButtonCell by following the steps below:
461+
462+
1. Create a Prefab Variant of the built-in Prefab and make any desired modifications.
463+
2. Ensure the name of this Prefab is the same as the original Prefab.
464+
3. Set this Prefab in the **Cell Prefabs** of the **Debug Sheet** component.
465+
459466
## Advanced Usage
460467

461468
### Use async methods instead of coroutines

README_JA.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,14 @@ debugSheet.PushPage<DebugPage>(true, pageId: "MyPageId");
572572
```
573573

574574
なお、まとめて戻る際にスキップされるページについては、遷移前後のライフサイクルイベントは呼ばれず、破棄前のイベントだけ呼ばれます。
575-
またスキップされるページの遷移アニメーションは再生されません。
575+
またスキップされるページの遷移アニメーションは再生されません。
576+
577+
### 組み込みセルPrefabを拡張する
578+
LabelCell や ButtonCell などの組み込みセルのPrefabは以下の手順で拡張することができます。
579+
580+
1. 組み込みPrefabのPrefabバリアントを作成し、任意の変更を加える
581+
2. このとき、Prefabの名前は元のPrefabと同じにする
582+
3. このPrefabを **Debug Sheet** コンポーネントの **Cell Prefabs** に設定する
576583

577584
## 拡張パッケージ
578585
Unity Debug Sheet はどんなアプリケーションでも汎用的に使う機能を拡張パッケージとして提供しています。

0 commit comments

Comments
 (0)