using System; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; public class LogManager : MonoBehaviour { [System.Serializable] public class LogEntry { public string wordOfInterest; public string userDefinition; } public List logEntries = new List(); public GameObject logPrefab; public Transform contentPanel; public GameObject logMenu; private bool isLogOpen = false; private InteractManager interactMan; private StarterAssetsInputs input; public ScrollRect scrollRect; private CrabInterface crabInterface; public Animator scrollArea; [Header("Audio")] public AudioClip openLogSound; public AudioClip closeLogSound; public AudioClip confirmSound; public AudioClip clearSound; private AudioSource audioSource; [Copyable] public bool canOpenLog = false; void Start() { UpdateLog(); interactMan = GetComponent(); input = GetComponent(); logMenu.SetActive(false); audioSource = GetComponent(); if (audioSource == null) { audioSource = gameObject.AddComponent(); audioSource.playOnAwake = false; } } void Update() { if (!canOpenLog) { return; } if (input.log) { ToggleLogMenu(!isLogOpen); input.log = false; } } public void SetCrabInterface(CrabInterface newCrabInterface) { crabInterface = newCrabInterface; } public void ToggleLogMenu(bool open) { isLogOpen = open; logMenu.SetActive(isLogOpen); AudioManager.Instance.ToggleRadioEQ(isLogOpen); if (audioSource != null) { if (isLogOpen && openLogSound != null) { audioSource.PlayOneShot(openLogSound); } else if (!isLogOpen && closeLogSound != null) { audioSource.PlayOneShot(closeLogSound); } } if (isLogOpen) { AudioManager.Instance.ToggleRadioEQ(isLogOpen); Time.timeScale = 0f; input.SetCursorState(false); interactMan.UnlockInteract(false); scrollArea.Play("EnterScrollArea"); if (scrollRect != null) { scrollRect.verticalNormalizedPosition = 1f; } } else { if (crabInterface != null) Destroy(crabInterface.gameObject); Time.timeScale = 1f; interactMan.UnlockInteract(true); input.SetCursorState(true); } } public void AddWord(string newWord) { interactMan = GetComponent(); input = GetComponent(); newWord = newWord.TrimEnd('!', '.', ',', '?', ';', ':').ToLower(); newWord = Char.ToUpper(newWord[0]) + newWord.Substring(1); if (logEntries.Exists(entry => entry.wordOfInterest == newWord)) return; logEntries.Add(new LogEntry { wordOfInterest = newWord, userDefinition = "" }); UpdateLog(); } public void UpdateLog() { foreach (Transform child in contentPanel) { Destroy(child.gameObject); } foreach (var entry in logEntries.OrderBy(e => e.wordOfInterest)) { GameObject logInstance = Instantiate(logPrefab, contentPanel); Button button = logInstance.GetComponent