Generalize settings panel.
This commit is contained in:
@@ -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)) {
|
||||
|
Reference in New Issue
Block a user