using System;
using System.Collections.Generic;
using UnityEngine;
namespace XericUI.ReflectionUIGenerator
{
///
/// 值范围配置 ScriptableObject
/// 定义不同类型的空/无效/警告/合理值范围判断依据
///
[CreateAssetMenu(
fileName = "Xeric UI avr Value Range Config",
menuName = "Xeric Library/UI Action Vessel/Reflection UI Gen/UI avr Value Range Config",
order = 25)]
public class AvrgValueRangeConfig : ScriptableObject
{
/// 值范围规则列表
[Tooltip("按类型定义的取值范围规则")]
public List entries = new List();
[NonSerialized]
private Dictionary _entryCache;
private void BuildCache()
{
if (_entryCache != null) return;
_entryCache = new Dictionary();
foreach (var entry in entries)
{
if (!string.IsNullOrEmpty(entry.key) && !_entryCache.ContainsKey(entry.key))
_entryCache[entry.key] = entry;
}
}
///
/// 根据键查找值范围规则
///
/// 类型标识(通常为 Type.FullName)
/// 匹配的规则,未找到则返回 null
public AvrgValueRangeEntry FindEntry(string key)
{
if (string.IsNullOrEmpty(key)) return null;
BuildCache();
_entryCache.TryGetValue(key, out var entry);
return entry;
}
///
/// 根据 Type 查找值范围规则
///
public AvrgValueRangeEntry FindEntryByType(Type type)
{
if (type == null) return null;
return FindEntry(type.FullName);
}
///
/// 清空缓存(用于编辑器热重载后重新构建)
///
public void ClearCache()
{
_entryCache = null;
}
}
}