On Failure no se ejecuta
Registra el valor devuelto. Si no es Failed, la solicitud fue rechazada antes de los eventos.
Ejecución
Solicita un fallo de forma explícita, interpreta el resultado, observa las dos notificaciones y deja la política de reinicio en el código del proyecto.
El sistema no deduce una derrota por salud, tiempo, muerte del jugador ni por un objetivo que no avanza. Un script del juego debe llamar a ChapterManager.TryFailCurrentChapter(reason). La llamada solo se acepta cuando el Manager está preparado, existe un capítulo activo y no hay una transición de escena en curso.
Aceptar el fallo cambia los estados y emite notificaciones. No carga una escena, no restaura un checkpoint, no reposiciona al jugador, no guarda Failed y no muestra una interfaz automáticamente.
| Resultado | Cuándo aparece | Respuesta recomendada |
|---|---|---|
Failed | El capítulo estaba Active y se aceptó el fallo. | Permite que los receptores apliquen la política del juego. |
ManagerNotReady | La inicialización aún no terminó. | Espera a On Manager Ready. |
NoActiveChapter | No hay capítulo actual. | Revisa la selección inicial. |
TransitionInProgress | Ya se está cargando otra escena. | Ignora la solicitud y no abras otro flujo de derrota. |
ChapterNotActive | El capítulo está Completed, Failed o Not Started. | No repitas el fallo histórico. |
El Manager rechaza estados no válidos sin efectos.
El Chapter pasa a Failed; el objetivo activo o en espera pasa a Failed.
ChapterFailed recibe ChapterFailureInfo con Chapter, Objective y reason.
On Failure se invoca sin parámetros para receptores del Inspector.
El juego decide mostrar UI, reintentar, recargar o cambiar de escena.
TryFailCurrentChapter("manual_test").ChapterFailed si necesitas leer el motivo o el objetivo afectado.ChapterNotActive y no emitir eventos nuevos.Después de Failed, el juego puede llamar a TrySelectChapter, ReloadCurrentScene(true), TransitionToScene o a su propio cargador. Elige una sola política y ejecútala desde el receptor de fallo. HandleFailure se conserva por compatibilidad con UnityEvents antiguos, pero su parámetro solo se reenvía como motivo y ya no selecciona un punto de reinicio.
Los estados Active y Failed son transitorios y no se restauran como progreso histórico. Consulta Persistencia del progreso.
Registra el valor devuelto. Si no es Failed, la solicitud fue rechazada antes de los eventos.
Es el comportamiento previsto. Añade una política externa y llama a la transición elegida.
Comprueba que no respondes a la vez a ChapterFailed y On Failure con la misma consecuencia.
El producto no persiste Failed. Busca un estado propio del juego o una suscripción duplicada.
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 FailureRequestExample : MonoBehaviour
{
public ChapterFailureResult RequestPlayerDefeat()
{
ChapterManager manager = ChapterManager.Instance;
return manager != null
? manager.TryFailCurrentChapter("player_defeated")
: ChapterFailureResult.ManagerNotReady;
}
}
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 DeathScreenExample : MonoBehaviour
{
[SerializeField]
private GameObject deathScreen;
private ChapterManager manager;
private void OnEnable()
{
manager = ChapterManager.Instance;
if (manager != null)
{
manager.ChapterFailed += ShowDeathScreen;
}
}
private void OnDisable()
{
if (manager != null)
{
manager.ChapterFailed -= ShowDeathScreen;
}
}
private void ShowDeathScreen(ChapterFailureInfo information)
{
if (deathScreen != null)
{
deathScreen.SetActive(true);
}
}
}
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 RestartAfterFailureExample : MonoBehaviour
{
private string failedChapterId = string.Empty;
public void RememberFailure(ChapterFailureInfo information)
{
failedChapterId = information.Chapter != null
? information.Chapter.Identifier
: string.Empty;
}
public bool TryRestartFailedChapter()
{
ChapterManager manager = ChapterManager.Instance;
return manager != null && !manager.IsTransitioning &&
!string.IsNullOrWhiteSpace(failedChapterId) &&
manager.TrySelectChapter(failedChapterId);
}
}