using System.Collections.Generic; using PrimeTween; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class ScriptManager : MonoBehaviour { [SerializeField] TextAsset scriptFile; [SerializeField] TextMeshProUGUI speakerText; [SerializeField] TextMeshProUGUI dialogueText; [SerializeField] private GameObject choiceButtonPrefab; [SerializeField] private Transform choiceButtonContainer; [SerializeField] float charsPerSecond = 45f; private readonly float shakeAmount = 1.1f; private bool isChoiceAvailable = false; private Tween dialogueTween; private Script _currentScript; void Start() { speakerText.SetText(" "); speakerText.ForceMeshUpdate(true); dialogueText.SetText(" "); dialogueText.ForceMeshUpdate(true); _currentScript = ScriptParser.Parse(scriptFile.text); } void Update() { DisplayEffects(dialogueText); if (!isChoiceAvailable && !IsPointerOverInteractiveUI() && (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))) { if (dialogueTween.isAlive) dialogueTween.Complete(); else NextStep(); } } public void DebugReload() { speakerText.SetText(" "); speakerText.ForceMeshUpdate(true); dialogueText.SetText(" "); dialogueText.ForceMeshUpdate(true); _currentScript = ScriptParser.Parse(scriptFile.text); } private void NextStep() { if (_currentScript.HasNextAction()) { ScriptAction action = _currentScript.Continue(); ExecuteAction(action); return; } Debug.Log("ScriptManager :: End of Script"); } private void ExecuteAction(ScriptAction action) { if (action.Type == "scene") { string sceneName = action.GetParam("name"); Debug.Log($"ScriptManager :: Change Scene: {sceneName}"); NextStep(); return; } if (action.Type == "bg") { string bgFile = action.GetParam("file"); Debug.Log($"ScriptManager :: Change Background: {bgFile}"); NextStep(); return; } if (action.Type == "spk") { string speaker = action.GetParam("name"); speakerText.SetText(speaker); speakerText.ForceMeshUpdate(true); NextStep(); return; } if (action.Type == "msg") { string dialogue = action.GetParam("content"); DisplayDialogue(dialogue); return; } if (action.Type == "goto") { string targetScene = action.GetParam("scene"); _currentScript.JumpTo(targetScene); NextStep(); return; } if (action.Type == "choices") { Debug.Log("ScriptManager :: Show Choices"); isChoiceAvailable = true; foreach (var choice in action.Choices) { string text = choice["content"]; string target = choice["goto"]; GameObject buttonObj = Instantiate(choiceButtonPrefab, choiceButtonContainer); buttonObj.GetComponentInChildren().text = text; buttonObj .GetComponent