Merge pull request #460 from Unity-UI-Extensions/feature/2023testing

Feature/2023testing
pull/461/head
Simon (Darkside) Jackson 2023-11-26 15:36:27 +00:00 committed by GitHub
commit c2c098cad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 304 additions and 210 deletions

View File

@ -2,217 +2,225 @@
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/ ///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using System; using System;
using System.Collections;
using UnityEngine.UI.Extensions.Tweens; using UnityEngine.UI.Extensions.Tweens;
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
[RequireComponent(typeof(RectTransform), typeof(LayoutElement))] [RequireComponent(typeof(RectTransform), typeof(LayoutElement))]
[AddComponentMenu("UI/Extensions/Accordion/Accordion Element")] [AddComponentMenu("UI/Extensions/Accordion/Accordion Element")]
public class AccordionElement : Toggle public class AccordionElement : Toggle
{ {
[SerializeField] private float m_MinHeight = 18f; [SerializeField] private float m_MinHeight = 18f;
public float MinHeight => m_MinHeight; public float MinHeight => m_MinHeight;
[SerializeField] private float m_MinWidth = 40f; [SerializeField] private float m_MinWidth = 40f;
public float MinWidth => m_MinWidth; public float MinWidth => m_MinWidth;
private Accordion m_Accordion; private Accordion m_Accordion;
private RectTransform m_RectTransform; private RectTransform m_RectTransform;
private LayoutElement m_LayoutElement; private LayoutElement m_LayoutElement;
[NonSerialized] [NonSerialized]
private readonly TweenRunner<FloatTween> m_FloatTweenRunner; private readonly TweenRunner<FloatTween> m_FloatTweenRunner;
protected AccordionElement() protected AccordionElement()
{ {
if (this.m_FloatTweenRunner == null) if (this.m_FloatTweenRunner == null)
this.m_FloatTweenRunner = new TweenRunner<FloatTween>(); this.m_FloatTweenRunner = new TweenRunner<FloatTween>();
this.m_FloatTweenRunner.Init(this); this.m_FloatTweenRunner.Init(this);
} }
protected override void Awake() protected override void Awake()
{ {
base.Awake(); base.Awake();
base.transition = Transition.None; base.transition = Transition.None;
base.toggleTransition = ToggleTransition.None; base.toggleTransition = ToggleTransition.None;
this.m_Accordion = this.gameObject.GetComponentInParent<Accordion>(); this.m_Accordion = this.gameObject.GetComponentInParent<Accordion>();
this.m_RectTransform = this.transform as RectTransform; this.m_RectTransform = this.transform as RectTransform;
this.m_LayoutElement = this.gameObject.GetComponent<LayoutElement>(); this.m_LayoutElement = this.gameObject.GetComponent<LayoutElement>();
this.onValueChanged.AddListener(OnValueChanged); this.onValueChanged.AddListener(OnValueChanged);
} }
private new IEnumerator Start()
{
base.Start();
yield return new WaitForEndOfFrame(); // Wait for the first frame
OnValueChanged(this.isOn);
}
#if UNITY_EDITOR #if UNITY_EDITOR
protected override void OnValidate() protected override void OnValidate()
{ {
base.OnValidate(); base.OnValidate();
this.m_Accordion = this.gameObject.GetComponentInParent<Accordion>(); this.m_Accordion = this.gameObject.GetComponentInParent<Accordion>();
if (this.group == null) if (this.group == null)
{ {
ToggleGroup tg = this.GetComponentInParent<ToggleGroup>(); ToggleGroup tg = this.GetComponentInParent<ToggleGroup>();
if (tg != null) if (tg != null)
{ {
this.group = tg; this.group = tg;
} }
} }
LayoutElement le = this.gameObject.GetComponent<LayoutElement>(); LayoutElement le = this.gameObject.GetComponent<LayoutElement>();
if (le != null && m_Accordion != null) if (le != null && m_Accordion != null)
{ {
if (this.isOn) if (this.isOn)
{ {
if (m_Accordion.ExpandVerticval) if (m_Accordion.ExpandVerticval)
{ {
le.preferredHeight = -1f; le.preferredHeight = -1f;
}
else
{
le.preferredWidth = -1f;
} }
}
else
{
if (m_Accordion.ExpandVerticval)
{
le.preferredHeight = this.m_MinHeight;
}
else else
{ {
le.preferredWidth = this.m_MinWidth; le.preferredWidth = -1f;
}
}
else
{
if (m_Accordion.ExpandVerticval)
{
le.preferredHeight = this.m_MinHeight;
}
else
{
le.preferredWidth = this.m_MinWidth;
} }
} }
} }
} }
#endif #endif
public void OnValueChanged(bool state) public void OnValueChanged(bool state)
{ {
if (this.m_LayoutElement == null) if (this.m_LayoutElement == null)
return; return;
Accordion.Transition transition = (this.m_Accordion != null) ? this.m_Accordion.transition : Accordion.Transition.Instant; Accordion.Transition transition = (this.m_Accordion != null) ? this.m_Accordion.transition : Accordion.Transition.Instant;
if (transition == Accordion.Transition.Instant && m_Accordion != null) if (transition == Accordion.Transition.Instant && m_Accordion != null)
{ {
if (state) if (state)
{ {
if (m_Accordion.ExpandVerticval) if (m_Accordion.ExpandVerticval)
{ {
this.m_LayoutElement.preferredHeight = -1f; this.m_LayoutElement.preferredHeight = -1f;
} }
else else
{ {
this.m_LayoutElement.preferredWidth = -1f; this.m_LayoutElement.preferredWidth = -1f;
} }
} }
else else
{ {
if (m_Accordion.ExpandVerticval) if (m_Accordion.ExpandVerticval)
{ {
this.m_LayoutElement.preferredHeight = this.m_MinHeight; this.m_LayoutElement.preferredHeight = this.m_MinHeight;
} }
else else
{ {
this.m_LayoutElement.preferredWidth = this.m_MinWidth; this.m_LayoutElement.preferredWidth = this.m_MinWidth;
} }
} }
} }
else if (transition == Accordion.Transition.Tween) else if (transition == Accordion.Transition.Tween)
{ {
if (state) if (state)
{ {
if (m_Accordion.ExpandVerticval) if (m_Accordion.ExpandVerticval)
{ {
this.StartTween(this.m_MinHeight, this.GetExpandedHeight()); this.StartTween(this.m_MinHeight, this.GetExpandedHeight());
} }
else else
{ {
this.StartTween(this.m_MinWidth, this.GetExpandedWidth()); this.StartTween(this.m_MinWidth, this.GetExpandedWidth());
} }
} }
else else
{ {
if (m_Accordion.ExpandVerticval) if (m_Accordion.ExpandVerticval)
{ {
this.StartTween(this.m_RectTransform.rect.height, this.m_MinHeight); this.StartTween(this.m_RectTransform.rect.height, this.m_MinHeight);
} }
else else
{ {
this.StartTween(this.m_RectTransform.rect.width, this.m_MinWidth); this.StartTween(this.m_RectTransform.rect.width, this.m_MinWidth);
} }
} }
} }
} }
protected float GetExpandedHeight() protected float GetExpandedHeight()
{ {
if (this.m_LayoutElement == null) if (this.m_LayoutElement == null)
return this.m_MinHeight; return this.m_MinHeight;
float originalPrefH = this.m_LayoutElement.preferredHeight; float originalPrefH = this.m_LayoutElement.preferredHeight;
this.m_LayoutElement.preferredHeight = -1f; this.m_LayoutElement.preferredHeight = -1f;
float h = LayoutUtility.GetPreferredHeight(this.m_RectTransform); float h = LayoutUtility.GetPreferredHeight(this.m_RectTransform);
this.m_LayoutElement.preferredHeight = originalPrefH; this.m_LayoutElement.preferredHeight = originalPrefH;
return h; return h;
} }
protected float GetExpandedWidth() protected float GetExpandedWidth()
{ {
if (this.m_LayoutElement == null) if (this.m_LayoutElement == null)
return this.m_MinWidth; return this.m_MinWidth;
float originalPrefW = this.m_LayoutElement.preferredWidth; float originalPrefW = this.m_LayoutElement.preferredWidth;
this.m_LayoutElement.preferredWidth = -1f; this.m_LayoutElement.preferredWidth = -1f;
float w = LayoutUtility.GetPreferredWidth(this.m_RectTransform); float w = LayoutUtility.GetPreferredWidth(this.m_RectTransform);
this.m_LayoutElement.preferredWidth = originalPrefW; this.m_LayoutElement.preferredWidth = originalPrefW;
return w; return w;
} }
protected void StartTween(float startFloat, float targetFloat) protected void StartTween(float startFloat, float targetFloat)
{ {
float duration = (this.m_Accordion != null) ? this.m_Accordion.transitionDuration : 0.3f; float duration = (this.m_Accordion != null) ? this.m_Accordion.transitionDuration : 0.3f;
FloatTween info = new FloatTween FloatTween info = new FloatTween
{ {
duration = duration, duration = duration,
startFloat = startFloat, startFloat = startFloat,
targetFloat = targetFloat targetFloat = targetFloat
}; };
if (m_Accordion.ExpandVerticval) if (m_Accordion.ExpandVerticval)
{ {
info.AddOnChangedCallback(SetHeight); info.AddOnChangedCallback(SetHeight);
} }
else else
{ {
info.AddOnChangedCallback(SetWidth); info.AddOnChangedCallback(SetWidth);
} }
info.ignoreTimeScale = true; info.ignoreTimeScale = true;
this.m_FloatTweenRunner.StartTween(info); this.m_FloatTweenRunner.StartTween(info);
} }
protected void SetHeight(float height) protected void SetHeight(float height)
{ {
if (this.m_LayoutElement == null) if (this.m_LayoutElement == null)
return; return;
this.m_LayoutElement.preferredHeight = height; this.m_LayoutElement.preferredHeight = height;
} }
protected void SetWidth(float width) protected void SetWidth(float width)
{ {
if (this.m_LayoutElement == null) if (this.m_LayoutElement == null)
return; return;
this.m_LayoutElement.preferredWidth = width; this.m_LayoutElement.preferredWidth = width;
} }
} }
} }

