Generalize settings panel.

This commit is contained in:
2022-11-15 12:10:34 +08:00
parent f44d9546e1
commit 8b29cd2893
3 changed files with 35 additions and 21 deletions

View File

@@ -6,11 +6,13 @@ namespace Cryville.Crtr {
public class Menu : MonoBehaviour { public class Menu : MonoBehaviour {
#pragma warning disable IDE0044 #pragma warning disable IDE0044
[SerializeField] [SerializeField]
private ResourceBrowserMaster m_browserMaster; ResourceBrowserMaster m_browserMaster;
[SerializeField] [SerializeField]
private Animator m_targetAnimator; Animator m_targetAnimator;
[SerializeField] [SerializeField]
private ProgressBar m_progressBar; ProgressBar m_progressBar;
[SerializeField]
SettingsPanel m_settingsPanel;
#pragma warning restore IDE0044 #pragma warning restore IDE0044
bool initialized = false; bool initialized = false;
@@ -19,6 +21,7 @@ namespace Cryville.Crtr {
void Awake() { void Awake() {
Game.Init(); Game.Init();
transform.parent.Find("Canvas/Contents").gameObject.SetActive(true); transform.parent.Find("Canvas/Contents").gameObject.SetActive(true);
m_settingsPanel.Target = Settings.Default;
} }
void Update() { void Update() {
if (!initialized) { if (!initialized) {

View File

@@ -7,30 +7,41 @@ using UnityEngine;
namespace Cryville.Crtr { namespace Cryville.Crtr {
public class SettingsPanel : MonoBehaviour { public class SettingsPanel : MonoBehaviour {
[SerializeField] [SerializeField]
private GameObject m_categoryPrefab; GameObject m_categoryPrefab;
private Transform _container; [SerializeField]
Transform m_container;
#pragma warning disable IDE0051 bool _invalidated = true;
void Awake() { object m_target;
_container = transform.Find("Content/__content__"); public object Target {
} get {
public void Start() { return m_target;
LoadProperties(); }
foreach (Transform c in _container) GameObject.Destroy(c.gameObject); set {
foreach (var c in _categories) { if (m_target != value) {
var obj = GameObject.Instantiate<GameObject>(m_categoryPrefab); m_target = value;
obj.transform.SetParent(_container, false); _invalidated = true;
obj.GetComponent<PropertyCategoryPanel>().Load(c.Key, c.Value, Settings.Default); }
} }
} }
#pragma warning restore IDE0051
Dictionary<string, List<PropertyInfo>> _categories = null; public void Update() {
if (!_invalidated) return;
LoadProperties();
foreach (Transform c in m_container) GameObject.Destroy(c.gameObject);
foreach (var c in _categories) {
var obj = GameObject.Instantiate<GameObject>(m_categoryPrefab, m_container, false);
obj.GetComponent<PropertyCategoryPanel>().Load(c.Key, c.Value, Target);
}
}
Dictionary<string, List<PropertyInfo>> _categories = new Dictionary<string, List<PropertyInfo>>();
public void LoadProperties() { public void LoadProperties() {
if (_categories != null) return; _categories.Clear();
_categories = new Dictionary<string, List<PropertyInfo>>(); _invalidated = false;
foreach (var p in typeof(Settings).GetProperties()) { if (Target == null) return;
foreach (var p in Target.GetType().GetProperties()) {
bool browsable = true; bool browsable = true;
string category = "miscellaneous"; string category = "miscellaneous";
foreach (var attr in p.GetCustomAttributes(true)) { foreach (var attr in p.GetCustomAttributes(true)) {

Binary file not shown.