Updated TextPic. Recent Unity updates seem to have changed the Event System behaviour and all click events are broken when a TextPic is placed as the child of a button. (gave up figuring out why)

Changed implementation, so that when TextPic is added as a child of a button, it adds a CanvasGroup and allows clicks to pass through it.  Downside is that hyperlinks don't work. TextPic on buttons is purely decorative.

The Button issue disables the ability to highlight links, so updated implementation to allow a "Selectable" component to be added to the TextPic to set highlight colours.

Resolves #110
release
Simon Jackson 2017-07-08 10:33:08 +01:00
parent 608a7bdf6a
commit 845f5d5700
1 changed files with 38 additions and 7 deletions

View File

@ -25,6 +25,9 @@ namespace UnityEngine.UI.Extensions
private bool clearImages = false; private bool clearImages = false;
private Object thisLock = new Object(); private Object thisLock = new Object();
/// <summary> /// <summary>
/// Vertex Index /// Vertex Index
/// </summary> /// </summary>
@ -38,6 +41,16 @@ namespace UnityEngine.UI.Extensions
private string fixedString; private string fixedString;
[SerializeField]
[Tooltip("Allow click events to be received by parents, (default) blocks")]
private bool m_ClickParents;
public bool AllowClickParents
{
get { return m_ClickParents; }
set { m_ClickParents = value; }
}
public override void SetVerticesDirty() public override void SetVerticesDirty()
{ {
base.SetVerticesDirty(); base.SetVerticesDirty();
@ -77,6 +90,7 @@ namespace UnityEngine.UI.Extensions
public Vector2 imageOffset = Vector2.zero; public Vector2 imageOffset = Vector2.zero;
private Button button; private Button button;
private Selectable highlightselectable;
//Commented out as private and not used.. Yet? //Commented out as private and not used.. Yet?
//private bool selected = false; //private bool selected = false;
@ -95,7 +109,23 @@ namespace UnityEngine.UI.Extensions
*/ */
new void Start() new void Start()
{ {
button = GetComponent<Button>(); button = GetComponentInParent<Button>();
if (button != null)
{
CanvasGroup cg;
cg = GetComponent<CanvasGroup>();
if (cg == null)
{
cg = gameObject.AddComponent<CanvasGroup>();
}
cg.blocksRaycasts = false;
highlightselectable = cg.GetComponent<Selectable>();
}
else
{
highlightselectable = GetComponent<Selectable>();
}
if (inspectorIconList != null && inspectorIconList.Length > 0) if (inspectorIconList != null && inspectorIconList.Length > 0)
{ {
foreach (IconName icon in inspectorIconList) foreach (IconName icon in inspectorIconList)
@ -105,6 +135,7 @@ namespace UnityEngine.UI.Extensions
} }
} }
Reset_m_HrefInfos (); Reset_m_HrefInfos ();
base.Start();
} }
protected void UpdateQuadImage() protected void UpdateQuadImage()
@ -379,9 +410,9 @@ namespace UnityEngine.UI.Extensions
{ {
foreach (Image img in m_ImagesPool) foreach (Image img in m_ImagesPool)
{ {
if (button != null && button.isActiveAndEnabled) if (highlightselectable != null && highlightselectable.isActiveAndEnabled)
{ {
img.color = button.colors.highlightedColor; img.color = highlightselectable.colors.highlightedColor;
} }
} }
} }
@ -396,9 +427,9 @@ namespace UnityEngine.UI.Extensions
{ {
foreach (Image img in m_ImagesPool) foreach (Image img in m_ImagesPool)
{ {
if (button != null && button.isActiveAndEnabled) if (highlightselectable != null && highlightselectable.isActiveAndEnabled)
{ {
img.color = button.colors.normalColor; img.color = highlightselectable.colors.normalColor;
} }
else else
{ {
@ -415,9 +446,9 @@ namespace UnityEngine.UI.Extensions
{ {
foreach (Image img in m_ImagesPool) foreach (Image img in m_ImagesPool)
{ {
if (button != null && button.isActiveAndEnabled) if (highlightselectable != null && highlightselectable.isActiveAndEnabled)
{ {
img.color = button.colors.highlightedColor; img.color = highlightselectable.colors.highlightedColor;
} }
} }
} }