View File

@ -1,7 +1,6 @@
///Credit perchik ///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/ ///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -132,6 +131,9 @@ namespace UnityEngine.UI.Extensions
[System.Serializable] [System.Serializable]
public class SelectionValidityChangedEvent : Events.UnityEvent<bool> { } public class SelectionValidityChangedEvent : Events.UnityEvent<bool> { }
[System.Serializable]
public class ItemSelectedEvent : Events.UnityEvent<string> { }
[System.Serializable] [System.Serializable]
public class ControlDisabledEvent : Events.UnityEvent<bool> { } public class ControlDisabledEvent : Events.UnityEvent<bool> { }
@ -142,6 +144,8 @@ namespace UnityEngine.UI.Extensions
public SelectionValidityChangedEvent OnSelectionValidityChanged; public SelectionValidityChangedEvent OnSelectionValidityChanged;
// fires in both cases // fires in both cases
public SelectionChangedEvent OnSelectionChanged; public SelectionChangedEvent OnSelectionChanged;
// fires when an item is clicked
public ItemSelectedEvent OnItemSelected;
// fires when item is changed; // fires when item is changed;
public ControlDisabledEvent OnControlDisabled; public ControlDisabledEvent OnControlDisabled;
@ -359,10 +363,10 @@ namespace UnityEngine.UI.Extensions
/// <param name="item"></param> /// <param name="item"></param>
private void OnItemClicked(string item) private void OnItemClicked(string item)
{ {
//Debug.Log("item " + item + " clicked");
Text = item; Text = item;
_mainInput.text = Text; _mainInput.text = Text;
ToggleDropdownPanel(true); ToggleDropdownPanel(true);
OnItemSelected?.Invoke(Text);
} }
private void RedrawPanel() private void RedrawPanel()

