The BIG Unity 2022 Text reorganisation
parent
1002db24f2
commit
8d18515a4a
|
@ -5,7 +5,11 @@
|
||||||
namespace UnityEngine.UI.Extensions.ColorPicker
|
namespace UnityEngine.UI.Extensions.ColorPicker
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
[RequireComponent(typeof(TMPro.TMP_Text))]
|
||||||
|
#else
|
||||||
[RequireComponent(typeof(Text))]
|
[RequireComponent(typeof(Text))]
|
||||||
|
#endif
|
||||||
public class ColorLabel : MonoBehaviour
|
public class ColorLabel : MonoBehaviour
|
||||||
{
|
{
|
||||||
public ColorPickerControl picker;
|
public ColorPickerControl picker;
|
||||||
|
@ -18,12 +22,18 @@ namespace UnityEngine.UI.Extensions.ColorPicker
|
||||||
|
|
||||||
public int precision = 0;
|
public int precision = 0;
|
||||||
|
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
private TMPro.TMP_Text label;
|
||||||
|
#else
|
||||||
private Text label;
|
private Text label;
|
||||||
|
#endif
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
label = GetComponent<TMPro.TMP_Text>();
|
||||||
|
#else
|
||||||
label = GetComponent<Text>();
|
label = GetComponent<Text>();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
|
@ -47,7 +57,11 @@ namespace UnityEngine.UI.Extensions.ColorPicker
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
private void OnValidate()
|
private void OnValidate()
|
||||||
{
|
{
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
label = GetComponent<TMPro.TMP_Text>();
|
||||||
|
#else
|
||||||
label = GetComponent<Text>();
|
label = GetComponent<Text>();
|
||||||
|
#endif
|
||||||
UpdateValue();
|
UpdateValue();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -299,8 +299,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (i < AvailableOptions.Count)
|
if (i < AvailableOptions.Count)
|
||||||
{
|
{
|
||||||
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
|
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
itemObjs[i].transform.Find("Text").GetComponent<TMPro.TMP_Text>().text = AvailableOptions[i]; //set the text value
|
||||||
|
#else
|
||||||
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
|
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
|
||||||
|
#endif
|
||||||
Button itemBtn = itemObjs[i].GetComponent<Button>();
|
Button itemBtn = itemObjs[i].GetComponent<Button>();
|
||||||
itemBtn.onClick.RemoveAllListeners();
|
itemBtn.onClick.RemoveAllListeners();
|
||||||
string textOfItem = _panelItems[i]; //has to be copied for anonymous function or it gets garbage collected away
|
string textOfItem = _panelItems[i]; //has to be copied for anonymous function or it gets garbage collected away
|
||||||
|
|
|
@ -213,8 +213,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (i < AvailableOptions.Count)
|
if (i < AvailableOptions.Count)
|
||||||
{
|
{
|
||||||
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
|
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
itemObjs[i].transform.Find("Text").GetComponent<TMPro.TMP_Text>().text = AvailableOptions[i]; //set the text value
|
||||||
|
#else
|
||||||
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
|
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
|
||||||
|
#endif
|
||||||
Button itemBtn = itemObjs[i].GetComponent<Button>();
|
Button itemBtn = itemObjs[i].GetComponent<Button>();
|
||||||
itemBtn.onClick.RemoveAllListeners();
|
itemBtn.onClick.RemoveAllListeners();
|
||||||
string textOfItem = _panelItems[i]; //has to be copied for anonymous function or it gets garbage collected away
|
string textOfItem = _panelItems[i]; //has to be copied for anonymous function or it gets garbage collected away
|
||||||
|
|
|
@ -5,7 +5,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
public class ReorderableListDebug : MonoBehaviour
|
public class ReorderableListDebug : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
public TMPro.TMP_Text DebugLabel;
|
||||||
|
#else
|
||||||
public Text DebugLabel;
|
public Text DebugLabel;
|
||||||
|
#endif
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
/// Credit David Gileadi
|
/// Credit David Gileadi
|
||||||
/// Sourced from - https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/pull-requests/12
|
/// Sourced from - https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/pull-requests/12
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using UnityEngine.Events;
|
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
|
@ -205,7 +203,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
void ChangeTextColor(Color targetColor)
|
void ChangeTextColor(Color targetColor)
|
||||||
{
|
{
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
var text = GetComponentInChildren<TMPro.TMP_Text>();
|
||||||
|
#else
|
||||||
var text = GetComponentInChildren<Text>();
|
var text = GetComponentInChildren<Text>();
|
||||||
|
#endif
|
||||||
if (!text)
|
if (!text)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -40,13 +40,21 @@ namespace UnityEngine.UI.Extensions
|
||||||
//We want the test object to be either a UI element, a 2D element or a 3D element, so we'll get the appropriate components
|
//We want the test object to be either a UI element, a 2D element or a 3D element, so we'll get the appropriate components
|
||||||
SpriteRenderer spriteRenderer;
|
SpriteRenderer spriteRenderer;
|
||||||
Image image;
|
Image image;
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
TMPro.TMP_Text text;
|
||||||
|
#else
|
||||||
Text text;
|
Text text;
|
||||||
|
#endif
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
spriteRenderer = transform.GetComponent<SpriteRenderer>();
|
spriteRenderer = transform.GetComponent<SpriteRenderer>();
|
||||||
image = transform.GetComponent<Image>();
|
image = transform.GetComponent<Image>();
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
text = transform.GetComponent<TMPro.TMP_Text>();
|
||||||
|
#else
|
||||||
text = transform.GetComponent<Text>();
|
text = transform.GetComponent<Text>();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
|
@ -86,8 +94,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
GetComponent<UnityEngine.Renderer>().material.color = color;
|
GetComponent<UnityEngine.Renderer>().material.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,12 @@ namespace UnityEngine.UI.Extensions {
|
||||||
[AddComponentMenu("UI/Extensions/TextPic")]
|
[AddComponentMenu("UI/Extensions/TextPic")]
|
||||||
|
|
||||||
[ExecuteInEditMode] // Needed for culling images that are not used //
|
[ExecuteInEditMode] // Needed for culling images that are not used //
|
||||||
public class TextPic : Text, IPointerClickHandler, IPointerExitHandler, IPointerEnterHandler, ISelectHandler {
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
public class TextPic : TMPro.TMP_Text, IPointerClickHandler, IPointerExitHandler, IPointerEnterHandler, ISelectHandler
|
||||||
|
#else
|
||||||
|
public class TextPic : Text, IPointerClickHandler, IPointerExitHandler, IPointerEnterHandler, ISelectHandler
|
||||||
|
#endif
|
||||||
|
{
|
||||||
// Icon entry to replace text with
|
// Icon entry to replace text with
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public struct IconName {
|
public struct IconName {
|
||||||
|
@ -465,14 +470,21 @@ namespace UnityEngine.UI.Extensions {
|
||||||
/// UNITY METHODS ///
|
/// UNITY METHODS ///
|
||||||
|
|
||||||
protected override void OnPopulateMesh(VertexHelper toFill) {
|
protected override void OnPopulateMesh(VertexHelper toFill) {
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
originalText = text;
|
||||||
|
text = GetOutputText();
|
||||||
|
base.OnPopulateMesh(toFill);
|
||||||
|
|
||||||
|
text = originalText;
|
||||||
|
#else
|
||||||
originalText = m_Text;
|
originalText = m_Text;
|
||||||
m_Text = GetOutputText();
|
m_Text = GetOutputText();
|
||||||
|
|
||||||
base.OnPopulateMesh(toFill);
|
base.OnPopulateMesh(toFill);
|
||||||
|
|
||||||
m_DisableFontTextureRebuiltCallback = true;
|
m_DisableFontTextureRebuiltCallback = true;
|
||||||
|
|
||||||
m_Text = originalText;
|
m_Text = originalText;
|
||||||
|
#endif
|
||||||
|
|
||||||
positions.Clear();
|
positions.Clear();
|
||||||
|
|
||||||
|
@ -539,8 +551,10 @@ namespace UnityEngine.UI.Extensions {
|
||||||
// Update the quad images
|
// Update the quad images
|
||||||
updateQuad = true;
|
updateQuad = true;
|
||||||
|
|
||||||
|
#if !UNITY_2022_1_OR_NEWER
|
||||||
m_DisableFontTextureRebuiltCallback = false;
|
m_DisableFontTextureRebuiltCallback = false;
|
||||||
}
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Click event is detected whether to click a hyperlink text
|
/// Click event is detected whether to click a hyperlink text
|
||||||
|
@ -641,7 +655,7 @@ namespace UnityEngine.UI.Extensions {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected override void OnEnable() {
|
protected override void OnEnable() {
|
||||||
#if UNITY_2019_1_OR_NEWER
|
#if UNITY_2019_1_OR_NEWER
|
||||||
// Here is the hack to see if Unity is using the new rendering system for text
|
// Here is the hack to see if Unity is using the new rendering system for text
|
||||||
usesNewRendering = false;
|
usesNewRendering = false;
|
||||||
|
|
||||||
|
@ -660,13 +674,14 @@ namespace UnityEngine.UI.Extensions {
|
||||||
else {
|
else {
|
||||||
usesNewRendering = true;
|
usesNewRendering = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
|
|
||||||
|
#if !UNITY_2022_1_OR_NEWER
|
||||||
supportRichText = true;
|
supportRichText = true;
|
||||||
alignByGeometry = true;
|
alignByGeometry = true;
|
||||||
|
#endif
|
||||||
// Enable images on TextPic disable
|
// Enable images on TextPic disable
|
||||||
if (m_ImagesPool.Count >= 1) {
|
if (m_ImagesPool.Count >= 1) {
|
||||||
for (int i = 0; i < m_ImagesPool.Count; i++) {
|
for (int i = 0; i < m_ImagesPool.Count; i++) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
/// Credit Melang
|
/// Credit Melang
|
||||||
/// Sourced from - http://forum.unity3d.com/members/melang.593409/
|
/// Sourced from - http://forum.unity3d.com/members/melang.593409/
|
||||||
|
/// NOT supported in Unity 2022
|
||||||
|
|
||||||
|
#if !UNITY_2022_1_OR_NEWER
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
|
@ -60,3 +62,4 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
|
@ -4,14 +4,24 @@
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
[RequireComponent(typeof(RectTransform))]
|
[RequireComponent(typeof(RectTransform))]
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
[RequireComponent(typeof(TMPro.TMP_Text))]
|
||||||
|
#else
|
||||||
[RequireComponent(typeof(Text))]
|
[RequireComponent(typeof(Text))]
|
||||||
|
#endif
|
||||||
[AddComponentMenu("UI/Effects/Extensions/Curly UI Text")]
|
[AddComponentMenu("UI/Effects/Extensions/Curly UI Text")]
|
||||||
public class CUIText : CUIGraphic
|
public class CUIText : CUIGraphic
|
||||||
{
|
{
|
||||||
public override void ReportSet()
|
public override void ReportSet()
|
||||||
{
|
{
|
||||||
if (uiGraphic == null)
|
if (uiGraphic == null)
|
||||||
|
{
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
uiGraphic = GetComponent<TMPro.TMP_Text>();
|
||||||
|
#else
|
||||||
uiGraphic = GetComponent<Text>();
|
uiGraphic = GetComponent<Text>();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
base.ReportSet();
|
base.ReportSet();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,12 @@
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
[RequireComponent(typeof(Text), typeof(RectTransform))]
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
[RequireComponent(typeof(TMPro.TMP_Text))]
|
||||||
|
#else
|
||||||
|
[RequireComponent(typeof(Text))]
|
||||||
|
#endif
|
||||||
|
[RequireComponent(typeof(RectTransform))]
|
||||||
[AddComponentMenu("UI/Effects/Extensions/Curved Text")]
|
[AddComponentMenu("UI/Effects/Extensions/Curved Text")]
|
||||||
public class CurvedText : BaseMeshEffect
|
public class CurvedText : BaseMeshEffect
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,12 @@
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
[RequireComponent(typeof(Text), typeof(RectTransform))]
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
[RequireComponent(typeof(TMPro.TMP_Text))]
|
||||||
|
#else
|
||||||
|
[RequireComponent(typeof(Text))]
|
||||||
|
#endif
|
||||||
|
[RequireComponent(typeof(RectTransform))]
|
||||||
[AddComponentMenu("UI/Effects/Extensions/Cylinder Text")]
|
[AddComponentMenu("UI/Effects/Extensions/Cylinder Text")]
|
||||||
public class CylinderText : BaseMeshEffect
|
public class CylinderText : BaseMeshEffect
|
||||||
{
|
{
|
||||||
|
|
|
@ -81,8 +81,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
List<UIVertex> verts = new List<UIVertex>();
|
List<UIVertex> verts = new List<UIVertex>();
|
||||||
vh.GetUIVertexStream(verts);
|
vh.GetUIVertexStream(verts);
|
||||||
|
|
||||||
Text text = GetComponent<Text>();
|
#if UNITY_2022_1_OR_NEWER
|
||||||
if (text == null)
|
var text = GetComponent<TMPro.TMP_Text>();
|
||||||
|
#else
|
||||||
|
var text = GetComponent<Text>();
|
||||||
|
#endif
|
||||||
|
if (text == null)
|
||||||
{
|
{
|
||||||
Debug.LogWarning("LetterSpacing: Missing Text component");
|
Debug.LogWarning("LetterSpacing: Missing Text component");
|
||||||
return;
|
return;
|
||||||
|
@ -94,28 +98,51 @@ namespace UnityEngine.UI.Extensions
|
||||||
float alignmentFactor = 0;
|
float alignmentFactor = 0;
|
||||||
int glyphIdx = 0;
|
int glyphIdx = 0;
|
||||||
|
|
||||||
switch (text.alignment)
|
#if UNITY_2022_1_OR_NEWER
|
||||||
{
|
switch (text.alignment)
|
||||||
case TextAnchor.LowerLeft:
|
{
|
||||||
case TextAnchor.MiddleLeft:
|
case TMPro.TextAlignmentOptions.BottomLeft:
|
||||||
case TextAnchor.UpperLeft:
|
case TMPro.TextAlignmentOptions.MidlineLeft:
|
||||||
alignmentFactor = 0f;
|
case TMPro.TextAlignmentOptions.TopLeft:
|
||||||
break;
|
alignmentFactor = 0f;
|
||||||
|
break;
|
||||||
|
|
||||||
case TextAnchor.LowerCenter:
|
case TMPro.TextAlignmentOptions.BottomJustified:
|
||||||
case TextAnchor.MiddleCenter:
|
case TMPro.TextAlignmentOptions.MidlineJustified:
|
||||||
case TextAnchor.UpperCenter:
|
case TMPro.TextAlignmentOptions.TopJustified:
|
||||||
alignmentFactor = 0.5f;
|
alignmentFactor = 0.5f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TextAnchor.LowerRight:
|
case TMPro.TextAlignmentOptions.BottomRight:
|
||||||
case TextAnchor.MiddleRight:
|
case TMPro.TextAlignmentOptions.MidlineRight:
|
||||||
case TextAnchor.UpperRight:
|
case TMPro.TextAlignmentOptions.TopRight:
|
||||||
alignmentFactor = 1f;
|
alignmentFactor = 1f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
switch (text.alignment)
|
||||||
|
{
|
||||||
|
case TextAnchor.LowerLeft:
|
||||||
|
case TextAnchor.MiddleLeft:
|
||||||
|
case TextAnchor.UpperLeft:
|
||||||
|
alignmentFactor = 0f;
|
||||||
|
break;
|
||||||
|
|
||||||
for (int lineIdx=0; lineIdx < lines.Length; lineIdx++)
|
case TextAnchor.LowerCenter:
|
||||||
|
case TextAnchor.MiddleCenter:
|
||||||
|
case TextAnchor.UpperCenter:
|
||||||
|
alignmentFactor = 0.5f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TextAnchor.LowerRight:
|
||||||
|
case TextAnchor.MiddleRight:
|
||||||
|
case TextAnchor.UpperRight:
|
||||||
|
alignmentFactor = 1f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int lineIdx=0; lineIdx < lines.Length; lineIdx++)
|
||||||
{
|
{
|
||||||
string line = lines[lineIdx];
|
string line = lines[lineIdx];
|
||||||
float lineOffset = (line.Length -1) * letterOffset * alignmentFactor;
|
float lineOffset = (line.Length -1) * letterOffset * alignmentFactor;
|
||||||
|
|
|
@ -46,7 +46,11 @@ using System.Collections.Generic;
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
[AddComponentMenu("UI/Effects/Extensions/Mono Spacing")]
|
[AddComponentMenu("UI/Effects/Extensions/Mono Spacing")]
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
[RequireComponent(typeof(TMPro.TMP_Text))]
|
||||||
|
#else
|
||||||
[RequireComponent(typeof(Text))]
|
[RequireComponent(typeof(Text))]
|
||||||
|
#endif
|
||||||
[RequireComponent(typeof(RectTransform))]
|
[RequireComponent(typeof(RectTransform))]
|
||||||
///Summary
|
///Summary
|
||||||
/// Note, Vertex Count has changed in 5.2.1+, is now 6 (two tris) instead of 4 (tri strip).
|
/// Note, Vertex Count has changed in 5.2.1+, is now 6 (two tris) instead of 4 (tri strip).
|
||||||
|
@ -58,13 +62,21 @@ namespace UnityEngine.UI.Extensions
|
||||||
public bool UseHalfCharWidth = false;
|
public bool UseHalfCharWidth = false;
|
||||||
|
|
||||||
private RectTransform rectTransform;
|
private RectTransform rectTransform;
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
private TMPro.TMP_Text text;
|
||||||
|
#else
|
||||||
private Text text;
|
private Text text;
|
||||||
|
#endif
|
||||||
|
|
||||||
protected MonoSpacing() { }
|
protected MonoSpacing() { }
|
||||||
|
|
||||||
protected override void Awake()
|
protected override void Awake()
|
||||||
{
|
{
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
text = GetComponent<TMPro.TMP_Text>();
|
||||||
|
#else
|
||||||
text = GetComponent<Text>();
|
text = GetComponent<Text>();
|
||||||
|
#endif
|
||||||
if (text == null)
|
if (text == null)
|
||||||
{
|
{
|
||||||
Debug.LogWarning("MonoSpacing: Missing Text component");
|
Debug.LogWarning("MonoSpacing: Missing Text component");
|
||||||
|
@ -105,28 +117,50 @@ namespace UnityEngine.UI.Extensions
|
||||||
float alignmentFactor = 0;
|
float alignmentFactor = 0;
|
||||||
int glyphIdx = 0;
|
int glyphIdx = 0;
|
||||||
|
|
||||||
switch (text.alignment)
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
switch (text.alignment)
|
||||||
{
|
{
|
||||||
case TextAnchor.LowerLeft:
|
case TMPro.TextAlignmentOptions.BottomLeft:
|
||||||
case TextAnchor.MiddleLeft:
|
case TMPro.TextAlignmentOptions.MidlineLeft:
|
||||||
case TextAnchor.UpperLeft:
|
case TMPro.TextAlignmentOptions.TopLeft:
|
||||||
alignmentFactor = 0f;
|
alignmentFactor = 0f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TextAnchor.LowerCenter:
|
case TMPro.TextAlignmentOptions.BottomJustified:
|
||||||
case TextAnchor.MiddleCenter:
|
case TMPro.TextAlignmentOptions.MidlineJustified:
|
||||||
case TextAnchor.UpperCenter:
|
case TMPro.TextAlignmentOptions.TopJustified:
|
||||||
alignmentFactor = 0.5f;
|
alignmentFactor = 0.5f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TextAnchor.LowerRight:
|
case TMPro.TextAlignmentOptions.BottomRight:
|
||||||
case TextAnchor.MiddleRight:
|
case TMPro.TextAlignmentOptions.MidlineRight:
|
||||||
case TextAnchor.UpperRight:
|
case TMPro.TextAlignmentOptions.TopRight:
|
||||||
alignmentFactor = 1f;
|
alignmentFactor = 1f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
switch (text.alignment)
|
||||||
|
{
|
||||||
|
case TextAnchor.LowerLeft:
|
||||||
|
case TextAnchor.MiddleLeft:
|
||||||
|
case TextAnchor.UpperLeft:
|
||||||
|
alignmentFactor = 0f;
|
||||||
|
break;
|
||||||
|
|
||||||
for (int lineIdx=0; lineIdx < lines.Length; lineIdx++)
|
case TextAnchor.LowerCenter:
|
||||||
|
case TextAnchor.MiddleCenter:
|
||||||
|
case TextAnchor.UpperCenter:
|
||||||
|
alignmentFactor = 0.5f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TextAnchor.LowerRight:
|
||||||
|
case TextAnchor.MiddleRight:
|
||||||
|
case TextAnchor.UpperRight:
|
||||||
|
alignmentFactor = 1f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
for (int lineIdx=0; lineIdx < lines.Length; lineIdx++)
|
||||||
{
|
{
|
||||||
string line = lines[lineIdx];
|
string line = lines[lineIdx];
|
||||||
float lineOffset = (line.Length - 1) * letterOffset * (alignmentFactor) - (alignmentFactor - 0.5f) * rectTransform.rect.width;
|
float lineOffset = (line.Length - 1) * letterOffset * (alignmentFactor) - (alignmentFactor - 0.5f) * rectTransform.rect.width;
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
/// Credit Melang, Lee Hui
|
/// Credit Melang, Lee Hui
|
||||||
/// Sourced from - http://forum.unity3d.com/members/melang.593409/
|
/// Sourced from - http://forum.unity3d.com/members/melang.593409/
|
||||||
/// GC Alloc fix - https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/pull-requests/130
|
/// GC Alloc fix - https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/pull-requests/130
|
||||||
|
/// NOT supported in Unity 2022
|
||||||
|
|
||||||
|
#if !UNITY_2022_1_OR_NEWER
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
|
@ -193,3 +195,4 @@ namespace UnityEngine.UI.Extensions
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
|
@ -1,4 +1,6 @@
|
||||||
/// Credit NemoKrad (aka Charles Humphrey) / valtain
|
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
/// Credit NemoKrad (aka Charles Humphrey) / valtain
|
||||||
/// Sourced from - http://www.randomchaos.co.uk/SoftAlphaUIMask.aspx
|
/// Sourced from - http://www.randomchaos.co.uk/SoftAlphaUIMask.aspx
|
||||||
/// Updated by valtain - https://bitbucket.org/SimonDarksideJ/unity-ui-extensions/pull-requests/33
|
/// Updated by valtain - https://bitbucket.org/SimonDarksideJ/unity-ui-extensions/pull-requests/33
|
||||||
|
|
||||||
|
@ -45,7 +47,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
MaskArea = GetComponent<RectTransform>();
|
MaskArea = GetComponent<RectTransform>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
var text = GetComponent<TMPro.TMP_Text>();
|
||||||
|
#else
|
||||||
var text = GetComponent<Text>();
|
var text = GetComponent<Text>();
|
||||||
|
#endif
|
||||||
if (text != null)
|
if (text != null)
|
||||||
{
|
{
|
||||||
mat = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/SoftMaskShader"));
|
mat = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/SoftMaskShader"));
|
||||||
|
|
|
@ -210,10 +210,10 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
FocusedElementIndex = i;
|
FocusedElementIndex = i;
|
||||||
#if UNITY_2022_1_OR_NEWER
|
#if UNITY_2022_1_OR_NEWER
|
||||||
var textComponentTxtMeshPro = _arrayOfElements[i].GetComponentInChildren<TMPro.TMP_Text>();
|
var textComponentTxtMeshPro = arrayOfElements[i].GetComponentInChildren<TMPro.TMP_Text>();
|
||||||
if (textComponentTxtMeshPro != null)
|
if (textComponentTxtMeshPro != null)
|
||||||
{
|
{
|
||||||
result = textComponentTxtMeshPro.text;
|
Result = textComponentTxtMeshPro.text;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
var textComponent = arrayOfElements[i].GetComponentInChildren<Text>();
|
var textComponent = arrayOfElements[i].GetComponentInChildren<Text>();
|
||||||
|
|
|
@ -213,10 +213,10 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
FocusedElementIndex = i;
|
FocusedElementIndex = i;
|
||||||
#if UNITY_2022_1_OR_NEWER
|
#if UNITY_2022_1_OR_NEWER
|
||||||
var textComponentTxtMeshPro = _arrayOfElements[i].GetComponentInChildren<TMPro.TMP_Text>();
|
var textComponentTxtMeshPro = arrayOfElements[i].GetComponentInChildren<TMPro.TMP_Text>();
|
||||||
if (textComponentTxtMeshPro != null)
|
if (textComponentTxtMeshPro != null)
|
||||||
{
|
{
|
||||||
result = textComponentTxtMeshPro.text;
|
Result = textComponentTxtMeshPro.text;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
var textComponent = arrayOfElements[i].GetComponentInChildren<Text>();
|
var textComponent = arrayOfElements[i].GetComponentInChildren<Text>();
|
||||||
|
|
|
@ -11,7 +11,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
public int verticalPadding;
|
public int verticalPadding;
|
||||||
|
|
||||||
//tooltip text
|
//tooltip text
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
public TMPro.TMP_Text thisText;
|
||||||
|
#else
|
||||||
public Text thisText;
|
public Text thisText;
|
||||||
|
#endif
|
||||||
|
|
||||||
//horizontal layout of the tooltip
|
//horizontal layout of the tooltip
|
||||||
public HorizontalLayoutGroup hlG;
|
public HorizontalLayoutGroup hlG;
|
||||||
|
|
|
@ -27,7 +27,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
public class ToolTip : MonoBehaviour
|
public class ToolTip : MonoBehaviour
|
||||||
{
|
{
|
||||||
//text of the tooltip
|
//text of the tooltip
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
private TMPro.TMP_Text _text;
|
||||||
|
#else
|
||||||
private Text _text;
|
private Text _text;
|
||||||
|
#endif
|
||||||
private RectTransform _rectTransform, canvasRectTransform;
|
private RectTransform _rectTransform, canvasRectTransform;
|
||||||
|
|
||||||
[Tooltip("The canvas used by the tooltip as positioning and scaling reference. Should usually be the root Canvas of the hierarchy this component is in")]
|
[Tooltip("The canvas used by the tooltip as positioning and scaling reference. Should usually be the root Canvas of the hierarchy this component is in")]
|
||||||
|
@ -114,7 +118,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
canvasRectTransform = canvas.GetComponent<RectTransform>();
|
canvasRectTransform = canvas.GetComponent<RectTransform>();
|
||||||
_layoutGroup = GetComponentInChildren<LayoutGroup>();
|
_layoutGroup = GetComponentInChildren<LayoutGroup>();
|
||||||
|
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
_text = GetComponentInChildren<TMPro.TMP_Text>();
|
||||||
|
#else
|
||||||
_text = GetComponentInChildren<Text>();
|
_text = GetComponentInChildren<Text>();
|
||||||
|
#endif
|
||||||
|
|
||||||
_inside = false;
|
_inside = false;
|
||||||
|
|
||||||
|
|
|
@ -6,15 +6,27 @@ Simply place the script on A Text control in the scene to display the current PP
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
[RequireComponent(typeof(TMPro.TMP_Text))]
|
||||||
|
#else
|
||||||
[RequireComponent(typeof(Text))]
|
[RequireComponent(typeof(Text))]
|
||||||
|
#endif
|
||||||
[AddComponentMenu("UI/Extensions/PPIViewer")]
|
[AddComponentMenu("UI/Extensions/PPIViewer")]
|
||||||
public class PPIViewer : MonoBehaviour
|
public class PPIViewer : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
private TMPro.TMP_Text label;
|
||||||
|
#else
|
||||||
private Text label;
|
private Text label;
|
||||||
|
#endif
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
label = GetComponent<Text>();
|
#if UNITY_2022_1_OR_NEWER
|
||||||
|
label = GetComponentInChildren<TMPro.TMP_Text>();
|
||||||
|
#else
|
||||||
|
label = GetComponentInChildren<Text>();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6f5aae3077b0a914bb69e41bb26605de
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue