From dc34f07526fe2d9bb8f275f8872bc27ec4e6906b Mon Sep 17 00:00:00 2001 From: JenChieh Date: Tue, 6 Aug 2024 03:05:52 -0700 Subject: [PATCH] feat: Expose dialogue system's variables --- .../UI/JCS_DialogueSystem (Game Pad).prefab | 2 +- .../Resources/UI/JCS_DialogueSystem.prefab | 2 +- .../Scenes/Utilities/JCS_ScriptTester.unity | 1 + .../Scripts/Examples/JCS_ScriptTester.cs | 3 + .../Scripts/UI/Dialogue/JCS_DialogueSystem.cs | 65 +++++++++++++++---- 5 files changed, 58 insertions(+), 15 deletions(-) diff --git a/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem (Game Pad).prefab b/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem (Game Pad).prefab index 9e79ab0f..62f4f1fe 100644 --- a/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem (Game Pad).prefab +++ b/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem (Game Pad).prefab @@ -450,7 +450,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_Material: {fileID: 0} m_Color: {r: 1, g: 1, b: 1, a: 0.382} - m_RaycastTarget: 0 + m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: diff --git a/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem.prefab b/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem.prefab index a255cc86..f60a5d0c 100644 --- a/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem.prefab +++ b/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem.prefab @@ -1033,7 +1033,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_Material: {fileID: 0} m_Color: {r: 1, g: 1, b: 1, a: 0.382} - m_RaycastTarget: 0 + m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: diff --git a/Assets/JCSUnity/Scenes/Utilities/JCS_ScriptTester.unity b/Assets/JCSUnity/Scenes/Utilities/JCS_ScriptTester.unity index 3be6b4e6..bc97b117 100644 --- a/Assets/JCSUnity/Scenes/Utilities/JCS_ScriptTester.unity +++ b/Assets/JCSUnity/Scenes/Utilities/JCS_ScriptTester.unity @@ -894,6 +894,7 @@ MonoBehaviour: mTestDialogueScript: {fileID: 1098634727} DisposeKey: 113 RunScriptKey: 119 + SkipKey: 101 --- !u!4 &1098634726 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/JCSUnity/Scripts/Examples/JCS_ScriptTester.cs b/Assets/JCSUnity/Scripts/Examples/JCS_ScriptTester.cs index e1cd51d7..ba201ea0 100644 --- a/Assets/JCSUnity/Scripts/Examples/JCS_ScriptTester.cs +++ b/Assets/JCSUnity/Scripts/Examples/JCS_ScriptTester.cs @@ -32,6 +32,7 @@ public class JCS_ScriptTester : MonoBehaviour public KeyCode DisposeKey = KeyCode.Q; public KeyCode RunScriptKey = KeyCode.W; + public KeyCode SkipKey = KeyCode.E; /* Setter & Getter */ @@ -53,6 +54,8 @@ private void Update() mDialogueSystem.Dispose(); if (JCS_Input.GetKeyDown(RunScriptKey)) mDialogueSystem.ActiveDialogue(mTestDialogueScript); + if (JCS_Input.GetKeyDown(SkipKey)) + print(mDialogueSystem.SkipToEnd()); } } } diff --git a/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs b/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs index 008c1407..623ccb8f 100644 --- a/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs +++ b/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs @@ -181,6 +181,11 @@ public class JCS_DialogueSystem : MonoBehaviour /* Setter & Getter */ + public bool Active { get { return this.mActive; } } + public bool Scrolling { get { return this.mScrolling; } } + public bool ScrollingSelectBtnText { get { return this.mScrollingSelectBtnText; } } + public bool Skip { get { return this.mSkip; } } + public bool MakeHoverSelect { get { return this.mMakeHoverSelect; } set { this.mMakeHoverSelect = value; } } public JCS_DeltaTimeType DeltaTimeType { get { return this.mDeltaTimeType; } set { this.mDeltaTimeType = value; } } public JCS_DialogueScript DialogueScript { get { return this.mDialogueScript; } set { this.mDialogueScript = value; } } @@ -236,7 +241,7 @@ public void ActiveDialogue(JCS_DialogueScript script) if (mActive) { - JCS_Debug.LogError("Dialogue System is already active... Failed to active another one."); + JCS_Debug.LogError("Dialogue System is already active!"); return; } @@ -484,7 +489,6 @@ public void Dispose() // disable the exit button! ExitBtnActive(false); - // dis-attach the script. mDialogueScript = null; @@ -556,7 +560,7 @@ public void SendNameTag(string name) #if UNITY_EDITOR if (mNameTag == null) { - JCS_Debug.LogError("Name tag is not assign but u still trying to access?"); + JCS_Debug.LogError("Name tag doesn't exist!"); return; } #endif @@ -575,7 +579,7 @@ public void SendCenterImage(Sprite sprite) #if UNITY_EDITOR if (mCenterImage == null) { - JCS_Debug.LogError("Center image call with image component attached"); + JCS_Debug.LogError("Image (center) doesn't exist"); return; } #endif @@ -593,7 +597,7 @@ public void SendLeftImage(Sprite sprite) #if UNITY_EDITOR if (mLeftImage == null) { - JCS_Debug.LogError("Left image call with image component attached"); + JCS_Debug.LogError("Image (left) doesn't exist"); return; } #endif @@ -611,7 +615,7 @@ public void SendRightImage(Sprite sprite) #if UNITY_EDITOR if (mRightImage == null) { - JCS_Debug.LogError("Right image call with image component attached"); + JCS_Debug.LogError("Image (right) doesn't exist"); return; } #endif @@ -649,6 +653,29 @@ public void NextOrDispose() Dispose(); } + /// + /// Return true if the dialogue system is still animating the text. + /// + public bool IsScrolling() + { + return this.mScrolling || this.mScrollingSelectBtnText; + } + + /// + /// Skip the current text scroll. + /// + public bool SkipToEnd() + { + if (IsScrolling()) + { + mSkip = true; + + return true; + } + + return false; + } + /// /// Do scroll text action. /// @@ -667,7 +694,7 @@ private void ScrollText() return; // reset timer - mScrollTimer = 0; + mScrollTimer = 0.0f; if (mMessage == mTextBox.text) { @@ -684,6 +711,7 @@ private void ScrollText() // reset text index counter mTextIndex = 0; + return; } @@ -692,6 +720,9 @@ private void ScrollText() // set directly to the text box. mTextBox.text = mMessage; + // set the rest to the selections. + CompleteSelectionsScroll(); + mSkip = false; // end effect. @@ -723,7 +754,7 @@ private void ScrollSelectBtnText() return; // reset timer - mScrollTimer = 0; + mScrollTimer = 0.0f; if (mSelectBtn.Length <= mRenderSelectTextIndex) { @@ -736,7 +767,6 @@ private void ScrollSelectBtnText() return; } - if (// if the text in not active skip it, and render the // next possible active selection. !mSelectBtn[mRenderSelectTextIndex].gameObject.activeSelf @@ -760,9 +790,8 @@ private void ScrollSelectBtnText() if (mSkip) { - // set directly to the text box. - mSelectBtn[mRenderSelectTextIndex].ButtonText.text - = mSelectMessage[mRenderSelectTextIndex]; + // set the rest to the selections. + CompleteSelectionsScroll(); mSkip = false; @@ -780,6 +809,17 @@ private void ScrollSelectBtnText() ++mSelectTextIndex; } + /// + /// Complete the selection scroll text immediately. + /// + private void CompleteSelectionsScroll() + { + for (int index = mRenderSelectTextIndex; index < mSelectBtn.Length; ++index) + { + mSelectBtn[index].ButtonText.text = mSelectMessage[index]; + } + } + /// /// Active the panel? /// @@ -1089,7 +1129,6 @@ private int FindSelectedButton() return -1; } - /// /// What if "Next Button" clicked? ///