View File

@ -2,10 +2,19 @@
/// Sourced from - http://forum.unity3d.com/members/melang.593409/ /// Sourced from - http://forum.unity3d.com/members/melang.593409/
/// NOT supported in Unity 2022 /// NOT supported in Unity 2022
using System;
#if !UNITY_2022_1_OR_NEWER #if !UNITY_2022_1_OR_NEWER
using System.Collections.Generic; using System.Collections.Generic;
#endif
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
#if UNITY_2022_1_OR_NEWER
[Obsolete("BestFitOutline is not supported in Unity 2022.1 or newer. Use TMPro instead.")]
public class BestFitOutline : Shadow
{
}
#else
[AddComponentMenu("UI/Effects/Extensions/BestFit Outline")] [AddComponentMenu("UI/Effects/Extensions/BestFit Outline")]
public class BestFitOutline : Shadow public class BestFitOutline : Shadow
{ {
@ -61,5 +70,5 @@ namespace UnityEngine.UI.Extensions
} }
} }
} }
}
#endif #endif
}

View File

@ -1,9 +1,17 @@
/// Credit Breyer 
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1777407 using System;
#if !UNITY_2022_1_OR_NEWER
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
#if UNITY_2022_1_OR_NEWER
[Obsolete("CurvedText is not supported in Unity 2022.1 or newer. Use TMPro instead.")]
public class CurvedText : BaseMeshEffect
{
public override void ModifyMesh(VertexHelper vh)
{
}
}
#else
[RequireComponent(typeof(Text))] [RequireComponent(typeof(Text))]
[RequireComponent(typeof(RectTransform))] [RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Effects/Extensions/Curved Text")] [AddComponentMenu("UI/Effects/Extensions/Curved Text")]
@ -83,5 +91,5 @@ namespace UnityEngine.UI.Extensions
} }
} }
} }
}
#endif #endif
}

