UICharacterControl - jimdroberts/FishMMO GitHub Wiki
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.
-
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.
-
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.
- Inherit from
UICharacterControl
to create a custom UI control for a player character. - Use
SetCharacter
to associate a character with the control. - Override pre/post set and unset methods for custom logic as needed.
// 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);
- Always use
SetCharacter
andUnsetCharacter
to manage the character association. - Override pre/post set and unset methods for custom initialization and cleanup.
- Use the
OnSetCharacter
andOnUnsetCharacter
events for additional callbacks.