diff --git a/.gitignore b/.gitignore index 8d63870..e86ca3a 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,14 @@ .vscode/ # Assets (Temp Setting) -/[Aa]ssets/_MAIN +/[Aa]ssets/_MAIN/Audio +/[Aa]ssets/_MAIN/Audio.meta +/[Aa]ssets/_MAIN/Graphics +/[Aa]ssets/_MAIN/Graphics.meta +/[Aa]ssets/_MAIN/Resources +/[Aa]ssets/_MAIN/Resources.meta +/[Aa]ssets/_MAIN/Scenes +/[Aa]ssets/_MAIN/Scenes.meta # By default unity supports Blender asset imports, *.blend1 blender files do not need to be commited to version control. *.blend1 diff --git a/Assets/_MAIN/Scripts.meta b/Assets/_MAIN/Scripts.meta new file mode 100644 index 0000000..3fd0e89 --- /dev/null +++ b/Assets/_MAIN/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 92d6b7f47c91f3d46ae3984d674a216f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_MAIN/Scripts/Core.meta b/Assets/_MAIN/Scripts/Core.meta new file mode 100644 index 0000000..dd296ae --- /dev/null +++ b/Assets/_MAIN/Scripts/Core.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3e4640df73c0c2348b4923873fe9ba55 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_MAIN/Scripts/Core/Script.cs b/Assets/_MAIN/Scripts/Core/Script.cs new file mode 100644 index 0000000..2cc6e6b --- /dev/null +++ b/Assets/_MAIN/Scripts/Core/Script.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using UnityEngine; + +public class Script +{ + private List _actions; + private int _currentIndex = -1; + private Dictionary _sceneMap = new Dictionary(); + + public Script(List actions, Dictionary sceneMap) + { + _actions = actions; + _sceneMap = sceneMap; + _currentIndex = -1; + } + + public bool HasNextAction() + { + return _currentIndex < _actions.Count - 1; + } + + public ScriptAction Continue() + { + if (!HasNextAction()) + return null; + + _currentIndex++; + ScriptAction currentAction = _actions[_currentIndex]; + + return currentAction; + } + + public ScriptAction GetCurrent() + { + if (_currentIndex >= 0 && _currentIndex < _actions.Count) + return _actions[_currentIndex]; + return null; + } + + public void JumpTo(string sceneName) + { + _currentIndex = _sceneMap[sceneName] - 1; // Continue() 호출 시 해당 인덱스가 되도록 -1 + Debug.Log($"Script :: Jump to scene: {sceneName} (Index: {_currentIndex + 1})"); + } +} diff --git a/Assets/_MAIN/Scripts/Core/Script.cs.meta b/Assets/_MAIN/Scripts/Core/Script.cs.meta new file mode 100644 index 0000000..82b55ba --- /dev/null +++ b/Assets/_MAIN/Scripts/Core/Script.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: b3f1c6b3f22568a45932d3414362bf0b \ No newline at end of file diff --git a/Assets/_MAIN/Scripts/Core/ScriptAction.cs b/Assets/_MAIN/Scripts/Core/ScriptAction.cs new file mode 100644 index 0000000..73caeea --- /dev/null +++ b/Assets/_MAIN/Scripts/Core/ScriptAction.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +public class ScriptAction +{ + public string Type { get; set; } + public Dictionary Params { get; set; } = new Dictionary(); + public List> Choices { get; set; } + + public string GetParam(string key, string defaultValue = "") + { + return Params.ContainsKey(key) ? Params[key].ToString() : defaultValue; + } +} diff --git a/Assets/_MAIN/Scripts/Core/ScriptAction.cs.meta b/Assets/_MAIN/Scripts/Core/ScriptAction.cs.meta new file mode 100644 index 0000000..1cdf374 --- /dev/null +++ b/Assets/_MAIN/Scripts/Core/ScriptAction.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ea31a181cac32d34c9511c7c988fea57 \ No newline at end of file diff --git a/Assets/_MAIN/Scripts/Core/ScriptManager.cs b/Assets/_MAIN/Scripts/Core/ScriptManager.cs new file mode 100644 index 0000000..4bb7a8a --- /dev/null +++ b/Assets/_MAIN/Scripts/Core/ScriptManager.cs @@ -0,0 +1,213 @@ +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