UICharacterControl - jimdroberts/FishMMO GitHub Wiki

Description

UICharacterControl is a base class in the FishMMO client responsible for managing the association between a player character and a UI control. It provides methods and events for setting and unsetting the character, and supports pre/post set and unset logic via virtual methods and callbacks.


API Access

Fields

  • public Action OnSetCharacter

    Event invoked when a character is set.

  • public Action OnUnsetCharacter

    Event invoked when a character is unset.

  • public IPlayerCharacter Character { get; private set; }

    The current player character associated with this control.

Methods

  • public override void OnStarting()

    Called when the UI control is starting. Override for initialization logic.

  • public override void OnDestroying()

    Called when the UI control is being destroyed. Clears the character reference.

  • public virtual void OnPreSetCharacter()

    Invoked before Character is set. Override for pre-set logic.

  • public virtual void OnPostSetCharacter()

    Invoked immediately after Character is set. Override for post-set logic.

  • public void SetCharacter(IPlayerCharacter character)

    Sets the character for this control, invoking pre/post set events and callbacks. Parameters: IPlayerCharacter character – The player character to associate.

  • public virtual void OnPreUnsetCharacter()

    Invoked before Character is unset. Override for pre-unset logic.

  • public virtual void OnPostUnsetCharacter()

    Invoked immediately after Character is unset. Override for post-unset logic.

  • public void UnsetCharacter()

    Unsets the character for this control, invoking pre/post unset events and callbacks.


Basic Usage

Setup

  1. Inherit from UICharacterControl to create a custom UI control for a player character.
  2. Use SetCharacter to associate a character with the control.
  3. Override pre/post set and unset methods for custom logic as needed.

Example

// Example: Creating a custom UI control for a player character
public class MyCharacterUI : UICharacterControl
{
    public override void OnPostSetCharacter()
    {
        // Custom logic after character is set
    }
}

// Usage
myCharacterUI.SetCharacter(playerCharacter);

Best Practices

  • Always use SetCharacter and UnsetCharacter to manage the character association.
  • Override pre/post set and unset methods for custom initialization and cleanup.
  • Use the OnSetCharacter and OnUnsetCharacter events for additional callbacks.
⚠️ **GitHub.com Fallback** ⚠️