Files
EnglewoodLAB/Assets/Scripts/UI/SettingPanel/OptionBase.cs
SOOBEEN HAN f1894889ee <refactor> Octopus Twin 템플릿 적용
- 기능 외 UI 구조만 적용
- 프로젝트에 걸맞는 UI는 재작업 필요
2026-02-23 18:20:09 +09:00

56 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class OptionBase
{
public string section;
public Dictionary<string, string> options= new Dictionary<string, string>();
public MonoBehaviour target;
public OptionBase(MonoBehaviour mb)
{
target = mb;
var targetFields = mb.GetType().GetAllFields();
foreach (var f in targetFields)
{
var attributes = f.GetCustomAttributes(typeof(OptionAttribute), false);
if (attributes.Count() != 0)
{
switch (attributes[0])
{
case OptionKeyAttribute ok:
options.Add(f.Name, f.GetValue(mb).ToString());
break;
case OptionSectionAttribute os:
section = f.Name;
break;
}
}
}
}
public void SetValue(MonoBehaviour mb)
{
var t = mb.GetType();
foreach(var option in options)
{
var field = t.GetAllField(option.Key);
field.SetValue(mb, option.Value);
}
}
}
[AttributeUsage(AttributeTargets.Field )]
public class OptionKeyAttribute : OptionAttribute
{
}
[AttributeUsage(AttributeTargets.Field)]
public class OptionSectionAttribute: OptionAttribute
{
}
[AttributeUsage(AttributeTargets.Field)]
public class OptionAttribute : Attribute { }