From b1990abf4b1c3353694d4c3e34b64b9b2ed04d6c Mon Sep 17 00:00:00 2001 From: JenChieh Date: Wed, 11 Sep 2024 02:14:57 -0700 Subject: [PATCH] feat(UI): Compatible to text mesh's button --- .../Scripts/UI/Dialogue/JCS_DialogueSystem.cs | 10 ++++----- Assets/JCSUnity/Scripts/UI/JCS_Button.cs | 22 +++++++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs b/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs index ea98e3ca..35053725 100644 --- a/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs +++ b/Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs @@ -924,10 +924,10 @@ private void ScrollSelectBtnText() || // if the text are the same skip it too. (mSelectMessage[mRenderSelectTextIndex] == - mSelectBtn[mRenderSelectTextIndex].ButtonText.text)) + mSelectBtn[mRenderSelectTextIndex].ItText.text)) { // set directly to the text box. - mSelectBtn[mRenderSelectTextIndex].ButtonText.text + mSelectBtn[mRenderSelectTextIndex].ItText.text = mSelectMessage[mRenderSelectTextIndex]; // increament one, start render next selection! @@ -952,7 +952,7 @@ private void ScrollSelectBtnText() else { // do the scrolling - mSelectBtn[mRenderSelectTextIndex].ButtonText.text + mSelectBtn[mRenderSelectTextIndex].ItText.text = mSelectMessage[mRenderSelectTextIndex].Substring(0, mSelectTextIndex); } @@ -967,7 +967,7 @@ private void CompleteSelectionsScroll() { for (int index = mRenderSelectTextIndex; index < mSelectBtn.Length; ++index) { - mSelectBtn[index].ButtonText.text = mSelectMessage[index]; + mSelectBtn[index].ItText.text = mSelectMessage[index]; } } @@ -1163,7 +1163,7 @@ private void ClearSelectBtnMessage() for (int index = 0; index < mSelectMessage.Length; ++index) { mSelectMessage[index] = ""; - mSelectBtn[index].ButtonText.text = ""; + mSelectBtn[index].ItText.text = ""; } } diff --git a/Assets/JCSUnity/Scripts/UI/JCS_Button.cs b/Assets/JCSUnity/Scripts/UI/JCS_Button.cs index 8915389c..be738126 100644 --- a/Assets/JCSUnity/Scripts/UI/JCS_Button.cs +++ b/Assets/JCSUnity/Scripts/UI/JCS_Button.cs @@ -6,10 +6,19 @@ * $Notice: See LICENSE.txt for modification and distribution information * Copyright (c) 2016 by Shen, Jen-Chieh $ */ + +/* NOTE: If you are using `TextMesh Pro` uncomment this line. + */ +#define TMP_PRO + using UnityEngine; using UnityEngine.UI; using MyBox; +#if TMP_PRO +using TMPro; +#endif + namespace JCSUnity { /// @@ -49,7 +58,7 @@ public abstract class JCS_Button : MonoBehaviour [Tooltip("text under the button, no necessary.")] [SerializeField] - protected Text mButtonText = null; + protected JCS_TextObject mItText = null; [Tooltip("Button Selection for if the button that are in the group.")] [SerializeField] @@ -105,7 +114,7 @@ public bool Interactable SetInteractable(); } } - public Text ButtonText { get { return this.mButtonText; } } + public JCS_TextObject ItText { get { return this.mItText; } } public JCS_ButtonSelection ButtonSelection { get { return this.mButtonSelection; } set { this.mButtonSelection = value; } } public bool IsSelectedInGroup { get { return this.mIsSelectedInGroup; } } @@ -145,8 +154,13 @@ public void Init(bool forceInit = false) this.mImage = this.GetComponent(); // try to get the text from the child. - if (mButtonText == null) - mButtonText = this.GetComponentInChildren(); + if (mItText != null) + { + if (mItText.TextContainer == null) + mItText.TextContainer = this.GetComponentInChildren(); + if (mItText.TMP_Text == null) + mItText.TMP_Text = this.GetComponentInChildren(); + } if (mAutoListener) {