UIManager - jimdroberts/FishMMO GitHub Wiki
UIManager
is a Static helper class for managing UI controls in the FishMMO client. Handles registration, visibility, focus, and client/character injection for all UIControl instances. Provides utility methods for showing, hiding, and querying UI state.
-
private static Dictionary<string, UIControl> controls
Maps GameObject names to their corresponding UIControl instances.
-
private static Dictionary<string, UICharacterControl> characterControls
Maps GameObject names to their corresponding UICharacterControl instances.
-
private static CircularBuffer closeOnEscapeControls
Buffer of UIControls that should be closed when Escape is pressed, in last-opened order.
-
private static Client _client
Reference to the current Client instance for dependency injection.
-
internal static void SetClient(Client client)
Injects the Client instance into all registered controls for network/UI interaction.
-
internal static void SetCharacter(IPlayerCharacter character)
Injects the IPlayerCharacter instance into all registered character controls.
-
internal static void UnsetCharacter()
Removes the character reference from all registered character controls.
-
internal static void Register(UIControl control)
Registers a new UIControl instance, making it accessible by name.
-
internal static void Unregister(UIControl control)
Unregisters a UIControl instance, removing it from the manager.
-
internal static void RegisterCloseOnEscapeUI(UIControl control)
Registers a UIControl to be closed when Escape is pressed.
-
internal static void UnregisterCloseOnEscapeUI(UIControl control)
Unregisters a UIControl from the Escape close list.
-
public static bool TryGet(string name, out T control) where T : UIControl
Tries to retrieve a control by name and cast it to the specified type.
-
public static bool Exists(string name)
Checks if a control exists by name.
-
public static void ToggleVisibility(string name)
Toggles the visibility of a control.
-
public static void Show(string name)
Shows a control by name.
-
public static void Hide(string name)
Hides a control by name.
-
public static void HideAll()
Hides all registered controls.
-
public static void ShowAll()
Shows all registered controls.
-
public static bool ControlHasFocus(UIControl ignore = null)
Checks if any control has focus, optionally ignoring a specific control.
-
public static bool InputControlHasFocus(string name)
Checks if a specific input control has focus.
-
public static bool InputControlHasFocus(UIControl ignore = null)
Checks if any input control has focus, optionally ignoring a specific control.
-
public static bool CloseNext(bool peakOnly = false)
Closes the next UIControl in the close-on-escape list, if available.
-
public static bool ClosedAll()
Checks if all UIControls in the close-on-escape list have been closed.
- All UIControl instances should be registered with UIManager for management.
- Use
SetClient()
andSetCharacter()
to inject dependencies as needed. - Use provided methods to show, hide, or toggle UI controls by name.
- Use focus and input query methods to manage UI state in gameplay logic.
// Example: Showing and hiding a UI control by name
public class UIExample : MonoBehaviour
{
void OpenInventory()
{
UIManager.Show("InventoryPanel");
}
void CloseInventory()
{
UIManager.Hide("InventoryPanel");
}
void ToggleInventory()
{
UIManager.ToggleVisibility("InventoryPanel");
}
}
- Always register UIControl instances with UIManager for consistent management.
- Use the provided methods for showing, hiding, and toggling UI; avoid manipulating GameObjects directly.
- Use focus and input query methods to coordinate UI and gameplay input.
- Inject Client and character references for networked UI as needed.
- Clean up controls by unregistering them when destroyed to prevent memory leaks.