logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class CharacterViewModel

    Runtime state for a single character instance. Extends the Domain CharacterState entity to centralize HP tracking and lifecycle logic, while implementing IViewModel for the presentation layer. Pure C# — no Unity dependencies. Identity is provided by CharacterId from Serenity.Character. Created by the Presenter from a Domain.Configuration.objectConfig at spawn time.

    Inheritance
    object
    CharacterViewModel
    Implements
    IViewModel
    Namespace: Serenity.Character.InterfaceAdapters.ViewModels
    Assembly: Serenity.UnityCharacter.InterfaceAdapters.dll
    Syntax
    public sealed class CharacterViewModel : CharacterState, IViewModel

    Constructors

    CharacterViewModel(CharacterId, int)

    Creates a new CharacterViewModel backed by Domain state.

    Declaration
    public CharacterViewModel(CharacterId characterId, int maxHp)
    Parameters
    Type Name Description
    CharacterId characterId

    Unique identifier for this character instance (CharacterId).

    int maxHp

    Maximum hit points from archetype config.

    Properties

    CharacterId

    Unique identifier for this character instance (alias for Id). Uses CharacterId from Serenity.Character.

    Declaration
    public CharacterId CharacterId { get; }
    Property Value
    Type Description
    CharacterId

    CurrentHp

    Current hit points (delegates to RemainingHealth).

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

    IsAlive

    True while CurrentHp is greater than zero.

    Declaration
    public bool IsAlive { get; }
    Property Value
    Type Description
    bool

    MaxHp

    Maximum hit points (delegates to MaxHealth).

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

    Methods

    ApplyDamage(int)

    Reduces CurrentHp by amount. Delegates to TakeHit(int) for Domain-consistent behavior.

    Declaration
    public void ApplyDamage(int amount)
    Parameters
    Type Name Description
    int amount

    Damage to apply. Must be >= 0.

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    Implements

    IViewModel
    In this article
    © 2026 Serenity. All Rights Reserved