logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityCharacterService

    Unity MonoBehaviour implementation of ICharacterService. Manages per-character state using a dictionary keyed by CharacterId. Stores archetype SO references for Unity-only data access (prefab, death window).

    Inheritance
    object
    UnityCharacterService
    Implements
    ICharacterService
    IService
    IFoundationSettings
    Namespace: Serenity.Character.Infrastructure.Services
    Assembly: Serenity.UnityCharacter.Infrastructure.dll
    Syntax
    public class UnityCharacterService : MonoBehaviour, ICharacterService, IService, IFoundationSettings

    Constructors

    UnityCharacterService()

    Declaration
    public UnityCharacterService()

    Fields

    LOG_CATEGORY

    Declaration
    protected const string LOG_CATEGORY = "CharacterService"
    Field Value
    Type Description
    string

    _characterConfigs

    Declaration
    protected ICharacterConfig[] _characterConfigs
    Field Value
    Type Description
    ICharacterConfig[]

    _characterScriptableObjects

    Declaration
    protected readonly Dictionary<object, ICharacterConfig> _characterScriptableObjects
    Field Value
    Type Description
    Dictionary<object, ICharacterConfig>

    _characterSettings

    Declaration
    protected readonly Dictionary<object, CharacterConfig> _characterSettings
    Field Value
    Type Description
    Dictionary<object, CharacterConfig>

    _characters

    Declaration
    protected readonly Dictionary<CharacterId, CharacterState> _characters
    Field Value
    Type Description
    Dictionary<CharacterId, CharacterState>

    _guid

    Declaration
    protected string _guid
    Field Value
    Type Description
    string

    _id

    Declaration
    protected string _id
    Field Value
    Type Description
    string

    _knownCharactersDebug

    Declaration
    protected List<string> _knownCharactersDebug
    Field Value
    Type Description
    List<string>

    _logService

    Declaration
    protected ILogService _logService
    Field Value
    Type Description
    ILogService

    Properties

    AliveCharacterCount

    Declaration
    public int AliveCharacterCount { get; }
    Property Value
    Type Description
    int

    Guid

    Declaration
    public string Guid { get; set; }
    Property Value
    Type Description
    string

    Id

    Declaration
    public string Id { get; set; }
    Property Value
    Type Description
    string

    LogService

    Declaration
    public ILogService LogService { get; set; }
    Property Value
    Type Description
    ILogService

    Methods

    ActivateCharacter(CharacterId)

    Declaration
    public virtual void ActivateCharacter(CharacterId id)
    Parameters
    Type Name Description
    CharacterId id

    ConfigureCharacters(CharacterConfig[])

    Declaration
    public virtual void ConfigureCharacters(CharacterConfig[] configs)
    Parameters
    Type Name Description
    CharacterConfig[] configs

    FinishCharacterDeath(CharacterId)

    Declaration
    public virtual void FinishCharacterDeath(CharacterId id)
    Parameters
    Type Name Description
    CharacterId id

    HitCharacter(CharacterId, int)

    Declaration
    public virtual bool HitCharacter(CharacterId id, int damage = 1)
    Parameters
    Type Name Description
    CharacterId id
    int damage
    Returns
    Type Description
    bool

    InitializeService(ILogService)

    Initializes the service with required dependencies.

    Declaration
    public virtual void InitializeService(ILogService logService)
    Parameters
    Type Name Description
    ILogService logService

    The logging service for diagnostic output.

    RegisterCharacter(CharacterId, object, int)

    Declaration
    public virtual void RegisterCharacter(CharacterId id, object character, int maxHealth)
    Parameters
    Type Name Description
    CharacterId id
    object character
    int maxHealth

    SetCharacterConfigs(ICharacterConfig[])

    Replaces the current archetype configuration with the provided ScriptableObject array. Called by the installer after label-based auto-discovery, or can be called manually. Overrides any previously applied configs (including inspector-assigned ones).

    Declaration
    public void SetCharacterConfigs(ICharacterConfig[] configs)
    Parameters
    Type Name Description
    ICharacterConfig[] configs

    Array of archetype ScriptableObjects to apply. Null entries are skipped.

    TryGetCharacterSO(object, out ICharacterConfig)

    Gets the Unity authoring data for a specific archetype. Provides access to prefab, death window, and other Unity-only fields.

    Declaration
    public bool TryGetCharacterSO(object character, out ICharacterConfig configSO)
    Parameters
    Type Name Description
    object character

    The character to look up.

    ICharacterConfig configSO

    The authoring ScriptableObject if found.

    Returns
    Type Description
    bool

    True if the archetype SO was found.

    TryGetSnapshot(CharacterId, out CharacterSnapshot)

    Declaration
    public virtual bool TryGetSnapshot(CharacterId id, out CharacterSnapshot snapshot)
    Parameters
    Type Name Description
    CharacterId id
    CharacterSnapshot snapshot
    Returns
    Type Description
    bool

    UnregisterCharacter(CharacterId)

    Declaration
    public virtual void UnregisterCharacter(CharacterId id)
    Parameters
    Type Name Description
    CharacterId id

    Implements

    ICharacterService
    IService
    IFoundationSettings
    In this article
    © 2026 Serenity. All Rights Reserved