Skip to content

Commit

Permalink
feat(TextSlider): Add text slider component
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Sep 3, 2022
1 parent a0b4d0c commit eb3ab41
Show file tree
Hide file tree
Showing 9 changed files with 1,008 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/UI/JCS_Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace JCSUnity
{
/// <summary>
/// Buttton Interface (NGUI)
/// Buttton Interface (uGUI)
/// </summary>
[RequireComponent(typeof(RectTransform))]
[RequireComponent(typeof(Button))]
Expand Down
61 changes: 61 additions & 0 deletions Assets/JCSUnity/Scripts/UI/JCS_TextObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* $File: JCS_TextObject.cs $
* $Date: 2022-09-04 01:14:38 $
* $Revision: $
* $Creator: Jen-Chieh Shen $
* $Notice: See LICENSE.txt for modification and distribution information
* Copyright © 2022 by Shen, Jen-Chieh $
*/

/* NOTE: If you are using `TextMesh Pro` uncomment this line.
*/
#define TMP_PRO

using UnityEngine;
using UnityEngine.UI;

#if TMP_PRO
using TMPro;
#endif

namespace JCSUnity
{
/// <summary>
/// Holds all type of UI text objects.
/// </summary>
public class JCS_TextObject : MonoBehaviour
{
/* Variables */

[Header("** Initialize Variables (JCS_TextObject) **")]

[Tooltip("Target text renderer.")]
[SerializeField]
private Text mTextContainer = null;

#if TMP_PRO
[Tooltip("Target text renderer. (TMP)")]
[SerializeField]
private TextMeshPro mTextMesh = null;
#endif

/* Setter & Getter */

public Text TextContainer { get { return this.mTextContainer; } set { this.mTextContainer = value; } }
#if TMP_PRO
public TextMeshPro TextMesh { get { return this.mTextMesh; } set { this.mTextMesh = value; } }
#endif

/* Functions */

public string text
{
get { return this.mTextContainer.text; } // just return one of them
set
{
if (this.mTextContainer) this.mTextContainer.text = value;
if (this.mTextMesh) this.mTextMesh.text = value;
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/JCSUnity/Scripts/UI/JCS_TextObject.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Assets/JCSUnity/Scripts/UI/Text/JCS_TextAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class JCS_TextAnimation : MonoBehaviour
[SerializeField]
private int mCurrentFrame = 0;


[Header("** Initialize Variables (JCS_TextAnimation) **")]

[Tooltip("Target text renderer.")]
Expand Down
39 changes: 39 additions & 0 deletions Assets/JCSUnity/Scripts/UI/Text/JCS_TextSliderDisplay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* $File: JCS_TextSliderDisplay.cs $
* $Date: 2022-09-04 01:10:40 $
* $Revision: $
* $Creator: Jen-Chieh Shen $
* $Notice: See LICENSE.txt for modification and distribution information
* Copyright © 2022 by Shen, Jen-Chieh $
*/
using UnityEngine;
using UnityEngine.UI;

namespace JCSUnity
{
/// <summary>
/// Text that display slider's value.
/// </summary>
public class JCS_TextSliderDisplay : JCS_TextObject
{
/* Variables */

[Header("** Initialize Variables (JCS_TextSliderDisplay) **")]

[Tooltip("To update the text along with this slider's value.")]
[SerializeField]
private Slider mSlider = null;

/* Setter & Getter */

/* Functions */

private void Update()
{
if (mSlider == null)
return;

this.text = mSlider.value.ToString();
}
}
}
11 changes: 11 additions & 0 deletions Assets/JCSUnity/Scripts/UI/Text/JCS_TextSliderDisplay.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eb3ab41

Please sign in to comment.