using System.Linq; using Michsky.UI.Heat; using Obvious.Soap; using UnityEngine; public class UI_ContinueGame : MonoBehaviour { public PlayerProfile PlayerProfile; public BoolVariable IsInGameMainMenuEnabled; private void Start() { Refresh(); } private void OnEnable() { PlayerProfile.OnLoadData += Refresh; PlayerProfile.OnProfileCreated += Refresh; } private void OnDisable() { PlayerProfile.OnLoadData -= Refresh; PlayerProfile.OnProfileCreated -= Refresh; } private void Refresh() { BoxButtonManager component = GetComponent(); if ((bool)component) { component.Interactable(!string.IsNullOrEmpty(PlayerProfile.LastLoadedChapterID) || IsInGameMainMenuEnabled.Value); } } public void OnButtonClick() { if (IsInGameMainMenuEnabled.Value) { IsInGameMainMenuEnabled.Value = false; } else { if (string.IsNullOrEmpty(PlayerProfile.LastLoadedChapterID)) { return; } ChapterManager chapterManager = Object.FindFirstObjectByType(FindObjectsInactive.Include); if ((bool)chapterManager) { chapterManager.chapters.FirstOrDefault((ChapterManager.ChapterItem c) => c.chapterID == PlayerProfile.LastLoadedChapterID)?.onPlay?.Invoke(); } } } }