using System; using System.Collections.Generic; using NaughtyAttributes; using SLSUtilities.General; using UnityEngine; namespace Continentis.MainGame { [CreateAssetMenu(menuName = "Continentis/KeywordData", fileName = "KeywordData")] public partial class KeywordData : ScriptableObject { [Tooltip("关键词,在显示上使用InterpretedKeyword的信息")] [KeyWidth(0.2f)] public SerializableDictionary interpretedKeywords = new SerializableDictionary(); /// /// 尝试获取关键词,基础关键词和解释关键词均可 /// 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; } /// /// 尝试获取关键词,基础关键词和解释关键词均可 /// 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; } } }