可以在 GetCharacterName 方法中加入处理逻辑,当人物名字中出现字母'b'时,找到下一个'b'的位置,然后截取字符串到下一个'b'之前的部分,返回截取后的字符串作为人物名字。

修改后的 GetCharacterName 方法如下所示:

public string GetCharacterName(Character character)
{
    string name = CharacterNameDic[character];
    int startIndex = name.IndexOf('b');
    if (startIndex != -1)
    {
        int endIndex = name.IndexOf('b', startIndex + 1);
        if (endIndex != -1)
        {
            return name.Substring(0, endIndex);
        }
    }
    return name;
}

这样,当人物名字为'Lilybab'时,实际显示出来的人物名字就是'Lily'。

C# 代码优化:对话系统中隐藏人物名字中的部分字符

原文地址: https://www.cveoy.top/t/topic/ph1h 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录