Generalize settings panel.
This commit is contained in:
@@ -6,11 +6,13 @@ namespace Cryville.Crtr {
|
||||
public class Menu : MonoBehaviour {
|
||||
#pragma warning disable IDE0044
|
||||
[SerializeField]
|
||||
private ResourceBrowserMaster m_browserMaster;
|
||||
ResourceBrowserMaster m_browserMaster;
|
||||
[SerializeField]
|
||||
private Animator m_targetAnimator;
|
||||
Animator m_targetAnimator;
|
||||
[SerializeField]
|
||||
private ProgressBar m_progressBar;
|
||||
ProgressBar m_progressBar;
|
||||
[SerializeField]
|
||||
SettingsPanel m_settingsPanel;
|
||||
#pragma warning restore IDE0044
|
||||
|
||||
bool initialized = false;
|
||||
@@ -19,6 +21,7 @@ namespace Cryville.Crtr {
|
||||
void Awake() {
|
||||
Game.Init();
|
||||
transform.parent.Find("Canvas/Contents").gameObject.SetActive(true);
|
||||
m_settingsPanel.Target = Settings.Default;
|
||||
}
|
||||
void Update() {
|
||||
if (!initialized) {
|
||||
|
@@ -7,30 +7,41 @@ using UnityEngine;
|
||||
namespace Cryville.Crtr {
|
||||
public class SettingsPanel : MonoBehaviour {
|
||||
[SerializeField]
|
||||
private GameObject m_categoryPrefab;
|
||||
GameObject m_categoryPrefab;
|
||||
|
||||
private Transform _container;
|
||||
[SerializeField]
|
||||
Transform m_container;
|
||||
|
||||
#pragma warning disable IDE0051
|
||||
void Awake() {
|
||||
_container = transform.Find("Content/__content__");
|
||||
}
|
||||
public void Start() {
|
||||
LoadProperties();
|
||||
foreach (Transform c in _container) GameObject.Destroy(c.gameObject);
|
||||
foreach (var c in _categories) {
|
||||
var obj = GameObject.Instantiate<GameObject>(m_categoryPrefab);
|
||||
obj.transform.SetParent(_container, false);
|
||||
obj.GetComponent<PropertyCategoryPanel>().Load(c.Key, c.Value, Settings.Default);
|
||||
bool _invalidated = true;
|
||||
object m_target;
|
||||
public object Target {
|
||||
get {
|
||||
return m_target;
|
||||
}
|
||||
set {
|
||||
if (m_target != value) {
|
||||
m_target = value;
|
||||
_invalidated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#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() {
|
||||
if (_categories != null) return;
|
||||
_categories = new Dictionary<string, List<PropertyInfo>>();
|
||||
foreach (var p in typeof(Settings).GetProperties()) {
|
||||
_categories.Clear();
|
||||
_invalidated = false;
|
||||
if (Target == null) return;
|
||||
foreach (var p in Target.GetType().GetProperties()) {
|
||||
bool browsable = true;
|
||||
string category = "miscellaneous";
|
||||
foreach (var attr in p.GetCustomAttributes(true)) {
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user