Se ejecuta dos veces al habilitar la UI
Se añadió sin retirar. Comprueba listeners por código y persistentes por separado.
Programación
Suscríbete y elimina suscripciones a las notificaciones del Manager y del capítulo sin duplicar receptores ni conservar referencias obsoletas.
| Necesidad | Evento | Contexto |
|---|---|---|
| Respuesta desde Inspector | UnityEvents del Manager | Sin parámetros |
| Motivo y elementos del fallo | ChapterFailed | ChapterFailureInfo |
| Índice aceptado antes de acciones | Chapter.ObjectiveCompleted | int |
| Detector aceptado | Objective.OnCompleted | Local y posterior al avance |
| Ciclo configurado | Eventos de Chapter/fila | Se editan en la ventana |
Guarda la instancia exacta, suscríbete una vez y elimina el mismo delegado. Durante la destrucción, buscar el singleton otra vez puede devolver null u otra instancia. Para eventos del Chapter, deja de observar el antiguo antes de enlazar el nuevo.
OnEnable/OnDisable funciona cuando la vida del componente coincide con la observación. Un objeto persistente debe reenlazar de forma explícita al cambiar de escena.
Después de suscribirte, lee las propiedades actuales una vez. Esto es imprescindible tras restaurar progreso, porque no se repiten finalizaciones. OnManagerReady indica que se intentó seleccionar; comprueba después CurrentChapter. OnBeforeSceneLoad indica que la transición ya está bloqueada.
Se añadió sin retirar. Comprueba listeners por código y persistentes por separado.
Puede conservar el Manager antiguo; cancela antes de descargar.
Es correcto tras la restauración; lee el estado.
Utiliza el evento tipado previo o guarda el ID antes de llamar.
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 LifecycleSubscriptionExample : MonoBehaviour
{
private ChapterManager manager;
private Chapter observedChapter;
private void OnEnable()
{
manager = ChapterManager.Instance;
if (manager == null)
{
return;
}
manager.OnManagerReady.AddListener(HandleManagerReady);
ObserveCurrentChapter();
}
private void OnDisable()
{
manager?.OnManagerReady.RemoveListener(HandleManagerReady);
StopObservingChapter();
manager = null;
}
private void HandleManagerReady()
{
ObserveCurrentChapter();
}
private void ObserveCurrentChapter()
{
StopObservingChapter();
observedChapter = manager != null ? manager.CurrentChapter : null;
if (observedChapter != null)
{
observedChapter.ObjectiveCompleted += HandleObjectiveCompleted;
}
}
private void StopObservingChapter()
{
if (observedChapter != null)
{
observedChapter.ObjectiveCompleted -= HandleObjectiveCompleted;
}
observedChapter = null;
}
private void HandleObjectiveCompleted(int objectiveIndex)
{
Debug.Log($"Completed objective index: {objectiveIndex}", this);
}
}
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 FailureSubscriptionExample : MonoBehaviour
{
private ChapterManager manager;
private void OnEnable()
{
manager = ChapterManager.Instance;
if (manager != null)
{
manager.ChapterFailed += HandleChapterFailed;
}
}
private void OnDisable()
{
if (manager != null)
{
manager.ChapterFailed -= HandleChapterFailed;
}
manager = null;
}
private void HandleChapterFailed(ChapterFailureInfo information)
{
Debug.Log($"{information.Chapter?.Identifier}: {information.Reason}", this);
}
}