UIChat - jimdroberts/FishMMO GitHub Wiki
A UI control for managing the chat system in the FishMMO client. Handles chat message display, tab management, channel selection, message rate limiting, and integration with the network and character systems. Supports multiple chat channels, tabbed chat, and dynamic message handling.
-
public const int MAX_LENGTH
The maximum allowed length for chat messages.
-
public string WelcomeMessage
The welcome message displayed when the chat is initialized.
-
public Transform ChatViewParent
The parent transform for chat message views.
-
public UIChatMessage ChatMessagePrefab
The prefab used to instantiate chat messages.
-
public Transform ChatTabViewParent
The parent transform for chat tab views.
-
public ChatTab ChatTabPrefab
The prefab used to instantiate chat tabs.
-
public Dictionary<string, string> ErrorCodes
Error code messages mapped to their respective error keys.
-
public UIChatChannelColorDictionary ChannelColors
Color mapping for each chat channel.
-
public Dictionary<string, ChatTab> Tabs
Dictionary of chat tabs by their names.
-
public string CurrentTab
The name of the currently active chat tab.
-
public List Messages
List of all chat messages currently displayed.
-
public bool AllowRepeatMessages
Whether repeated messages are allowed.
-
public float MessageRateLimit
The rate at which messages can be sent, in milliseconds.
-
public override void OnStarting()
Initializes tabs, welcome message, and channel commands.
-
public override void OnClientSet()
Registers chat broadcast event handler.
-
public override void OnClientUnset()
Unregisters chat broadcast event handler.
-
void Update()
Unity Update loop. Handles chat input and message validation.
-
public void EnableChatInput()
Enables chat input if no other input field has focus and chat keys are pressed.
// ...other methods for message handling, tab management, and channel selection...
- Attach
UIChat
to a chat UI GameObject in the Unity Editor. - Assign all required UI fields in the Inspector:
ChatViewParent
,ChatMessagePrefab
,ChatTabViewParent
, andChatTabPrefab
. - Ensure the character, network, and input systems are available and properly set up.
// Example usage in a MonoBehaviour
public UIChat chatUI;
void Start() {
chatUI.OnStarting();
}
// To add a message
chatUI.InstantiateChatMessage(ChatChannel.World, "Player", "Hello world!");
// To add a new tab
chatUI.AddTab();
- Always assign all UI references in the Inspector to avoid null reference errors.
- Use event subscriptions in
OnClientSet
/OnClientUnset
to avoid memory leaks. - Keep the UI updated by managing tabs and messages dynamically.
- Integrate with the network and character systems for real-time chat updates.
- Use message rate limiting to prevent spam.