Files
Continentis/Assets/Scripts/MainGame/Base/Keywords/KeywordData.cs
SoulliesOfficial 61a397dd4c MOD!
2025-10-23 00:49:44 -04:00

73 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using NaughtyAttributes;
using SLSFramework.General;
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;
}
}
}