Skip to content

Commit 6580b32

Browse files
authored
Merge pull request Haruma-K#27 from Haruma-K/feature/override_builtin_cells
Feature that override built-in cells
2 parents 86eb268 + e544616 commit 6580b32

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Hierarchical debug menu system for Unity that makes it easy to create intuitive
3636
- [Workflow in multiple scenes](#workflow-in-multiple-scenes)
3737
- [Exclude from the release builds](#exclude-from-the-release-builds)
3838
- [Custom Cells](#custom-cells)
39+
- [Extending Built-in Cell Prefabs](#extending-built-in-cell-prefabs)
3940
- [Advanced Usage](#advanced-usage)
4041
- [Use async methods instead of coroutines](#use-async-methods-instead-of-coroutines)
4142
- [Hide Backdrop](#hide-backdrop)
@@ -456,6 +457,13 @@ Next, set this cell to **Cell Prefabs** on the **Debug Sheet**.
456457
All that remains is to add this cell to the page.
457458
Please refer to [the demo scene of the custom cells](Assets/Demo/03_CustomCells/Scenes/CustomCellsDemo.unity) for the actual implementation.
458459

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

461469
### Use async methods instead of coroutines

README_JA.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
- [最小・最大サイズの調整](#%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)
4747
- [デザインをカスタムする](#%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)
4848
- [まとめて戻る](#%E3%81%BE%E3%81%A8%E3%82%81%E3%81%A6%E6%88%BB%E3%82%8B)
49+
- [組み込みセルPrefabを拡張する](#%E7%B5%84%E3%81%BF%E8%BE%BC%E3%81%BF%E3%82%BB%E3%83%ABprefab%E3%82%92%E6%8B%A1%E5%BC%B5%E3%81%99%E3%82%8B)
4950
- [拡張パッケージ](#%E6%8B%A1%E5%BC%B5%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8)
5051
- [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)
5152
- [In-game Debug Console](#in-game-debug-console)
@@ -572,7 +573,14 @@ debugSheet.PushPage<DebugPage>(true, pageId: "MyPageId");
572573
```
573574

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

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

0 commit comments

Comments
 (0)