add limit char for chat
This commit is contained in:
@@ -23,5 +23,34 @@ namespace BrewMonster.Scripts.ChatUI
|
||||
|
||||
[Header("Channel Icons")]
|
||||
public List<ChannelIconMapping> channelIcons = new List<ChannelIconMapping>();
|
||||
|
||||
[Header("Message Limits")]
|
||||
[Tooltip("Giới hạn số ký tự thô cho một tin nhắn. <= 0 nghĩa là không giới hạn. " +
|
||||
"TMP tag như <sprite ...> cũng được tính theo đúng số ký tự của tag.")]
|
||||
public int maxRawCharactersPerMessage = 60;
|
||||
|
||||
/// <summary>
|
||||
/// Đếm số ký tự thô (raw) của nội dung đang nhập.
|
||||
/// Count raw characters from current input text.
|
||||
/// </summary>
|
||||
public int CountRawCharacters(string rawText)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rawText))
|
||||
return 0;
|
||||
return rawText.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kiểm tra có thể dùng thêm reserveChars mà vẫn không vượt giới hạn ký tự thô.
|
||||
/// Check whether reserveChars can be added without exceeding raw character limit.
|
||||
/// </summary>
|
||||
public bool CanUseRawCharacters(string rawText, int reserveChars, out int usedChars, out int limitChars)
|
||||
{
|
||||
limitChars = maxRawCharactersPerMessage;
|
||||
usedChars = CountRawCharacters(rawText) + Mathf.Max(0, reserveChars);
|
||||
if (limitChars <= 0)
|
||||
return true;
|
||||
return usedChars <= limitChars;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user