using Cryville.Crtr.Browsing; using System.Collections.Generic; using System.ComponentModel; using System.Reflection; using UnityEngine; namespace Cryville.Crtr { public class SettingsPanel : MonoBehaviour { [SerializeField] private GameObject m_categoryPrefab; private Transform _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(m_categoryPrefab); obj.transform.SetParent(_container, false); obj.GetComponent().Load(c.Key, c.Value, Settings.Default); } } #pragma warning restore IDE0051 Dictionary> _categories = null; public void LoadProperties() { if (_categories != null) return; _categories = new Dictionary>(); foreach (var p in typeof(Settings).GetProperties()) { bool browsable = true; string category = "miscellaneous"; foreach (var attr in p.GetCustomAttributes(true)) { if (attr is BrowsableAttribute) { browsable = ((BrowsableAttribute)attr).Browsable; if (!browsable) break; } else if (attr is CategoryAttribute) { category = ((CategoryAttribute)attr).Category; } } if (!browsable) continue; if (!_categories.ContainsKey(category)) _categories.Add(category, new List()); _categories[category].Add(p); } } } }