View File

@ -1,10 +1,20 @@
/// adaption for cylindrical bending by herbst 
using System;
/// adaption for cylindrical bending by herbst
/// Credit Breyer /// Credit Breyer
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1777407 /// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1777407
#if !UNITY_2022_1_OR_NEWER
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
#if UNITY_2022_1_OR_NEWER
[Obsolete("CylinderText is not supported in Unity 2022.1 or newer. Use TMPro instead.")]
public class CylinderText : BaseMeshEffect
{
public override void ModifyMesh(VertexHelper vh)
{
}
}
#else
[RequireComponent(typeof(Text))] [RequireComponent(typeof(Text))]
[RequireComponent(typeof(RectTransform))] [RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Effects/Extensions/Cylinder Text")] [AddComponentMenu("UI/Effects/Extensions/Cylinder Text")]
@ -53,5 +63,5 @@ namespace UnityEngine.UI.Extensions
} }
} }
} }
}
#endif #endif
}

View File

@ -1,6 +1,4 @@
/// Credit Deeperbeige /*
/// Sourced from - http://forum.unity3d.com/threads/adjustable-character-spacing-free-script.288277/
/*
Produces an simple tracking/letter-spacing effect on UI Text components. Produces an simple tracking/letter-spacing effect on UI Text components.
@ -42,9 +40,23 @@ break down entirely, but it doesn't really do what you'd want either.
*/ */
#if !UNITY_2022_1_OR_NEWER #if !UNITY_2022_1_OR_NEWER
using System.Collections.Generic; using System.Collections.Generic;
#endif
using System;
/// Credit Deeperbeige
/// Sourced from - http://forum.unity3d.com/threads/adjustable-character-spacing-free-script.288277/
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
#if UNITY_2022_1_OR_NEWER
[Obsolete("LetterSpacing is not supported in Unity 2022.1 or newer. Use TMPro instead.")]
public class LetterSpacing : BaseMeshEffect
{
public override void ModifyMesh(VertexHelper vh)
{
}
}
#else
[AddComponentMenu("UI/Effects/Extensions/Letter Spacing")] [AddComponentMenu("UI/Effects/Extensions/Letter Spacing")]
///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).
@ -55,13 +67,13 @@ namespace UnityEngine.UI.Extensions
protected LetterSpacing() { } protected LetterSpacing() { }
#if UNITY_EDITOR #if UNITY_EDITOR
protected override void OnValidate() protected override void OnValidate()
{ {
spacing = m_spacing; spacing = m_spacing;
base.OnValidate(); base.OnValidate();
} }
#endif #endif
public float spacing public float spacing
{ {
@ -171,5 +183,5 @@ namespace UnityEngine.UI.Extensions
vh.AddUIVertexTriangleStream(verts); vh.AddUIVertexTriangleStream(verts);
} }
} }
}
#endif #endif
}

View File

@ -1,5 +1,3 @@
/// Credit herbst / derived from LetterSpacing by Deeperbeige
/// Sourced from - http://forum.unity3d.com/threads/adjustable-character-spacing-free-script.288277/
/* /*
Produces an simple mono-spacing effect on UI Text components. Produces an simple mono-spacing effect on UI Text components.
@ -41,11 +39,24 @@ break down entirely, but it doesn't really do what you'd want either.
*/ */
#if !UNITY_2022_1_OR_NEWER #if !UNITY_2022_1_OR_NEWER
using System.Collections.Generic; using System.Collections.Generic;
#endif
using System;
/// Credit herbst / derived from LetterSpacing by Deeperbeige
/// Sourced from - http://forum.unity3d.com/threads/adjustable-character-spacing-free-script.288277/
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
#if UNITY_2022_1_OR_NEWER
[Obsolete("MonoSpacing is not supported in Unity 2022.1 or newer. Use TMPro instead.")]
public class MonoSpacing : BaseMeshEffect
{
public override void ModifyMesh(VertexHelper vh)
{
}
}
#else
[AddComponentMenu("UI/Effects/Extensions/Mono Spacing")] [AddComponentMenu("UI/Effects/Extensions/Mono Spacing")]
[RequireComponent(typeof(Text))] [RequireComponent(typeof(Text))]
[RequireComponent(typeof(RectTransform))] [RequireComponent(typeof(RectTransform))]
@ -76,13 +87,13 @@ namespace UnityEngine.UI.Extensions
rectTransform = text.GetComponent<RectTransform>(); rectTransform = text.GetComponent<RectTransform>();
} }
#if UNITY_EDITOR #if UNITY_EDITOR
protected override void OnValidate() protected override void OnValidate()
{ {
Spacing = m_spacing; Spacing = m_spacing;
base.OnValidate(); base.OnValidate();
} }
#endif #endif
public float Spacing public float Spacing
{ {
@ -190,5 +201,5 @@ namespace UnityEngine.UI.Extensions
vh.AddUIVertexTriangleStream(verts); vh.AddUIVertexTriangleStream(verts);
} }
} }
}
#endif #endif
}

View File

@ -1,12 +1,25 @@
#if !UNITY_2022_1_OR_NEWER
using System.Collections.Generic;
#endif
using System;
/// 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 /// NOT supported in Unity 2022
#if !UNITY_2022_1_OR_NEWER
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
#if UNITY_2022_1_OR_NEWER
[Obsolete("BestFitOutline is not supported in Unity 2022.1 or newer. Use TMPro instead.")]
public class NicerOutline : BaseMeshEffect
{
public override void ModifyMesh(VertexHelper vh)
{
}
}
#else
//An outline that looks a bit nicer than the default one. It has less "holes" in the outline by drawing more copies of the effect //An outline that looks a bit nicer than the default one. It has less "holes" in the outline by drawing more copies of the effect
[AddComponentMenu("UI/Effects/Extensions/Nicer Outline")] [AddComponentMenu("UI/Effects/Extensions/Nicer Outline")]
public class NicerOutline : BaseMeshEffect public class NicerOutline : BaseMeshEffect
@ -194,5 +207,5 @@ namespace UnityEngine.UI.Extensions
} }
#endif #endif
} }
}
#endif #endif
}

View File

@ -223,12 +223,21 @@ namespace UnityEngine.UI.Extensions
/// <summary> /// <summary>
/// used for changing / updating between screen resolutions /// used for changing / updating between screen resolutions
/// </summary> /// </summary>
public void UpdateLayout() public void UpdateLayout(bool resetPositionToStart = false)
{ {
_lerp = false; _lerp = false;
DistributePages(); DistributePages();
if (resetPositionToStart)
{
_currentPage = StartingScreen;
}
if (MaskArea) if (MaskArea)
{
UpdateVisible(); UpdateVisible();
}
SetScrollContainerPosition(); SetScrollContainerPosition();
OnCurrentScreenChange(_currentPage); OnCurrentScreenChange(_currentPage);
} }

View File

@ -218,11 +218,21 @@ namespace UnityEngine.UI.Extensions
/// <summary> /// <summary>
/// used for changing / updating between screen resolutions /// used for changing / updating between screen resolutions
/// </summary> /// </summary>
public void UpdateLayout() public void UpdateLayout(bool resetPositionToStart = false)
{ {
_lerp = false; _lerp = false;
DistributePages(); DistributePages();
if (MaskArea) UpdateVisible();
if (resetPositionToStart)
{
_currentPage = StartingScreen;
}
if (MaskArea)
{
UpdateVisible();
}
SetScrollContainerPosition(); SetScrollContainerPosition();
OnCurrentScreenChange(_currentPage); OnCurrentScreenChange(_currentPage);
} }