pull/458/head
SimonDarksideJ 2023-10-05 20:36:27 +01:00
commit 250befb08c
3 changed files with 213 additions and 148 deletions

View File

@ -49,6 +49,9 @@ namespace UnityEngine.UI.Extensions
private GameObject _itemTemplate; private GameObject _itemTemplate;
private bool _initialized; private bool _initialized;
private string _defaultMainButtonCaption = null;
private Color _defaultNormalColor;
[SerializeField] [SerializeField]
private float _scrollBarWidth = 20.0f; private float _scrollBarWidth = 20.0f;
public float ScrollBarWidth public float ScrollBarWidth
@ -61,7 +64,6 @@ namespace UnityEngine.UI.Extensions
} }
} }
// private int scrollOffset; //offset of the selected item
private int _selectedIndex = -1; private int _selectedIndex = -1;
[SerializeField] [SerializeField]
@ -98,7 +100,7 @@ namespace UnityEngine.UI.Extensions
[System.Serializable] [System.Serializable]
public class ControlDisabledEvent : Events.UnityEvent<bool> { } public class ControlDisabledEvent : Events.UnityEvent<bool> { }
// fires when item is changed; // fires when item changes between enabled and disabled;
public ControlDisabledEvent OnControlDisabled; public ControlDisabledEvent OnControlDisabled;
public void Start() public void Start()
@ -121,6 +123,9 @@ namespace UnityEngine.UI.Extensions
_rectTransform = GetComponent<RectTransform>(); _rectTransform = GetComponent<RectTransform>();
_mainButton = new DropDownListButton(_rectTransform.Find("MainButton").gameObject); _mainButton = new DropDownListButton(_rectTransform.Find("MainButton").gameObject);
_defaultMainButtonCaption = _mainButton.txt.text;
_defaultNormalColor = _mainButton.btn.colors.normalColor;
_overlayRT = _rectTransform.Find("Overlay").GetComponent<RectTransform>(); _overlayRT = _rectTransform.Find("Overlay").GetComponent<RectTransform>();
_overlayRT.gameObject.SetActive(false); _overlayRT.gameObject.SetActive(false);
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>(); _scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
@ -266,6 +271,24 @@ namespace UnityEngine.UI.Extensions
RedrawPanel(); RedrawPanel();
} }
public void ResetDropDown()
{
if (!_initialized)
{
return;
}
_mainButton.txt.text = _defaultMainButtonCaption;
for (int i = 0; i < _itemsPanelRT.childCount; i++)
{
_panelItems[i].btnImg.color = _defaultNormalColor;
}
_selectedIndex = -1;
_initialized = false;
Initialize();
}
public void ResetItems() public void ResetItems()
{ {
Items.Clear(); Items.Clear();
@ -407,38 +430,63 @@ namespace UnityEngine.UI.Extensions
} }
/// <summary> /// <summary>
/// Toggle the drop down list /// Toggle the drop down list if it is active
/// </summary> /// </summary>
/// <param name="directClick"> whether an item was directly clicked on</param> /// <param name="directClick">Retained for backwards compatibility only.</param>
public void ToggleDropdownPanel(bool directClick) [Obsolete("DirectClick Parameter is no longer required")]
public void ToggleDropdownPanel(bool directClick = false)
{ {
if (!isActive) return; ToggleDropdownPanel();
}
/// <summary>
/// Toggle the drop down list if it is active
/// </summary>
public void ToggleDropdownPanel()
{
if (!isActive)
{
return;
}
_overlayRT.transform.localScale = new Vector3(1, 1, 1); _overlayRT.transform.localScale = new Vector3(1, 1, 1);
_scrollBarRT.transform.localScale = new Vector3(1, 1, 1); _scrollBarRT.transform.localScale = new Vector3(1, 1, 1);
_isPanelActive = !_isPanelActive; _isPanelActive = !_isPanelActive;
_overlayRT.gameObject.SetActive(_isPanelActive); _overlayRT.gameObject.SetActive(_isPanelActive);
if (_isPanelActive) if (_isPanelActive)
{ {
transform.SetAsLastSibling(); transform.SetAsLastSibling();
} }
else if (directClick)
{
// scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y);
} }
/// <summary>
/// Hides the drop down panel if its visible at the moment
/// </summary>
public void HideDropDownPanel()
{
if (!_isPanelActive)
{
return;
}
ToggleDropdownPanel(false);
} }
/// <summary> /// <summary>
/// Updates the control and sets its active status, determines whether the dropdown will open ot not /// Updates the control and sets its active status, determines whether the dropdown will open ot not
/// and takes care of the underlying button to follow the status.
/// </summary> /// </summary>
/// <param name="status"></param> /// <param name="status"></param>
public void SetActive(bool status) public void SetActive(bool status)
{ {
if (status != isActive) if (status == isActive)
{ {
OnControlDisabled?.Invoke(status); return;
} }
isActive = status; isActive = status;
OnControlDisabled?.Invoke(isActive);
_mainButton.btn.enabled = isActive;
} }
} }
} }

View File

@ -16,6 +16,9 @@ namespace UnityEngine.UI.Extensions
[Tooltip("Enables 3d rotation for the particles")] [Tooltip("Enables 3d rotation for the particles")]
public bool use3dRotation = false; public bool use3dRotation = false;
[Tooltip("Enables using Renderer.lengthScale parameter")]
public bool _useLengthScale = false;
private Transform _transform; private Transform _transform;
private ParticleSystem pSystem; private ParticleSystem pSystem;
private ParticleSystem.Particle[] particles; private ParticleSystem.Particle[] particles;
@ -183,8 +186,6 @@ namespace UnityEngine.UI.Extensions
#else #else
Vector2 position = (pSystem.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position)); Vector2 position = (pSystem.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
#endif #endif
float rotation = -particle.rotation * Mathf.Deg2Rad;
float rotation90 = rotation + Mathf.PI / 2;
Color32 color = particle.GetCurrentColor(pSystem); Color32 color = particle.GetCurrentColor(pSystem);
float size = particle.GetCurrentSize(pSystem) * 0.5f; float size = particle.GetCurrentSize(pSystem) * 0.5f;
@ -280,13 +281,29 @@ namespace UnityEngine.UI.Extensions
_quad[3].color = color; _quad[3].color = color;
_quad[3].uv0 = temp; _quad[3].uv0 = temp;
float rotation = -particle.rotation * Mathf.Deg2Rad;
var lengthScale = pRenderer.lengthScale;
if (_useLengthScale)
{
// rotate towards velocity
var normalizedVelocity = particle.velocity.normalized;
rotation = Mathf.Atan2(normalizedVelocity.y, normalizedVelocity.x);
}
else
{
lengthScale = 1f;
}
float rotation90 = rotation + Mathf.PI / 2;
if (rotation == 0) if (rotation == 0)
{ {
// no rotation // no rotation
corner1.x = position.x - size; corner1.x = position.x - size;
corner1.y = position.y - size; corner1.y = position.y - size * lengthScale;
corner2.x = position.x + size; corner2.x = position.x + size;
corner2.y = position.y + size; corner2.y = position.y + size * lengthScale;
temp.x = corner1.x; temp.x = corner1.x;
temp.y = corner1.y; temp.y = corner1.y;
@ -339,7 +356,7 @@ namespace UnityEngine.UI.Extensions
else else
{ {
// apply rotation // apply rotation
Vector2 right = new Vector2(Mathf.Cos(rotation), Mathf.Sin(rotation)) * size; Vector2 right = new Vector2(Mathf.Cos(rotation), Mathf.Sin(rotation)) * size * lengthScale;
Vector2 up = new Vector2(Mathf.Cos(rotation90), Mathf.Sin(rotation90)) * size; Vector2 up = new Vector2(Mathf.Cos(rotation90), Mathf.Sin(rotation90)) * size;
_quad[0].position = position - right - up; _quad[0].position = position - right - up;

View File

@ -287,7 +287,7 @@ namespace UnityEngine.UI.Extensions
PopulateMesh (vh, m_points); PopulateMesh (vh, m_points);
} }
else if (m_segments != null && m_segments.Count > 0) { if (m_segments != null && m_segments.Count > 0) {
GeneratedUVs (); GeneratedUVs ();
vh.Clear (); vh.Clear ();