Easy Chapter Generator
EnglishEspañol

Leer el estado actual con seguridad

ChapterManager.Instance es el punto público de consulta. Puede no existir aún, puede no haber Chapter seleccionado y puede no haber objetivo actual tras finalizar o fallar. Comprueba esas situaciones antes de acceder a objetos o mostrar ID.

Las propiedades ofrecen una lectura instantánea desde el hilo principal. No crean una suscripción ni vuelven a cargar el almacén.

Propiedades de consulta

PropiedadSi no existeUso
CurrentChapter / CurrentChapterIdnull / string vacíoIdentidad seleccionada
CurrentChapterStatenullable sin valorEstado del Chapter
HasActiveChapterfalseComprobación rápida
CurrentObjective / CurrentObjectiveIdnull / string vacíoFila actual
CurrentObjectiveStatenullable sin valorEstado de la fila
HasActiveObjectivefalseChapter y fila activos
IsTransitioningfalseEvitar comandos incompatibles

Consultar después de un momento conocido

  • Tras OnManagerReady para el estado inicial.
  • Después de que un comando del proyecto devuelva éxito.
  • Dentro de ChapterFailed para obtener contexto tipado.
  • Antes de mostrar controles que necesitan un objetivo activo.
  • En diagnósticos a intervalos controlados, no generando texto cada frame.

En Objective.OnCompleted el Chapter puede haber avanzado. Guarda el ID anterior o utiliza ObjectiveCompleted si lo necesitas.

Evitar suposiciones habituales

CurrentObjectiveId está vacío

Es válido sin selección o en un estado terminal.

No llega un evento de finalización al cargar

La restauración no reproduce eventos; lee la fotografía tras Ready.

OnCompleted muestra la fila siguiente

El evento local ocurre después de que el Chapter acepte y avance.

Consultar el estado actual de la progresión

Dónde colocarlo
Utiliza este componente en objetos de interfaz, telemetría o integración propios del proyecto.
Cuándo llamarlo
Llama a TryReadCurrentProgress cuando la interfaz deba actualizarse o después de una notificación de ciclo de vida.
Comportamiento
Es una lectura instantánea desde el hilo principal. No se suscribe a cambios posteriores y devuelve false cuando no hay un objetivo activo.
using System;
using System.Collections;
using System.Collections.Generic;
using OverFuture.ChapterObjectiveSystem.Chapters;
using OverFuture.ChapterObjectiveSystem.Events;
using OverFuture.ChapterObjectiveSystem.Objectives;
using OverFuture.ChapterObjectiveSystem.Persistence;
using OverFuture.ChapterObjectiveSystem.Progression;
using UnityEngine;

public sealed class CurrentProgressReaderExample : MonoBehaviour
{
    public bool TryReadCurrentProgress(
        out string chapterId,
        out string objectiveId,
        out ChapterObjective.ObjectiveState objectiveState)
    {
        chapterId = string.Empty;
        objectiveId = string.Empty;
        objectiveState = ChapterObjective.ObjectiveState.NotStarted;

        ChapterManager manager = ChapterManager.Instance;
        if (manager == null || !manager.HasActiveObjective ||
            !manager.CurrentObjectiveState.HasValue)
        {
            return false;
        }

        chapterId = manager.CurrentChapterId;
        objectiveId = manager.CurrentObjectiveId;
        objectiveState = manager.CurrentObjectiveState.Value;
        return true;
    }
}