Files

73 lines
2.2 KiB
C#
Raw Permalink Normal View History

2025-10-23 00:49:44 -04:00
using System;
using System.Collections.Generic;
using NaughtyAttributes;
2026-04-17 12:01:50 -04:00
using SLSUtilities.General;
2025-10-23 00:49:44 -04:00
using UnityEngine;
namespace Continentis.MainGame
{
[CreateAssetMenu(menuName = "Continentis/KeywordData", fileName = "KeywordData")]
public partial class KeywordData : ScriptableObject
{
[Tooltip("关键词在显示上使用InterpretedKeyword的信息")]
[KeyWidth(0.2f)]
public SerializableDictionary<string, InterpretedKeyword> interpretedKeywords = new SerializableDictionary<string, InterpretedKeyword>();
/// <summary>
/// 尝试获取关键词,基础关键词和解释关键词均可
/// </summary>
public bool TryGetLocalizedKeyword(string key, out string locName, out string locDesc)
{
if (TryGetKeyword(key, out InterpretedKeyword keyword))
{
locName = keyword.name.Localize();
locDesc = keyword.description.Localize();
return true;
}
locName = keyword.name;
locDesc = keyword.description;
return false;
}
/// <summary>
/// 尝试获取关键词,基础关键词和解释关键词均可
/// </summary>
public bool TryGetKeyword(string key, out InterpretedKeyword keyword)
{
if (interpretedKeywords.TryGetValue(key, out keyword))
{
return true;
}
keyword = default;
return false;
}
}
public partial class KeywordData
{
public string keywordToAdd;
[Button]
private void AddKeywordToCollection()
{
InterpretedKeyword ik = new InterpretedKeyword("Keyword_" + keywordToAdd, "Keyword_" + keywordToAdd + "_Description");
interpretedKeywords.TryAdd(keywordToAdd, ik);
}
}
[Serializable]
public struct InterpretedKeyword
{
public string name;
public string description;
public InterpretedKeyword(string name, string description)
{
this.name = name;
this.description = description;
}
}
}