调整目录结构

This commit is contained in:
2025-08-29 09:11:08 +08:00
parent efb64ce7bc
commit 1fff9db9ca
351 changed files with 304 additions and 215 deletions

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace NBF.Setting
{
public interface IMultiOption : IOptionBase
{
List<string> GetOptionNames();
}
public abstract class MultiOption<T> : OptionBase, IMultiOption
{
protected OptionTable<T> OptionTable = new OptionTable<T>();
protected void AddOption(string name, T value)
{
OptionTable.Add(name, value);
}
public List<string> GetOptionNames() => OptionTable.GetNames();
protected void SelectOption(T value, int defaultIndex = 0)
{
SetValue(TryGetIndex(value, out var index) ? index : defaultIndex);
}
protected void SelectOption(Predicate<T> predicate, int defaultIndex = 0)
{
SetValue(TryGetIndex(predicate, out var index) ? index : defaultIndex);
}
protected bool TryGetIndex(T option, out int index)
{
return TryGetIndex(entry => entry.Equals(option), out index);
}
protected bool TryGetIndex(Predicate<T> predicate, out int index)
{
index = -1;
var entries = OptionTable.GetValues();
for (var i = 0; i < entries.Count; i++)
{
if (!predicate(entries[i])) continue;
index = i;
return true;
}
return false;
}
public T GetSelectedOption() => OptionTable.GetValue(Value);
public override string GetDisplayString()
{
return OptionTable.GetName(Value);
}
}
}