From f654d7f93cfece172ccc6ec187dd6cee9a6b46b0 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Tue, 6 Aug 2024 06:04:56 -0700 Subject: [PATCH] feat(UI): Add auto progress --- .../UI/JCS_DialogueSystem (Game Pad).prefab | 8 ++- .../Resources/UI/JCS_DialogueSystem.prefab | 8 ++- .../Scenes/Utilities/JCS_ScriptTester.unity | 10 --- .../Scripts/UI/Dialogue/JCS_DialogueSystem.cs | 70 +++++++++++++++---- .../UI/Dialogue/JCS_DialogueSystem.md | 6 +- 5 files changed, 71 insertions(+), 31 deletions(-) diff --git a/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem (Game Pad).prefab b/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem (Game Pad).prefab index feae8646..a3458800 100644 --- a/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem (Game Pad).prefab +++ b/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem (Game Pad).prefab @@ -4124,7 +4124,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &764007139224113502 RectTransform: m_ObjectHideFlags: 0 @@ -4237,8 +4237,6 @@ MonoBehaviour: mRightImage: {fileID: 6393945804426866846} mNameTag: {fileID: 7830457409021631893} mTextBox: {fileID: 4721417465960552238} - mCompleteTextBeforeAction: 0 - mCompleteTextBeforeActionOnButton: 0 mScrollTime: 0.01 mDeltaTimeType: 0 mPanelTrans: {fileID: 0} @@ -4258,6 +4256,10 @@ MonoBehaviour: - {fileID: 7296028875851633172} - {fileID: 8791215142036938067} mButtonSelectionGroup: {fileID: 5080200581021259784} + mCompleteTextBeforeAction: 0 + mCompleteTextBeforeActionOnButton: 0 + mAutoProgress: 0 + mAutoDelay: 2 mActiveSound: {fileID: 8300000, guid: 4913222f00b7466419656d01e8bae9d6, type: 3} mDisposeSound: {fileID: 8300000, guid: ffcf3906540e3b74fa27dc938e19d461, type: 3} --- !u!1 &7811244761158602352 diff --git a/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem.prefab b/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem.prefab index 4e0fd04a..2eea8739 100644 --- a/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem.prefab +++ b/Assets/JCSUnity/Resources/UI/JCS_DialogueSystem.prefab @@ -2338,7 +2338,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &984955064616139632 RectTransform: m_ObjectHideFlags: 0 @@ -2451,8 +2451,6 @@ MonoBehaviour: mRightImage: {fileID: 6546777816282174048} mNameTag: {fileID: 827766543013699587} mTextBox: {fileID: 6267707290331941680} - mCompleteTextBeforeAction: 0 - mCompleteTextBeforeActionOnButton: 0 mScrollTime: 0.01 mDeltaTimeType: 0 mPanelTrans: {fileID: 0} @@ -2472,6 +2470,10 @@ MonoBehaviour: - {fileID: 526192977114094584} - {fileID: 7604726519187752915} mButtonSelectionGroup: {fileID: 1527436958594954669} + mCompleteTextBeforeAction: 0 + mCompleteTextBeforeActionOnButton: 0 + mAutoProgress: 0 + mAutoDelay: 2 mActiveSound: {fileID: 0} mDisposeSound: {fileID: 0} --- !u!1 &4528894428773322394 diff --git a/Assets/JCSUnity/Scenes/Utilities/JCS_ScriptTester.unity b/Assets/JCSUnity/Scenes/Utilities/JCS_ScriptTester.unity index 33e357b9..20ec22dc 100644 --- a/Assets/JCSUnity/Scenes/Utilities/JCS_ScriptTester.unity +++ b/Assets/JCSUnity/Scenes/Utilities/JCS_ScriptTester.unity @@ -1290,11 +1290,6 @@ PrefabInstance: propertyPath: m_Name value: JCS_DialogueSystem (Game Pad) objectReference: {fileID: 0} - - target: {fileID: 7657870147620464614, guid: c7ea891da8aadd741a2b75f708a50d65, - type: 3} - propertyPath: m_IsActive - value: 0 - objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] @@ -1413,11 +1408,6 @@ PrefabInstance: propertyPath: m_Name value: JCS_DialogueSystem objectReference: {fileID: 0} - - target: {fileID: 4431048296620540127, guid: 11e5c739135b1e34d8a1164d3c66f6f8, - type: 3} - propertyPath: m_IsActive - value: 0 - objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] diff --git a/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs b/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs index 64cc1f44..98912371 100644 --- a/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs +++ b/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs @@ -111,14 +111,6 @@ public class JCS_DialogueSystem : MonoBehaviour [SerializeField] private JCS_TextObject mTextBox = null; - [Tooltip("Complete text before run action.")] - [SerializeField] - private bool mCompleteTextBeforeAction = false; - - [Tooltip("Complete text before run action on button's event.")] - [SerializeField] - private bool mCompleteTextBeforeActionOnButton = false; - [Tooltip("Speed of scrolling the text.")] [SerializeField] [Range(0.01f, 10.0f)] @@ -175,13 +167,36 @@ public class JCS_DialogueSystem : MonoBehaviour private string mSelectStringFront = "#L" + 0 + "##b"; private string mSelectStringBack = "#k#l"; - [Header("- Optional Variables")] + [Header("Controller")] [Tooltip("Button selection group for this dialogue system.")] [SerializeField] private JCS_ButtonSelectionGroup mButtonSelectionGroup = null; - [Header("- Sound")] + [Header("Completing")] + + [Tooltip("Complete text before run action.")] + [SerializeField] + private bool mCompleteTextBeforeAction = false; + + [Tooltip("Complete text before run action on button's event.")] + [SerializeField] + private bool mCompleteTextBeforeActionOnButton = false; + + [Header("Auto")] + + [Tooltip("If true, auto progress the dialgoue.")] + [SerializeField] + private bool mAutoProgress = false; + + [Tooltip("Delay before start the next text popup.")] + [SerializeField] + [Range(0.0f, 30.0f)] + private float mAutoDelay = 2.0f; + + private float mAutoTimer = 0.0f; + + [Header("Sound")] [Tooltip("Sound plays when active dialogue.")] [SerializeField] @@ -199,14 +214,16 @@ public class JCS_DialogueSystem : MonoBehaviour public bool Skip { get { return this.mSkip; } } public bool MakeHoverSelect { get { return this.mMakeHoverSelect; } set { this.mMakeHoverSelect = value; } } - public bool CompleteTextBeforeAction { get { return this.mCompleteTextBeforeAction; } set { this.mCompleteTextBeforeAction = value; } } - public bool CompleteTextBeforeActionOnButton { get { return this.mCompleteTextBeforeActionOnButton; } set { this.mCompleteTextBeforeActionOnButton = 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; } } public string SelectStringFront { get { return this.mSelectStringFront; } } public string SelectStringBack { get { return this.mSelectStringBack; } } - public JCS_ButtonSelectionGroup ButtonSelectionGroup { get { return this.mButtonSelectionGroup; } set { this.mButtonSelectionGroup = value; } } + public JCS_ButtonSelectionGroup ButtonSelectionGroup { get { return this.mButtonSelectionGroup; } set { this.mButtonSelectionGroup = value; } } + public bool CompleteTextBeforeAction { get { return this.mCompleteTextBeforeAction; } set { this.mCompleteTextBeforeAction = value; } } + public bool CompleteTextBeforeActionOnButton { get { return this.mCompleteTextBeforeActionOnButton; } set { this.mCompleteTextBeforeActionOnButton = value; } } + public bool AutoProgress { get { return this.mAutoProgress; } set { this.mAutoProgress = value; } } + public float AutoDelay { get { return this.AutoDelay; } set { this.mAutoDelay = value; } } public AudioClip AcitveSound { get { return this.mActiveSound; } set { this.mActiveSound = value; } } public AudioClip DisposeSound { get { return this.mDisposeSound; } set { this.mDisposeSound = value; } } @@ -253,6 +270,8 @@ private void LateUpdate() ScrollSelectBtnText(); + DoAuto(); + mActiveThisFrame = false; } @@ -550,6 +569,9 @@ public void Dispose() /// public void ResetStats() { + mScrollTimer = 0.0f; + mAutoTimer = 0.0f; + mScrolling = false; mSkip = false; mTextIndex = 0; @@ -875,6 +897,28 @@ private void CompleteSelectionsScroll() } } + /// + /// Automatically start the next text popup. + /// + private void DoAuto() + { + if (!mAutoProgress) + return; + + if (IsScrolling()) + return; + + mAutoTimer += JCS_Time.DeltaTime(mDeltaTimeType); + + if (mAutoTimer < mAutoDelay) + return; + + // Reset timer. + mAutoTimer = 0.0f; + + NextOrDispose(); + } + /// /// Active the panel? /// diff --git a/docs/ScriptReference/UI/Dialogue/JCS_DialogueSystem.md b/docs/ScriptReference/UI/Dialogue/JCS_DialogueSystem.md index c8aea405..680ca852 100644 --- a/docs/ScriptReference/UI/Dialogue/JCS_DialogueSystem.md +++ b/docs/ScriptReference/UI/Dialogue/JCS_DialogueSystem.md @@ -8,14 +8,16 @@ Dialogue system core implementation. |:----------------------------------|:---------------------------------------------------| | onDispose | Callback when successfully dispose the dialogue. | | mMakeHoverSelect | If the mouse hover then select the selection. | -| mCompleteTextBeforeAction | Complete text before run action. | -| mCompleteTextBeforeActionOnButton | Complete text before run action on button's event. | | mCenterImage | Image displayed at the center. | | mLeftImage | Image displayed at the left. | | mRightImage | Image displayed at the right. | | mNameTag | Current name tag. | | mScrollTime | Speed of scrolling the text. | | mButtonSelectionGroup | Make control from the gamepad. | +| mCompleteTextBeforeAction | Complete text before run action. | +| mCompleteTextBeforeActionOnButton | Complete text before run action on button's event. | +| mAutoProgress | If true, auto progress the dialgoue. | +| mAutoDelay | Delay before start the next text popup. | | mActiveSound | Sound plays when active dialogue. | | mDisposeSound | Sound plays when dispose dialogue. |