using System.Collections.Generic; using System.Linq; using UnityEngine; namespace Ilumisoft.GraphicsControl { [DisallowMultipleComponent()] [DefaultExecutionOrder(-1)] public class DefaultGraphicSettingsManager : GraphicSettingsManager { List settings = new(); public override List GetGraphicSettings() => settings; public override T Get() { foreach (var setting in settings) { if (setting is T targetSetting) { return targetSetting; } } return default; } public override bool TryGet(out T graphicSetting) { foreach (var setting in settings) { if (setting is T targetSetting) { graphicSetting = targetSetting; return true; } } graphicSetting = default; return false; } protected override void Awake() { base.Awake(); settings = GetComponents().ToList(); } private void Start() { foreach (var setting in settings) { setting.Initialize(); } LoadSettings(); ApplySettings(); } public override void LoadSettings() { foreach (var setting in settings) { if (setting is GraphicSetting storeable) { storeable.LoadSetting(); } } } public override void SaveSettings() { foreach (var setting in settings) { if (setting is GraphicSetting storeable) { storeable.SaveSetting(); } } } public override void ApplySettings() { foreach (var settingApplier in GraphicSettingsAppliers) { settingApplier.ApplySettings(); } } private void Reset() { if(!TryGetComponent(out _)) { gameObject.AddComponent(); } } } }