ICharacter - jimdroberts/FishMMO GitHub Wiki

Description

Interface for a character entity in the game world. Defines core properties, state management, and behaviour registration for all character types.


API Access

Fields

  • long ID { get; set; }

    Unique identifier for the character.

  • string Name { get; }

    The character's display name.

  • Transform Transform { get; }

    The transform of the character.

  • GameObject GameObject { get; }

    The GameObject associated with the character.

  • Collider Collider { get; set; }

    The collider for the character.

  • bool IsTeleporting { get; }

    Whether the character is currently teleporting.

  • bool IsSpawned { get; }

    Whether the character is currently spawned in the world.

  • int Flags { get; set; }

    Bitwise flags representing the character's state.

#if !UNITY_SERVER

  • Transform MeshRoot { get; }

    The root transform for the character's mesh/model hierarchy.

  • TextMeshPro CharacterNameLabel { get; set; }

    The label displaying the character's name above their model.

  • TextMeshPro CharacterGuildLabel { get; set; }

    The label displaying the character's guild above their model.

  • void InstantiateRaceModelFromIndex(RaceTemplate raceTemplate, int modelIndex)

    Instantiates the character's race model prefab at the specified index and attaches it to the mesh root. Parameters:

    • RaceTemplate raceTemplate: The race template containing model references.
    • int modelIndex: The index of the model to instantiate. #endif

Methods

  • void EnableFlags(CharacterFlags flags)

    Enables the specified flags for the character using bitwise operations. Parameters:

    • CharacterFlags flags: Flags to enable.
  • void DisableFlags(CharacterFlags flags)

    Disables the specified flags for the character using bitwise operations. Parameters:

    • CharacterFlags flags: Flags to disable.
  • void RegisterCharacterBehaviour(ICharacterBehaviour characterBehaviour)

    Registers a character behaviour component for this character. Enables behaviour-based extension and modular logic. Parameters:

    • ICharacterBehaviour characterBehaviour: The behaviour to register.
  • void UnregisterCharacterBehaviour(ICharacterBehaviour characterBehaviour)

    Unregisters a character behaviour component from this character. Parameters:

    • ICharacterBehaviour characterBehaviour: The behaviour to unregister.
  • bool TryGet(out T control) where T : class, ICharacterBehaviour

    Attempts to get a registered character behaviour of type T. Returns true if found, with the behaviour in the out parameter. Parameters:

    • out T control: The behaviour instance if found, otherwise null. Returns: bool (True if the behaviour is found; otherwise, false.)

Basic Usage

Setup

  1. Implement ICharacter for all character types in your game.
  2. Use the interface to manage core character state, registration, and behaviour extension.
  3. Integrate with other systems (e.g., networking, UI) via the defined properties and methods.

Example

// Example 1: Implementing ICharacter
public class PlayerCharacter : MonoBehaviour, ICharacter {
    // Implement all required properties and methods
}

// Example 2: Registering a behaviour
ICharacter character = ...;
ICharacterBehaviour behaviour = ...;
character.RegisterCharacterBehaviour(behaviour);

// Example 3: Checking and enabling flags
if (!character.IsTeleporting) {
    character.EnableFlags(CharacterFlags.IsTeleporting);
}

Best Practices

  • Always implement all required properties and methods when creating a new character type.
  • Use bitwise flags for efficient state management.
  • Register and unregister behaviours to enable modular and extensible character logic.
  • Use the provided interface for type safety and consistency across character systems.
⚠️ **GitHub.com Fallback** ⚠️