From 34e3f82395894b5f7d47ab1fbd99ed496fb89c89 Mon Sep 17 00:00:00 2001 From: adibacco Date: Wed, 28 Jun 2023 23:00:16 +0200 Subject: [PATCH 1/8] Update UILineRenderer.cs There is no need to draw either points or segments. Both should be drawn. --- Runtime/Scripts/Primitives/UILineRenderer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/Scripts/Primitives/UILineRenderer.cs b/Runtime/Scripts/Primitives/UILineRenderer.cs index d3b5d3d..3e50eb8 100644 --- a/Runtime/Scripts/Primitives/UILineRenderer.cs +++ b/Runtime/Scripts/Primitives/UILineRenderer.cs @@ -287,7 +287,7 @@ namespace UnityEngine.UI.Extensions PopulateMesh (vh, m_points); } - else if (m_segments != null && m_segments.Count > 0) { + if (m_segments != null && m_segments.Count > 0) { GeneratedUVs (); vh.Clear (); @@ -480,4 +480,4 @@ namespace UnityEngine.UI.Extensions } } } -} \ No newline at end of file +} From 2a925fcf65c4925ded102acbe036f5d246d0522b Mon Sep 17 00:00:00 2001 From: "eldar.zakaryaev" Date: Wed, 5 Jul 2023 11:11:44 +0300 Subject: [PATCH 2/8] Add using lengthScale to UIParticleSystem --- Runtime/Scripts/Effects/UIParticleSystem.cs | 31 +++++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/Runtime/Scripts/Effects/UIParticleSystem.cs b/Runtime/Scripts/Effects/UIParticleSystem.cs index 4083b02..2b24889 100644 --- a/Runtime/Scripts/Effects/UIParticleSystem.cs +++ b/Runtime/Scripts/Effects/UIParticleSystem.cs @@ -16,6 +16,9 @@ namespace UnityEngine.UI.Extensions [Tooltip("Enables 3d rotation for the particles")] public bool use3dRotation = false; + [Tooltip("Enables using Renderer.lengthScale parameter")] + public bool _useLengthScale = false; + private Transform _transform; private ParticleSystem pSystem; private ParticleSystem.Particle[] particles; @@ -26,6 +29,7 @@ namespace UnityEngine.UI.Extensions private Vector2 textureSheetAnimationFrameSize; private ParticleSystemRenderer pRenderer; private bool isInitialised = false; + private float _lengthScale; private Material currentMaterial; @@ -91,7 +95,8 @@ namespace UnityEngine.UI.Extensions pRenderer = pSystem.GetComponent(); if (pRenderer != null) pRenderer.enabled = false; - + + _lengthScale = pRenderer.lengthScale; if (material == null) { var foundShader = ShaderLibrary.GetShaderInstance("UI Extensions/Particles/Additive"); @@ -183,8 +188,6 @@ namespace UnityEngine.UI.Extensions #else Vector2 position = (pSystem.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position)); #endif - float rotation = -particle.rotation * Mathf.Deg2Rad; - float rotation90 = rotation + Mathf.PI / 2; Color32 color = particle.GetCurrentColor(pSystem); float size = particle.GetCurrentSize(pSystem) * 0.5f; @@ -280,13 +283,29 @@ namespace UnityEngine.UI.Extensions _quad[3].color = color; _quad[3].uv0 = temp; + + float rotation = -particle.rotation * Mathf.Deg2Rad; + var lengthScale = _lengthScale; + if (_useLengthScale) // this flag is mostly to secure old behaviour, it probably can be replaced with _lengthScale != 1 + { + // 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) { // no rotation corner1.x = position.x - size; - corner1.y = position.y - size; + corner1.y = position.y - size * lengthScale; corner2.x = position.x + size; - corner2.y = position.y + size; + corner2.y = position.y + size * lengthScale; temp.x = corner1.x; temp.y = corner1.y; @@ -339,7 +358,7 @@ namespace UnityEngine.UI.Extensions else { // 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; _quad[0].position = position - right - up; From 11de6837812fb3ce799144705128969d82ec15a0 Mon Sep 17 00:00:00 2001 From: "eldar.zakaryaev" Date: Wed, 5 Jul 2023 11:24:50 +0300 Subject: [PATCH 3/8] Fix UIParticleSystem does not correspond to runtime lengthScale change --- Runtime/Scripts/Effects/UIParticleSystem.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Runtime/Scripts/Effects/UIParticleSystem.cs b/Runtime/Scripts/Effects/UIParticleSystem.cs index 2b24889..a004b7b 100644 --- a/Runtime/Scripts/Effects/UIParticleSystem.cs +++ b/Runtime/Scripts/Effects/UIParticleSystem.cs @@ -29,7 +29,6 @@ namespace UnityEngine.UI.Extensions private Vector2 textureSheetAnimationFrameSize; private ParticleSystemRenderer pRenderer; private bool isInitialised = false; - private float _lengthScale; private Material currentMaterial; @@ -96,7 +95,6 @@ namespace UnityEngine.UI.Extensions if (pRenderer != null) pRenderer.enabled = false; - _lengthScale = pRenderer.lengthScale; if (material == null) { var foundShader = ShaderLibrary.GetShaderInstance("UI Extensions/Particles/Additive"); @@ -285,8 +283,8 @@ namespace UnityEngine.UI.Extensions float rotation = -particle.rotation * Mathf.Deg2Rad; - var lengthScale = _lengthScale; - if (_useLengthScale) // this flag is mostly to secure old behaviour, it probably can be replaced with _lengthScale != 1 + var lengthScale = pRenderer.lengthScale; + if (_useLengthScale) { // rotate towards velocity var normalizedVelocity = particle.velocity.normalized; From c06cd38081d576f8de1fec961e358949191a23f6 Mon Sep 17 00:00:00 2001 From: Robert Wartenberg Date: Wed, 16 Aug 2023 12:02:41 +0200 Subject: [PATCH 4/8] add: public accessable reset function --- .../Scripts/Controls/ComboBox/DropDownList.cs | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs index 7de1b07..46ea9d3 100644 --- a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs +++ b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; namespace UnityEngine.UI.Extensions { /// - /// Extension to the UI class which creates a dropdown list + /// Extension to the UI class which creates a dropdown list /// [RequireComponent(typeof(RectTransform))] [AddComponentMenu("UI/Extensions/ComboBox/Dropdown List")] @@ -49,6 +49,9 @@ namespace UnityEngine.UI.Extensions private GameObject _itemTemplate; private bool _initialized; + private string _defaultMainButtonCaption = null; + private Color _defaultNormalColor; + [SerializeField] private float _scrollBarWidth = 20.0f; public float ScrollBarWidth @@ -121,6 +124,9 @@ namespace UnityEngine.UI.Extensions _rectTransform = GetComponent(); _mainButton = new DropDownListButton(_rectTransform.Find("MainButton").gameObject); + _defaultMainButtonCaption = _mainButton.txt.text; + _defaultNormalColor = _mainButton.btn.colors.normalColor; + _overlayRT = _rectTransform.Find("Overlay").GetComponent(); _overlayRT.gameObject.SetActive(false); _scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent(); @@ -212,7 +218,7 @@ namespace UnityEngine.UI.Extensions } /// - /// Adds an additional drop down list item using a string name + /// Adds an additional drop down list item using a string name /// /// Item of type String public void AddItem(string item) @@ -223,7 +229,7 @@ namespace UnityEngine.UI.Extensions } /// - /// Adds an additional drop down list item using a sprite image + /// Adds an additional drop down list item using a sprite image /// /// Item of type UI Sprite public void AddItem(Sprite item) @@ -245,7 +251,7 @@ namespace UnityEngine.UI.Extensions } /// - /// Removes an item from the drop down list item using a string name + /// Removes an item from the drop down list item using a string name /// /// Item of type String public void RemoveItem(string item) @@ -256,7 +262,7 @@ namespace UnityEngine.UI.Extensions } /// - /// Removes an item from the drop down list item using a sprite image + /// Removes an item from the drop down list item using a sprite image /// /// Item of type UI Sprite public void RemoveItem(Sprite item) @@ -266,7 +272,21 @@ namespace UnityEngine.UI.Extensions RedrawPanel(); } - public void ResetItems() + 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() { Items.Clear(); RebuildPanel(); @@ -304,7 +324,7 @@ namespace UnityEngine.UI.Extensions _panelItems[i].txt.text = item.Caption; if (item.IsDisabled) _panelItems[i].txt.color = disabledTextColor; - if (_panelItems[i].btnImg != null) _panelItems[i].btnImg.sprite = null;//hide the button image + if (_panelItems[i].btnImg != null) _panelItems[i].btnImg.sprite = null;//hide the button image _panelItems[i].img.sprite = item.Image; _panelItems[i].img.color = (item.Image == null) ? new Color(1, 1, 1, 0) : item.IsDisabled ? new Color(1, 1, 1, .5f) @@ -413,7 +433,7 @@ namespace UnityEngine.UI.Extensions public void ToggleDropdownPanel(bool directClick) { if (!isActive) return; - + _overlayRT.transform.localScale = new Vector3(1, 1, 1); _scrollBarRT.transform.localScale = new Vector3(1, 1, 1); _isPanelActive = !_isPanelActive; @@ -424,7 +444,7 @@ namespace UnityEngine.UI.Extensions } else if (directClick) { - // scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y); + // scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y); } } From 2a59f37653052cf331cc363fd099c90dd6e72121 Mon Sep 17 00:00:00 2001 From: Robert Wartenberg Date: Wed, 16 Aug 2023 12:03:59 +0200 Subject: [PATCH 5/8] fix: tabs vs. spaces in DropDownList { } --- .../Scripts/Controls/ComboBox/DropDownList.cs | 262 +++++++++--------- 1 file changed, 131 insertions(+), 131 deletions(-) diff --git a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs index 46ea9d3..40e90c4 100644 --- a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs +++ b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs @@ -5,25 +5,25 @@ using System.Collections.Generic; namespace UnityEngine.UI.Extensions { - /// - /// Extension to the UI class which creates a dropdown list - /// - [RequireComponent(typeof(RectTransform))] + /// + /// Extension to the UI class which creates a dropdown list + /// + [RequireComponent(typeof(RectTransform))] [AddComponentMenu("UI/Extensions/ComboBox/Dropdown List")] public class DropDownList : MonoBehaviour { public Color disabledTextColor; public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it - [Header("Dropdown List Items")] - public List Items; + [Header("Dropdown List Items")] + public List Items; - [Header("Properties")] + [Header("Properties")] - [SerializeField] - private bool isActive = true; + [SerializeField] + private bool isActive = true; - public bool OverrideHighlighted = true; + public bool OverrideHighlighted = true; //private bool isInitialized = false; private bool _isPanelActive = false; @@ -46,13 +46,13 @@ namespace UnityEngine.UI.Extensions private List _panelItems = new List(); - private GameObject _itemTemplate; + private GameObject _itemTemplate; private bool _initialized; private string _defaultMainButtonCaption = null; private Color _defaultNormalColor; - [SerializeField] + [SerializeField] private float _scrollBarWidth = 20.0f; public float ScrollBarWidth { @@ -64,7 +64,7 @@ namespace UnityEngine.UI.Extensions } } - // private int scrollOffset; //offset of the selected item + // private int scrollOffset; //offset of the selected item private int _selectedIndex = -1; [SerializeField] @@ -79,42 +79,42 @@ namespace UnityEngine.UI.Extensions } } - [SerializeField] - private float dropdownOffset; + [SerializeField] + private float dropdownOffset; - [SerializeField] - private bool _displayPanelAbove = false; + [SerializeField] + private bool _displayPanelAbove = false; - public bool SelectFirstItemOnStart = false; + public bool SelectFirstItemOnStart = false; - [SerializeField] - private int selectItemIndexOnStart = 0; - private bool shouldSelectItemOnStart => SelectFirstItemOnStart || selectItemIndexOnStart > 0; + [SerializeField] + private int selectItemIndexOnStart = 0; + private bool shouldSelectItemOnStart => SelectFirstItemOnStart || selectItemIndexOnStart > 0; - [System.Serializable] + [System.Serializable] public class SelectionChangedEvent : Events.UnityEvent { } - // fires when item is changed; - [Header("Events")] - public SelectionChangedEvent OnSelectionChanged; + // fires when item is changed; + [Header("Events")] + public SelectionChangedEvent OnSelectionChanged; - [System.Serializable] - public class ControlDisabledEvent : Events.UnityEvent { } + [System.Serializable] + public class ControlDisabledEvent : Events.UnityEvent { } - // fires when item is changed; - public ControlDisabledEvent OnControlDisabled; + // fires when item is changed; + public ControlDisabledEvent OnControlDisabled; - public void Start() - { - Initialize(); - if (shouldSelectItemOnStart && Items.Count > 0) - { - SelectItemIndex(SelectFirstItemOnStart ? 0 : selectItemIndexOnStart); - } - RedrawPanel(); - } + public void Start() + { + Initialize(); + if (shouldSelectItemOnStart && Items.Count > 0) + { + SelectItemIndex(SelectFirstItemOnStart ? 0 : selectItemIndexOnStart); + } + RedrawPanel(); + } - private bool Initialize() + private bool Initialize() { if (_initialized) return true; @@ -153,32 +153,32 @@ namespace UnityEngine.UI.Extensions Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Reference Exception"); success = false; } - _initialized = true; + _initialized = true; - RebuildPanel(); + RebuildPanel(); RedrawPanel(); return success; } - /// + /// /// Update the drop down selection to a specific index /// /// public void SelectItemIndex(int index) - { - ToggleDropdownPanel(false); - OnItemClicked(index); - } + { + ToggleDropdownPanel(false); + OnItemClicked(index); + } - // currently just using items in the list instead of being able to add to it. - /// - /// Rebuilds the list from a new collection. - /// - /// - /// NOTE, this will clear all existing items - /// - /// - public void RefreshItems(params object[] list) + // currently just using items in the list instead of being able to add to it. + /// + /// Rebuilds the list from a new collection. + /// + /// + /// NOTE, this will clear all existing items + /// + /// + public void RefreshItems(params object[] list) { Items.Clear(); List ddItems = new List(); @@ -203,74 +203,74 @@ namespace UnityEngine.UI.Extensions } Items.AddRange(ddItems); RebuildPanel(); - RedrawPanel(); - } + RedrawPanel(); + } - /// - /// Adds an additional item to the drop down list (recommended) - /// - /// Item of type DropDownListItem - public void AddItem(DropDownListItem item) - { + /// + /// Adds an additional item to the drop down list (recommended) + /// + /// Item of type DropDownListItem + public void AddItem(DropDownListItem item) + { Items.Add(item); RebuildPanel(); RedrawPanel(); - } + } - /// - /// Adds an additional drop down list item using a string name - /// - /// Item of type String - public void AddItem(string item) + /// + /// Adds an additional drop down list item using a string name + /// + /// Item of type String + public void AddItem(string item) { Items.Add(new DropDownListItem(caption: (string)item)); RebuildPanel(); - RedrawPanel(); - } + RedrawPanel(); + } - /// - /// Adds an additional drop down list item using a sprite image - /// - /// Item of type UI Sprite - public void AddItem(Sprite item) + /// + /// Adds an additional drop down list item using a sprite image + /// + /// Item of type UI Sprite + public void AddItem(Sprite item) { Items.Add(new DropDownListItem(image: (Sprite)item)); RebuildPanel(); - RedrawPanel(); - } + RedrawPanel(); + } - /// - /// Removes an item from the drop down list (recommended) - /// - /// Item of type DropDownListItem - public void RemoveItem(DropDownListItem item) + /// + /// Removes an item from the drop down list (recommended) + /// + /// Item of type DropDownListItem + public void RemoveItem(DropDownListItem item) { Items.Remove(item); RebuildPanel(); - RedrawPanel(); - } + RedrawPanel(); + } - /// - /// Removes an item from the drop down list item using a string name - /// - /// Item of type String - public void RemoveItem(string item) + /// + /// Removes an item from the drop down list item using a string name + /// + /// Item of type String + public void RemoveItem(string item) { Items.Remove(new DropDownListItem(caption: (string)item)); RebuildPanel(); - RedrawPanel(); - } + RedrawPanel(); + } - /// - /// Removes an item from the drop down list item using a sprite image - /// - /// Item of type UI Sprite - public void RemoveItem(Sprite item) + /// + /// Removes an item from the drop down list item using a sprite image + /// + /// Item of type UI Sprite + public void RemoveItem(Sprite item) { Items.Remove(new DropDownListItem(image: (Sprite)item)); RebuildPanel(); - RedrawPanel(); - } + RedrawPanel(); + } public void ResetDropDown() { @@ -369,25 +369,25 @@ namespace UnityEngine.UI.Extensions _mainButton.txt.text = SelectedItem.Caption; - //update selected index color - if (OverrideHighlighted) - { - for (int i = 0; i < _itemsPanelRT.childCount; i++) - { - _panelItems[i].btnImg.color = (_selectedIndex == i) ? _mainButton.btn.colors.highlightedColor : new Color(0, 0, 0, 0); - } - } - } + //update selected index color + if (OverrideHighlighted) + { + for (int i = 0; i < _itemsPanelRT.childCount; i++) + { + _panelItems[i].btnImg.color = (_selectedIndex == i) ? _mainButton.btn.colors.highlightedColor : new Color(0, 0, 0, 0); + } + } + } private void RedrawPanel() { float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items _scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay); - float dropdownHeight = _itemsToDisplay > 0 ? _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) : _rectTransform.sizeDelta.y * _panelItems.Count; - dropdownHeight += dropdownOffset; + float dropdownHeight = _itemsToDisplay > 0 ? _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) : _rectTransform.sizeDelta.y * _panelItems.Count; + dropdownHeight += dropdownOffset; - if (!_hasDrawnOnce || _rectTransform.sizeDelta != _mainButton.rectTransform.sizeDelta) + if (!_hasDrawnOnce || _rectTransform.sizeDelta != _mainButton.rectTransform.sizeDelta) { _hasDrawnOnce = true; _mainButton.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x); @@ -397,12 +397,12 @@ namespace UnityEngine.UI.Extensions itemsRemaining = itemsRemaining < 0 ? 0 : itemsRemaining; _scrollPanelRT.SetParent(transform, true); - _scrollPanelRT.anchoredPosition = _displayPanelAbove ? - new Vector2(0, dropdownOffset + dropdownHeight) : - new Vector2(0, -(dropdownOffset + _rectTransform.sizeDelta.y)); + _scrollPanelRT.anchoredPosition = _displayPanelAbove ? + new Vector2(0, dropdownOffset + dropdownHeight) : + new Vector2(0, -(dropdownOffset + _rectTransform.sizeDelta.y)); - //make the overlay fill the screen - _overlayRT.SetParent(_canvas.transform, false); + //make the overlay fill the screen + _overlayRT.SetParent(_canvas.transform, false); _overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _canvasRT.sizeDelta.x); _overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _canvasRT.sizeDelta.y); @@ -412,7 +412,7 @@ namespace UnityEngine.UI.Extensions if (_panelItems.Count < 1) return; - _scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight); + _scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight); _scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x); _itemsPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _scrollPanelRT.sizeDelta.x - scrollbarWidth - 5); @@ -432,7 +432,7 @@ namespace UnityEngine.UI.Extensions /// whether an item was directly clicked on public void ToggleDropdownPanel(bool directClick) { - if (!isActive) return; + if (!isActive) return; _overlayRT.transform.localScale = new Vector3(1, 1, 1); _scrollBarRT.transform.localScale = new Vector3(1, 1, 1); @@ -448,17 +448,17 @@ namespace UnityEngine.UI.Extensions } } - /// - /// Updates the control and sets its active status, determines whether the dropdown will open ot not - /// - /// - public void SetActive(bool status) - { - if (status != isActive) - { - OnControlDisabled?.Invoke(status); - } - isActive = status; - } - } + /// + /// Updates the control and sets its active status, determines whether the dropdown will open ot not + /// + /// + public void SetActive(bool status) + { + if (status != isActive) + { + OnControlDisabled?.Invoke(status); + } + isActive = status; + } + } } \ No newline at end of file From 95f1956f48179662f0286173681ad460348123d7 Mon Sep 17 00:00:00 2001 From: Robert Wartenberg Date: Wed, 16 Aug 2023 14:47:35 +0200 Subject: [PATCH 6/8] fix: SetActive() takes care of btn. Add: ded. Hide funct --- .../Scripts/Controls/ComboBox/DropDownList.cs | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs index 40e90c4..2bbbf02 100644 --- a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs +++ b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs @@ -101,7 +101,7 @@ namespace UnityEngine.UI.Extensions [System.Serializable] public class ControlDisabledEvent : Events.UnityEvent { } - // fires when item is changed; + // fires when item changed between enabled and disabled; public ControlDisabledEvent OnControlDisabled; public void Start() @@ -427,38 +427,45 @@ namespace UnityEngine.UI.Extensions } /// - /// Toggle the drop down list + /// Toggle the drop down list if it's active /// - /// whether an item was directly clicked on + /// makes no difference, only for backwards compatibility reasons public void ToggleDropdownPanel(bool directClick) { - if (!isActive) return; + if (!isActive) + return; _overlayRT.transform.localScale = new Vector3(1, 1, 1); _scrollBarRT.transform.localScale = new Vector3(1, 1, 1); _isPanelActive = !_isPanelActive; _overlayRT.gameObject.SetActive(_isPanelActive); + if (_isPanelActive) - { transform.SetAsLastSibling(); - } - else if (directClick) - { - // scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y); - } + } + + /// + /// Hides the drop down panel if its visible at the moment + /// + public void HideDropDownPanel() + { + if (!_isPanelActive) + return; + ToggleDropdownPanel(false); } /// /// 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. /// /// public void SetActive(bool status) { - if (status != isActive) - { - OnControlDisabled?.Invoke(status); - } + if (status == isActive) + return; isActive = status; + OnControlDisabled?.Invoke(isActive); + _mainButton.btn.enabled = isActive; } } } \ No newline at end of file From 289a50d7966efb415976d72496217c868c23d436 Mon Sep 17 00:00:00 2001 From: "Simon (Darkside) Jackson" Date: Thu, 5 Oct 2023 16:53:04 +0100 Subject: [PATCH 7/8] Minor review corrections --- .../Scripts/Controls/ComboBox/DropDownList.cs | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs index 2bbbf02..00ff714 100644 --- a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs +++ b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs @@ -64,7 +64,6 @@ namespace UnityEngine.UI.Extensions } } - // private int scrollOffset; //offset of the selected item private int _selectedIndex = -1; [SerializeField] @@ -101,7 +100,7 @@ namespace UnityEngine.UI.Extensions [System.Serializable] public class ControlDisabledEvent : Events.UnityEvent { } - // fires when item changed between enabled and disabled; + // fires when item changes between enabled and disabled; public ControlDisabledEvent OnControlDisabled; public void Start() @@ -275,11 +274,15 @@ namespace UnityEngine.UI.Extensions 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; @@ -427,13 +430,24 @@ namespace UnityEngine.UI.Extensions } /// - /// Toggle the drop down list if it's active + /// Toggle the drop down list if it is active /// - /// makes no difference, only for backwards compatibility reasons - public void ToggleDropdownPanel(bool directClick) + /// Retained for backwards compatibility only. + [Obsolete("DirectClick Parameter is no longer required")] + public void ToggleDropdownPanel(bool directClick = false) + { + ToggleDropdownPanel(); + } + + /// + /// Toggle the drop down list if it is active + /// + public void ToggleDropdownPanel() { if (!isActive) + { return; + } _overlayRT.transform.localScale = new Vector3(1, 1, 1); _scrollBarRT.transform.localScale = new Vector3(1, 1, 1); @@ -441,7 +455,9 @@ namespace UnityEngine.UI.Extensions _overlayRT.gameObject.SetActive(_isPanelActive); if (_isPanelActive) + { transform.SetAsLastSibling(); + } } /// @@ -450,7 +466,10 @@ namespace UnityEngine.UI.Extensions public void HideDropDownPanel() { if (!_isPanelActive) + { return; + } + ToggleDropdownPanel(false); } @@ -462,7 +481,9 @@ namespace UnityEngine.UI.Extensions public void SetActive(bool status) { if (status == isActive) + { return; + } isActive = status; OnControlDisabled?.Invoke(isActive); _mainButton.btn.enabled = isActive; From 9a823060a792a7f3c0bc270183ddd6c22bbcf8c8 Mon Sep 17 00:00:00 2001 From: SimonDarksideJ Date: Thu, 5 Oct 2023 20:35:32 +0100 Subject: [PATCH 8/8] Update workflows --- ...=> development-buildandtestupmrelease.yml} | 15 +- .github/workflows/development-publish.yml | 26 +++ .github/workflows/main-publish.yml | 91 +++++++++ .github/workflows/refreshbranch.yml | 43 +++++ .../workflows/rununitybuildmultiversion.yml | 30 +-- .github/workflows/rununitysinglebuild.yml | 17 +- .github/workflows/tagrelease.yml | 131 ++++--------- .github/workflows/upversionandtagrelease.yml | 181 ++++++++++++++++++ 8 files changed, 400 insertions(+), 134 deletions(-) rename .github/workflows/{buildupmpackages.yml => development-buildandtestupmrelease.yml} (65%) create mode 100644 .github/workflows/development-publish.yml create mode 100644 .github/workflows/main-publish.yml create mode 100644 .github/workflows/refreshbranch.yml create mode 100644 .github/workflows/upversionandtagrelease.yml diff --git a/.github/workflows/buildupmpackages.yml b/.github/workflows/development-buildandtestupmrelease.yml similarity index 65% rename from .github/workflows/buildupmpackages.yml rename to .github/workflows/development-buildandtestupmrelease.yml index 01e1795..a61beba 100644 --- a/.github/workflows/buildupmpackages.yml +++ b/.github/workflows/development-buildandtestupmrelease.yml @@ -1,10 +1,10 @@ -name: Build and test UPM packages for platforms on all available Unity Versions +name: Build and test UPM packages for platforms, all branches except main on: pull_request: branches-ignore: - 'release' - # Ignore PRs targetting main + # Ignore PRs targeting main # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -14,6 +14,7 @@ concurrency: cancel-in-progress: true jobs: + # Check Unity version required by the package # Run Unity build unit tests defined in the package for a single version for feature branches Run-Partial-Unit-Tests: name: Run Unity Unit Tests @@ -26,12 +27,4 @@ jobs: Run-Full-Unit-Tests: name: Run Unity Unit Tests if: github.ref == 'refs/heads/development' - uses: ./.github/workflows/rununitybuildmultiversion.yml - - # Update the package release version - Update-Version: - name: Update Package Version - uses: ./.github/workflows/tagrelease.yml - with: - build-target: windows - secrets: inherit + uses: ./.github/workflows/rununitybuildmultiversion.yml \ No newline at end of file diff --git a/.github/workflows/development-publish.yml b/.github/workflows/development-publish.yml new file mode 100644 index 0000000..a770e9d --- /dev/null +++ b/.github/workflows/development-publish.yml @@ -0,0 +1,26 @@ +name: Publish development branch on Merge + +on: + pull_request: + types: + - closed + branches: + - development + # On close of PR targeting development + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + release_on_merge: + if: github.event.pull_request.merged == true + name: Tag and Publish UPM package + uses: ./.github/workflows/upversionandtagrelease.yml + with: + build-host: ubuntu-latest + build-type: pre-release + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/main-publish.yml b/.github/workflows/main-publish.yml new file mode 100644 index 0000000..9120cb9 --- /dev/null +++ b/.github/workflows/main-publish.yml @@ -0,0 +1,91 @@ +name: Publish main branch and increment version + +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + # Get Version to tag and release the branch, no up-version - [no-ver] included in PR title + validate-environment: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver') + name: Get Version from UPM package + uses: ./.github/workflows/getpackageversionfrompackage.yml + with: + build-host: ubuntu-latest + + # Perform tagging + release-Package-only: + needs: validate-environment + name: Release package only, no upversion + uses: ./.github/workflows/tagrelease.yml + with: + build-host: ubuntu-latest + version: ${{ needs.validate-environment.outputs.packageversion }} + secrets: inherit + + # Up version the release and publish major release + upversion-major-Package: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver') == false && contains(github.event.pull_request.title, 'major-release') + name: Major Version package and release + uses: ./.github/workflows/upversionandtagrelease.yml + with: + build-host: ubuntu-latest + build-type: major + secrets: inherit + + # Up version the release and publish minor release + upversion-minor-Package: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver') == false && contains(github.event.pull_request.title, 'minor-release') + name: Minor Version package and release + uses: ./.github/workflows/upversionandtagrelease.yml + with: + build-host: ubuntu-latest + build-type: minor + secrets: inherit + + # Up version the release and publish patch release (default) + upversion-patch-Package: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver') == false && contains(github.event.pull_request.title, 'minor-release') == false && contains(github.event.pull_request.title, 'major-release') == false + name: Patch Version package and release + uses: ./.github/workflows/upversionandtagrelease.yml + with: + build-host: ubuntu-latest + build-type: patch-release + secrets: inherit + + release-Complete: + if: ${{ always() }} + needs: [upversion-major-Package, upversion-minor-Package, upversion-patch-Package, release-Package-only] + name: Release complete + runs-on: ubuntu-latest + steps: + - name: Script Version + run: echo "Release done, updating Development" + + # Refresh the development branch with the main publish + refresh-development: + if: ${{ always() }} + needs: [release-Complete] + name: Refresh development branch + uses: ./.github/workflows/refreshbranch.yml + with: + build-host: ubuntu-latest + target-branch: development + source-branch: main + secrets: inherit + + # Up version the development branch ready for future development + upversion-development: + if: ${{ always() }} + needs: [refresh-development] + name: UpVersion the development branch for the next release + uses: ./.github/workflows/upversionandtagrelease.yml + with: + build-host: ubuntu-latest + build-type: patch + target-branch: development + createTag: false + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/refreshbranch.yml b/.github/workflows/refreshbranch.yml new file mode 100644 index 0000000..fb8a021 --- /dev/null +++ b/.github/workflows/refreshbranch.yml @@ -0,0 +1,43 @@ +name: Refresh branch + +on: + workflow_call: + inputs: + build-host: + required: true + type: string + target-branch: + required: true + type: string + source-branch: + required: true + type: string + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + packageRelease: + name: Refresh ${{ inputs.target-branch }} branch from ${{ inputs.source-branch }} branch + runs-on: ${{ inputs.build-host }} + steps: + - name: Script Version + run: | + echo "::group::Script Versioning" + $scriptVersion = "1.0.1" + echo "Build Script Version: $scriptVersion" + echo "::endgroup::" + shell: pwsh + - uses: actions/checkout@v3 + with: + ref: ${{ inputs.target-branch }} + clean: true + token: ${{ secrets.GIT_PAT }} + - name: Refresh from Source Branch + run: | + git pull origin ${{ inputs.source-branch }} + git commit -m "Branch ${{ inputs.target-branch }} updated with changes from ${{ inputs.source-branch }} [skip ci]" + git push origin ${{ inputs.target-branch }} + echo "Branch ${{ inputs.target-branch }} updated with changes from ${{ inputs.source-branch }}" + shell: pwsh \ No newline at end of file diff --git a/.github/workflows/rununitybuildmultiversion.yml b/.github/workflows/rununitybuildmultiversion.yml index bd98ccf..ffd309c 100644 --- a/.github/workflows/rununitybuildmultiversion.yml +++ b/.github/workflows/rununitybuildmultiversion.yml @@ -18,7 +18,7 @@ jobs: - os: windows unityVersion: 2019.4 build-target: Android - - os: macos + - os: macOS unityVersion: 2019.4 build-target: iOS - os: windows @@ -30,7 +30,7 @@ jobs: - os: windows unityVersion: 2020.3 build-target: Android - - os: macos + - os: macOS unityVersion: 2020.3 build-target: iOS - os: windows @@ -42,7 +42,7 @@ jobs: - os: windows unityVersion: 2021.3 build-target: Android - - os: macos + - os: macOS unityVersion: 2021.3 build-target: iOS - os: windows @@ -54,7 +54,7 @@ jobs: - os: windows unityVersion: 2022.2 build-target: Android - - os: macos + - os: macOS unityVersion: 2022.2 build-target: iOS - os: windows @@ -80,7 +80,7 @@ jobs: name: 'Run Unity Builds' run: | echo "::group::Set Hub and editor locations" - $unityVersion = ${{ matrix.unityVersion }} + $unityVersion = '${{ matrix.unityVersion }}' echo "::group::Set Hub and editor locations" @@ -90,6 +90,7 @@ jobs: $hubPath = "C:\Program Files\Unity Hub\Unity Hub.exe" $editorRootPath = "C:\Program Files\Unity\Hub\Editor\" $editorFileEx = "\Editor\Unity.exe" + $directorySeparatorChar = "\" #"Unity Hub.exe" -- --headless help #. 'C:\Program Files\Unity Hub\Unity Hub.exe' -- --headless help @@ -100,11 +101,12 @@ jobs: } elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) { - $hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" + $hubPath = "/Applications/Unity Hub.app/Contents/macOS/Unity Hub" $editorRootPath = "/Applications/Unity/Hub/Editor/" - $editorFileEx = "/Unity.app/Contents/MacOS/Unity" + $editorFileEx = "/Unity.app/Contents/macOS/Unity" + $directorySeparatorChar = "/" - # /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help + # /Applications/Unity\ Hub.app/Contents/macOS/Unity\ Hub -- --headless help function unity-hub { & $hubPath -- --headless $args.Split(" ") | Out-String -NoNewline @@ -115,6 +117,7 @@ jobs: $hubPath = "$HOME/Unity Hub/UnityHub.AppImage" $editorRootPath = "$HOME/Unity/Hub/Editor/" $editorFileEx = "/Editor/Unity" + $directorySeparatorChar = "/" # /UnityHub.AppImage --headless help # xvfb-run --auto-servernum "$HOME/Unity Hub/UnityHub.AppImage" --headless help @@ -126,8 +129,6 @@ jobs: echo "::endgroup::" - - echo "::group::Get String function to query a string for a value" function GetString($InputString, $InputPattern, $MatchIndex) @@ -151,10 +152,9 @@ jobs: echo "::endgroup::" echo "::group::Get Installed Unity version based on Matrix" - echo 'Script Start' echo "Unity hub path is {$hubPath}" echo "Requested unity version is {$unityVersion}" - + $InstalledUnityVersions = unity-hub editors $editorRootPath = unity-hub ip -g echo "Installed unity versions are {$InstalledUnityVersions}" @@ -171,7 +171,7 @@ jobs: $queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion" -MatchIndex 0 } - echo "Found unity version is {$queryUnityVersion}" + echo "Found unity version is {$queryUnityVersion} for input {$unityVersion}" if ($queryUnityVersion -ne 0) { @@ -218,7 +218,7 @@ jobs: } elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) { echo 'Building using Mac' - $editorFileEx = "/Unity.app/Contents/MacOS/Unity" + $editorFileEx = "/Unity.app/Contents/macOS/Unity" $editorrunpath = Join-Path $editorRootPath $unityVersion $editorFileEx function unity-editor { @@ -456,4 +456,4 @@ jobs: if: always() with: name: unity-build-log - path: Logs/** \ No newline at end of file + path: Logs/** \ No newline at end of file diff --git a/.github/workflows/rununitysinglebuild.yml b/.github/workflows/rununitysinglebuild.yml index 58404ce..d6ba283 100644 --- a/.github/workflows/rununitysinglebuild.yml +++ b/.github/workflows/rununitysinglebuild.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: include: - - os: macos + - os: macOS build-target: iOS - os: windows build-target: Android @@ -40,12 +40,11 @@ jobs: with: submodules: recursive clean: true - - id: build name: 'Run Unity Builds' run: | echo "::group::Set Hub and editor locations" - $unityVersion = ${{ inputs.unityVersion }} + $unityVersion = '${{ inputs.unityVersion }}' echo "::group::Set Hub and editor locations" @@ -55,6 +54,7 @@ jobs: $hubPath = "C:\Program Files\Unity Hub\Unity Hub.exe" $editorRootPath = "C:\Program Files\Unity\Hub\Editor\" $editorFileEx = "\Editor\Unity.exe" + $directorySeparatorChar = "\" #"Unity Hub.exe" -- --headless help #. 'C:\Program Files\Unity Hub\Unity Hub.exe' -- --headless help @@ -68,6 +68,7 @@ jobs: $hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" $editorRootPath = "/Applications/Unity/Hub/Editor/" $editorFileEx = "/Unity.app/Contents/MacOS/Unity" + $directorySeparatorChar = "/" # /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help function unity-hub @@ -80,6 +81,7 @@ jobs: $hubPath = "$HOME/Unity Hub/UnityHub.AppImage" $editorRootPath = "$HOME/Unity/Hub/Editor/" $editorFileEx = "/Editor/Unity" + $directorySeparatorChar = "/" # /UnityHub.AppImage --headless help # xvfb-run --auto-servernum "$HOME/Unity Hub/UnityHub.AppImage" --headless help @@ -91,8 +93,6 @@ jobs: echo "::endgroup::" - - echo "::group::Get String function to query a string for a value" function GetString($InputString, $InputPattern, $MatchIndex) @@ -115,8 +115,7 @@ jobs: } echo "::endgroup::" - echo "::group::Get Installed Unity version based on Matrix" - echo 'Script Start' + echo "::group::Find Installed Unity version based on input" echo "Unity hub path is {$hubPath}" echo "Requested unity version is {$unityVersion}" @@ -136,7 +135,7 @@ jobs: $queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion" -MatchIndex 0 } - echo "Found unity version is {$queryUnityVersion}" + echo "Found unity version is {$queryUnityVersion} for input {$unityVersion}" if ($queryUnityVersion -ne 0) { @@ -421,4 +420,4 @@ jobs: if: always() with: name: unity-build-log - path: Logs/** \ No newline at end of file + path: Logs/** \ No newline at end of file diff --git a/.github/workflows/tagrelease.yml b/.github/workflows/tagrelease.yml index c690863..d572d76 100644 --- a/.github/workflows/tagrelease.yml +++ b/.github/workflows/tagrelease.yml @@ -1,33 +1,26 @@ -name: Package UPM project and deploy +name: Tag Release on: workflow_call: inputs: - build-target: + build-host: + required: true + type: string + version: required: true type: string - build-type: - required: false - default: 'pre-release' - type: string -# options: -# - major -# - minor -# - patch -# - pre-release -# - build - outputs: - packageversion: - description: "Returns the version of Unity the UPM package requires" - value: ${{ jobs.packageRelease.outputs.packageversion }} - secrets: - GIT_USER_NAME: - required: false + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true jobs: packageRelease: name: Package UPM Project and tag - runs-on: ${{ inputs.build-target }} + runs-on: ${{ inputs.build-host }} outputs: packageversion: ${{ steps.getpackageversion.outputs.packageversion }} steps: @@ -40,6 +33,7 @@ jobs: shell: pwsh - uses: actions/checkout@v3 with: + fetch-depth: 0 submodules: recursive clean: true token: ${{ secrets.GIT_PAT }} @@ -60,87 +54,26 @@ jobs: $gitUser = "${{ secrets.GIT_USER_NAME }}" $gitEmail = "$gitUser@users.noreply.github.com" } - echo "email $gitUser@users.noreply.github.com" git config --global user.email "$gitUser@users.noreply.github.com" git config --global user.name "$gitUser" - shell: pwsh - - id: getpackageversion - name: Bump UPM Package version + shell: pwsh + - name: Check if Tag Exists run: | - function UpdateProjectVersionJSON { - param ( - [Parameter(Mandatory)] - $type, - $packageFile = 'package.json' - ) - <# - Type of build can be one of the following - - 'build' # Build release - 1.0.0-pre-release.0+1 - - 'pre-release' # Pre-Release release - 1.0.0-pre-release.1 - - 'patch' # Patch release - 1.0.1 - - 'minor' # Minor release - 1.1.0 - - 'major' # Major release - 2.0.0 - #> - - if ( -not (Test-Path -Path $packageFile) ) { - Write-Error "Failed to find a valid project manifest at `"$packageFile`"" - return $null + $tagVersion = "${{ inputs.version }}" + $tags = git tag + echo "Tags found are [$tags], searching for [$tagVersion]" + foreach ($tag in $tags) + { + if($tag.Trim() -eq "$tagVersion") + { + Write-Error "$tagVersion tag already exists" + exit 1 } - - $packageInfo = (Get-Content $packageFile -Raw) | ConvertFrom-Json - Write-Host "Detected Project Version:" $packageInfo.version - function IfNull($a, $b, $c) { if ($null -eq $a) { return $b } else { return $c } } - - $packageSemVer = [System.Management.Automation.SemanticVersion]$packageInfo.version - $majorVersion = if($null -eq $packageSemVer.Major) {0} else {$packageSemVer.Major} - $minorVersion = if($null -eq $packageSemVer.Minor) {0} else {$packageSemVer.Minor} - $patchVersion = if($null -eq $packageSemVer.Patch) {0} else {$packageSemVer.Patch} - $prereleaseVersion = if($null -eq $packageSemVer.PreReleaseLabel) {0} else {$packageSemVer.PreReleaseLabel.Replace('pre-release.','')} - $buildVersion = if($null -eq $packageSemVer.BuildLabel) {0} else {$packageSemVer.BuildLabel} - - # work out new version - switch ($type) { - 'build' { - [int]$buildVersion += 1 - $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre-release." + $prereleaseVersion, $buildVersion) - } - 'pre-release' { - [int]$prereleaseVersion += 1 - $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre-release." + $prereleaseVersion) - } - 'patch' { - [int]$patchVersion += 1 - $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion) - } - 'minor' { - [int]$minorVersion += 1 - $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, 0) - } - 'major' { - [int]$majorVersion += 1 - $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, 0, 0) - } - } - - Write-Host "Upgrading project version [$packageSemVer] to [$newPackageSemVer]" - - # Write out updated package info - - $packageInfo.version = $newPackageSemVer.ToString() - $packageInfo | ConvertTo-Json | Set-Content $packageFile - - return $packageInfo.version } - - $packageFile = 'package.json' - $result = UpdateProjectVersionJSON("${{ inputs.build-type }}","$packageFile") - if([string]::IsNullOrEmpty($result)) { - echo "Version patch failed" - exit 1 - } - echo "packageversion=$result" >> $env:GITHUB_OUTPUT - git add "$packageFile" - git commit -m "Auto increment pre-release version to $result [skip ci]" - git tag -fa "$result" "${GITHUB_SHA}" -m "$result Release" - git push origin --force - shell: pwsh \ No newline at end of file + shell: pwsh + - name: Create tag and push + run: | + $tagVersion = "${{ inputs.version }}" + git tag -fa "v$tagVersion" "${GITHUB_SHA}" -m "v$tagVersion Release [skip ci]" + git push origin "v$tagVersion" --force + shell: pwsh \ No newline at end of file diff --git a/.github/workflows/upversionandtagrelease.yml b/.github/workflows/upversionandtagrelease.yml new file mode 100644 index 0000000..4e630ba --- /dev/null +++ b/.github/workflows/upversionandtagrelease.yml @@ -0,0 +1,181 @@ +name: UpVersion Package UPM project and create new tag + +on: + workflow_call: + inputs: + build-host: + required: true + type: string + build-type: + required: false + default: 'pre-release' + type: string +# options: +# - major +# - minor +# - patch +# - patch-release +# - pre-release +# - build + target-branch: + required: false + type: string + default: ${{ github.ref }} + createTag: + required: false + type: boolean + default: true + + outputs: + packageversion: + description: "Returns the version of Unity the UPM package requires" + value: ${{ jobs.packageRelease.outputs.packageversion }} + secrets: + GIT_PAT: + required: true + +jobs: + packageRelease: + name: Package UPM Project and tag + runs-on: ${{ inputs.build-host }} + outputs: + packageversion: ${{ steps.getpackageversion.outputs.packageversion }} + steps: + - name: Script Version + run: | + echo "::group::Script Versioning" + $scriptVersion = "1.0.2" + echo "Build Script Version: $scriptVersion" + echo "::endgroup::" + shell: pwsh + - uses: actions/checkout@v3 + with: + ref: ${{ inputs.target-branch }} + fetch-depth: 0 + submodules: recursive + clean: true + token: ${{ secrets.GIT_PAT }} + - uses: actions/setup-node@v3 + - name: Set Github vars + run: | + if([string]::IsNullOrEmpty('${{ secrets.GIT_USER_NAME }}')){ + if([string]::IsNullOrEmpty('${{ secrets.GIT_USER_NAME }}')){ + $gitUser = "action" + $gitEmail = "action@github.com" + } + else { + $gitUser = "${GITHUB_ACTOR}" + $gitEmail = "$gitUser@users.noreply.github.com" + } + } + else { + $gitUser = "${{ secrets.GIT_USER_NAME }}" + $gitEmail = "$gitUser@users.noreply.github.com" + } + git config --global user.email "$gitUser@users.noreply.github.com" + git config --global user.name "$gitUser" + shell: pwsh + - id: getpackageversion + name: Bump UPM Package version + run: | + function UpdateProjectVersionJSON { + param ( + [Parameter(Mandatory)] + $type, + $packageFile = 'package.json' + ) + <# + Type of build can be one of the following + - 'build' # Build release - 1.0.0-pre.0+1 + - 'pre-release' # Pre-Release - 1.0.0-pre.1 + - 'patch-release' # Patch release - 1.0.1 (reset preview version to current patch, no increase) + - 'patch' # Patch release - 1.0.1 + - 'minor' # Minor release - 1.1.0 + - 'major' # Major release - 2.0.0 + #> + + if ( -not (Test-Path -Path $packageFile) ) { + Write-Error "Failed to find a valid project manifest at `"$packageFile`"" + return $null + } + + $packageInfo = (Get-Content $packageFile -Raw) | ConvertFrom-Json + Write-Host "Detected Project Version:" $packageInfo.version + function IfNull($a, $b, $c) { if ($null -eq $a) { return $b } else { return $c } } + + $packageSemVer = [System.Management.Automation.SemanticVersion]$packageInfo.version + $majorVersion = if($null -eq $packageSemVer.Major) {0} else {$packageSemVer.Major} + $minorVersion = if($null -eq $packageSemVer.Minor) {0} else {$packageSemVer.Minor} + $patchVersion = if($null -eq $packageSemVer.Patch) {0} else {$packageSemVer.Patch} + $prereleaseVersion = if($null -eq $packageSemVer.PreReleaseLabel) {0} else {$packageSemVer.PreReleaseLabel.Replace('pre.','')} + $buildVersion = if($null -eq $packageSemVer.BuildLabel) {0} else {$packageSemVer.BuildLabel} + + # work out new version + switch ($type) { + 'build' { + [int]$buildVersion += 1 + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre." + $prereleaseVersion, $buildVersion) + } + 'pre-release' { + [int]$prereleaseVersion += 1 + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre." + $prereleaseVersion) + } + 'patch-release' { + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion) + } + 'patch' { + [int]$patchVersion += 1 + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion) + } + 'minor' { + [int]$minorVersion += 1 + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, 0) + } + 'major' { + [int]$majorVersion += 1 + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, 0, 0) + } + } + + Write-Host "Upgrading project version [$packageSemVer] to [$newPackageSemVer]" + + # Write out updated package info + + $packageInfo.version = $newPackageSemVer.ToString() + $packageInfo | ConvertTo-Json | Set-Content $packageFile + + return $packageInfo.version + } + + $packageFile = 'package.json' + $result = UpdateProjectVersionJSON("${{ inputs.build-type }}","$packageFile") + if([string]::IsNullOrEmpty($result)) { + echo "Version patch failed" + exit 1 + } + git add "$packageFile" + git commit -m "Auto increment pre-release version to $result [skip ci]" + git push origin + echo "packageversion=$result" >> $env:GITHUB_OUTPUT + shell: pwsh + - name: Check if Tag Exists + run: | + $tagVersion = '${{steps.getpackageversion.outputs.packageversion }}' + $tags = git tag + echo "Tags found are [$tags], searching for [$tagVersion]" + foreach ($tag in $tags) + { + if($tag.Trim() -eq "$tagVersion") + { + Write-Error "$tagVersion tag already exists" + exit 1 + } + } + shell: pwsh + - name: Publish package tag + if: ${{inputs.createTag == true}} + run: | + $outputVersion = '${{steps.getpackageversion.outputs.packageversion }}' + git tag -fa "v$outputVersion" "${GITHUB_SHA}" -m "v$outputVersion Release" + git push origin "v$outputVersion" --force --tags + shell: pwsh \ No newline at end of file