UICharacterSelect - jimdroberts/FishMMO GitHub Wiki

Description

The UICharacterSelect class is a UI control for the FishMMO client that manages the character selection screen. It handles displaying available characters, selection, creation, and deletion, and manages UI feedback and button states. It also integrates with the cinematic camera and handles network broadcasts for character list, creation, and deletion events.


API Access

Fields

  • public Button ConnectButton

    Button to connect with the selected character.

  • public Button DeleteButton

    Button to delete the selected character.

  • public RectTransform SelectedCharacterParent, CharacterButtonParent

    Parent transforms for the selected character UI and character selection buttons.

  • public CharacterDetailsButton CharacterButtonPrefab

    Prefab for individual character selection button.

  • public Action OnCharacterListStart, OnCharacterListEnd

    Actions called when the character list is received and after processing.

  • public CinematicCamera CinematicCamera

    Reference to the cinematic camera attached to this UI control.

  • private List characterList

    List of currently displayed character buttons.

  • private CharacterDetailsButton selectedCharacter

    The currently selected character button.

  • private Color previousColor

    Stores the previous color for label reset.

Methods

  • public override void OnClientSet()

    Subscribes to connection, authentication, and character broadcast events.

  • public override void OnClientUnset()

    Unsubscribes from connection, authentication, and character broadcast events.

  • public override void OnDestroying()

    Cleans up character list when the UI is destroyed.

  • private void ClientManager_OnClientConnectionState(ClientConnectionStateArgs obj)

    Handles client connection state changes and hides the panel when disconnected.

  • private void Authenticator_OnClientAuthenticationResult(ClientAuthenticationResult result)

    Handles authentication results and updates UI accordingly.

  • public void DestroyCharacterList()

    Destroys all character buttons and clears the character list.

  • private void OnClientCharacterListBroadcastReceived(CharacterListBroadcast msg, Channel channel)

    Handles incoming character list broadcast and populates character buttons.

  • private void OnCharacterListReady()

    Invokes start event and begins post-processing coroutine for the character list.

  • IEnumerator OnProcessCharacterList()

    Coroutine for post-character-list processing, resets camera and shows panel.

  • private void OnClientCharacterCreateBroadcastReceived(CharacterCreateBroadcast msg, Channel channel)

    Handles character creation broadcast and adds new character button.

  • private void OnClientCharacterDeleteBroadcastReceived(CharacterDeleteBroadcast msg, Channel channel)

    Handles character deletion broadcast and removes character button.

  • private void OnCharacterSelected(CharacterDetailsButton button)

    Handles character selection and updates button colors.

  • public void OnClick_SelectCharacter()

    Initiates character selection and connection when the connect button is clicked.

  • public void OnClick_DeleteCharacter()

    Prompts for confirmation and deletes character if confirmed when the delete button is clicked.

  • public void OnClick_CreateCharacter()

    Shows the character creation panel when the create character button is clicked.

  • public override void OnQuitToLogin()

    Stops character list coroutine and unlocks buttons when quitting to login.

  • public void OnClick_QuitToLogin()

    Stops character list coroutine and returns to login screen when the quit to login button is clicked.

  • public void OnClick_Quit()

    Quits the client application when the quit button is clicked.

  • private void SetConnectButtonLocked(bool locked)

    Enables or disables the connect button.

  • private void SetDeleteButtonLocked(bool locked)

    Enables or disables the delete button.


Basic Usage

Setup

  1. Attach UICharacterSelect to a UI panel in your scene.
  2. Assign all required UI references (buttons, parents, prefabs, etc.) in the inspector.
  3. Call OnClientSet() when the client is ready to initialize event handlers.
  4. The user can select, create, or delete characters, and connect to the game world.
  5. Handle UI feedback and navigation using the provided methods.

Example

// On client ready:
uiCharacterSelect.OnClientSet();

// On client disconnect or scene change:
uiCharacterSelect.OnClientUnset();

// On connect button click:
uiCharacterSelect.OnClick_SelectCharacter();

Best Practices

  • Always clean up event subscriptions in OnClientUnset and OnDestroying to avoid memory leaks.
  • Lock buttons while network requests are pending to prevent duplicate actions.
  • Use the cinematic camera for smooth transitions and immersive UI experience.
  • Use the character list events to trigger additional UI or logic as needed.
  • Validate user actions before sending network requests.
⚠️ **GitHub.com Fallback** ⚠️