Skip to content

Commit

Permalink
feat(UI): Compatible to text mesh's button
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Sep 11, 2024
1 parent 8e13fbe commit b1990ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
10 changes: 5 additions & 5 deletions Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -952,7 +952,7 @@ private void ScrollSelectBtnText()
else
{
// do the scrolling
mSelectBtn[mRenderSelectTextIndex].ButtonText.text
mSelectBtn[mRenderSelectTextIndex].ItText.text
= mSelectMessage[mRenderSelectTextIndex].Substring(0, mSelectTextIndex);
}

Expand All @@ -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];
}
}

Expand Down Expand Up @@ -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 = "";
}
}

Expand Down
22 changes: 18 additions & 4 deletions Assets/JCSUnity/Scripts/UI/JCS_Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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; } }

Expand Down Expand Up @@ -145,8 +154,13 @@ public void Init(bool forceInit = false)
this.mImage = this.GetComponent<Image>();

// try to get the text from the child.
if (mButtonText == null)
mButtonText = this.GetComponentInChildren<Text>();
if (mItText != null)
{
if (mItText.TextContainer == null)
mItText.TextContainer = this.GetComponentInChildren<Text>();
if (mItText.TMP_Text == null)
mItText.TMP_Text = this.GetComponentInChildren<TMP_Text>();
}

if (mAutoListener)
{
Expand Down

0 comments on commit b1990ab

Please sign in to comment.