Merged in development (pull request #122)

Development

* Merged in updated_new_input_system_check (pull request #117)

Updated the new Input system switch and tested against 2021

* Updated LineRenderer to initialise with a 1 point array, this resolves an issue with Unity putting the previous controls vertext array in an uninitialised control.
Also updated examples checkout

* Merged in UpdatedLineRender (pull request #118)

UILineRender now initilises with a point of 1 to correct Unity issue

* Applied J.R. Mitchell's fix for the Accordion Controls/Accordion/AccordionElement.cs

resolves: #364

* Merged in AccordionFIx (pull request #119)

Update to Accordion to allow for prefab Accordion Elements

* Resolved issue where the Content Scroll snap would cause issue with only 1 child.
Also tested and fixed working with no children.

Resolves #362

* Merged in content_scroll_snap_fix (pull request #120)

ContentScrollSnap update

* Updated the PaginationManager to override if the ScrollSnap is in motion.
BuyerBeware, Unity's toggles can get in to a state where they are clicked but not clicked.

* Merged in PaginationFix (pull request #121)

Updated the PaginationManager to override if the ScrollSnap is in motion.

* Updated release notes and bumped version to release
release
Simon Jackson 2021-05-10 17:38:31 +00:00
parent 1dbf2679fa
commit 383e19fb05
23 changed files with 601 additions and 397 deletions

3
.gitignore vendored
View File

@ -36,4 +36,5 @@ sysinfo.txt
# UPM Build updates # UPM Build updates
[Ee]xamples [Ee]xamples
[Ee]xamples.meta [Ee]xamples.meta
bitbucket-pipelines.yml.meta

View File

@ -35,8 +35,8 @@ sysinfo.txt
/.vs /.vs
# UPM Build updates # UPM Build updates
[Ee]xamples
[Ee]xamples.meta [Ee]xamples.meta
# NPM publish exclusions # NPM publish exclusions
bitbucket-pipelines.yml bitbucket-pipelines.yml
bitbucket-pipelines.yml.meta

View File

@ -4,34 +4,37 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/). The format is based on [Keep a Changelog](http://keepachangelog.com/).
## 2019.5 (v2.3) - 2020-10-31 ## 2019.6 - 2.5 - Bug squash - 2021/05/10
Its been a while since the last update and although Unity keeps changing, thankfully the parts underneath do not. THanks to some awesome work by our contributors and the test teams, we made a run on some underlying bugs and issues. If you spot anything else, please log it on the BitBucket site for resolution.
> Be sure to logon to the new [Gitter Chat](https://gitter.im/Unity-UI-Extensions/Lobby) site for the UI Extensions project, if you have any questions, queries or suggestions
>
> Much easier that posting a question / issue on YouTube, Twitter or Facebook :D
>
> ## [UIExtensions Gitter Channel](https://gitter.im/Unity-UI-Extensions/Lobby)
Since the move to UPM, the team have been able to react quicker and push out fixes a lot easier, without affecting previous installation (whilst still adhering to Unity's backwards compatibility pattern). So it is with great news we announce this new release, faster that ever :D (and thanks to UPM, easier to upgrade than ever).
Be sure to also check out the "Examples" option in the Package Manager window to import the samples to your project.
### Added ### Added
- Add squircle primitive Nothing new this time, bugfix release.
- Adding new magnetic scroll control
- Added a static library to collate shaders on first use.
- Finalized new InputManagerHelper, which translates input based on the operating input system, new or old Updated CardStack2D to have defined keyboard input or specific gamepad input over the older axisname for new input system.
- Updated DropDown and Autocomplete controls based on feedback in #204
### Changed ### Changed
- Examples now included with UPM delivery and available as a button on the UPM package manager window - Updated UI Line connector to use relative position instead of anchored position to verify if the Lines need updating.
- Updated DropDown and Autocomplete controls based on feedback in #204 - Allow menu prefabs to not have to have canvas components. This allows you to use any type of prefab as a "menu". Adam Kapos mentions the concept on the Unite talk, https://youtu.be/wbmjturGbAQ?t=1654
- Updated Accordion to support both Vertical as well as Horizontal layout - Updated segment line drawing for Line Lists. Seems Unity no longer needs UV's to be wrapped manually.
- Updated ComboBox controls to improve better programmatic controls - Updated the AutoCompleteComboBox to display text as entered (instead of all lowercase)
- Updates to the Infinite scroll to support content of various sizes - Updated the ComboBox to display text as entered (instead of all lowercase)
- Updated UI Knob control - enabled dragging outside the target area, added example scene - Updated ComboBox Examples to include programmatic versions
- Minor update to MagneticInfinite Scroll - Further ComboBox improvements including:
- Refactored and extended the ContentScrollSnap control * Upwards panel
- Added protection against errors and empty scrollrect content * Start fixes
- Added new SetNewItems function to add children programmatically to the control and reset accordingly * Item Template resize
- Patch supplied by a contributor to improve the texture sheet use with the UIParticlesystem * Disabled sorting on combobox as it wasn't working
- Added "SetKnobValue" function which allows the setting of Value and loops * Disabled Slider handle when not in use
- Added the programmatic capability to change the parent scroll rect on the ScrollConflictManager at runtime. * Updated Example
- Updated the new Input system switch and tested against 2021
### Deprecated ### Deprecated
@ -39,20 +42,15 @@ None
### Fixed ### Fixed
- Fix to add a "RequireComponent" to Primitives as Unity 2020 does not add them by default - Reordering issue resolved with ScrollRectOcclusion.
- Remove old Examples submodule - Fixed Sorting at min and max positions for ScrollRect
- Updated submodules to hide Examples folder Additionally, updated Package manifest to allow importing of examples direct from UPM package. - Updated ScrollToSelect script provided by zero3growlithe, tested and vastly reduces the previous jitter. Still present but barely noticeable now.
- Fixed hard swipe to ensure it only ever moves one page, no matter how far you swipe. - Fixed Issue # 363 Update Combobox control that takes multiple items programmatically, to only allow distinct items
- Fixed a conflict when using the ScrollConflictManager in child content of a HSS or VSS - Fixed the issues where dragging outside the range slider handle causes the range to update. - Resolves #369
- Fix for UI Particle system looping - Resolves an issue with Unity putting the previous controls vertex array in an uninitialised control.
- Fixed public GoToScreen call to only raise events internally (not multiple) - Applied J.R. Mitchell's fix for the Accordion Controls/Accordion/AccordionElement.cs - resolves: #364
- Final roll-up and fix. Resolved race condition for associated pagination controls. - Resolved issue where the Content Scroll snap issue with only 1 child. Resolves #362
- Fixed issue with page events not being raised when inertia was disabled (velocity was always zero) - Updated the PaginationManager to override if the ScrollSnap is in motion.
- When cloned, reorderable list was creating a second List Content component that was not initialized. Refactored to ensure only one list content was present and is initialized correctly
- Reorderable list items marked as transferable, remain transferable after being dropped
- Patch to resolve issues without the new Input System installed
- Refined magnetic scroll and dependencies while documenting Updated example
- Patch Tooltip
### Removed ### Removed

View File

@ -39,31 +39,28 @@ This version of the Unity UI Extensions is compatible with the following version
## [Release Notes](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/ReleaseNotes/RELEASENOTES) ## [Release Notes](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/ReleaseNotes/RELEASENOTES)
### 2019.5 - 2.3 - Accelerated Deployment ### 2019.6 - 2.5 - Bug squash
#### Added #### Added
- Add squircle primitive Nothing new this time, bugfix release.
- Adding new magnetic scroll control
- Added a static library to collate shaders on first use.
- Finalized new InputManagerHelper, which translates input based on the operating input system, new or old Updated CardStack2D to have defined keyboard input or specific gamepad input over the older axisname for new input system.
- Updated DropDown and Autocomplete controls based on feedback in #204
#### Changed #### Changed
- Examples now included with UPM delivery and available as a button on the UPM package manager window - Updated UI Line connector to use relative position instead of anchored position to verify if the Lines need updating.
- Updated DropDown and Autocomplete controls based on feedback in #204 - Allow menu prefabs to not have to have canvas components. This allows you to use any type of prefab as a "menu". Adam Kapos mentions the concept on the Unite talk, https://youtu.be/wbmjturGbAQ?t=1654
- Updated Accordion to support both Vertical as well as Horizontal layout - Updated segment line drawing for Line Lists. Seems Unity no longer needs UV's to be wrapped manually.
- Updated ComboBox controls to improve better programmatic controls - Updated the AutoCompleteComboBox to display text as entered (instead of all lowercase)
- Updates to the Infinite scroll to support content of various sizes - Updated the ComboBox to display text as entered (instead of all lowercase)
- Updated UI Knob control - enabled dragging outside the target area, added example scene - Updated ComboBox Examples to include programmatic versions
- Minor update to MagneticInfinite Scroll - Further ComboBox improvements including:
- Refactored and extended the ContentScrollSnap control * Upwards panel
- Added protection against errors and empty scrollrect content * Start fixes
- Added new SetNewItems function to add children programmatically to the control and reset accordingly * Item Template resize
- Patch supplied by a contributor to improve the texture sheet use with the UIParticlesystem * Disabled sorting on combobox as it wasn't working
- Added "SetKnobValue" function which allows the setting of Value and loops * Disabled Slider handle when not in use
- Added the programmatic capability to change the parent scroll rect on the ScrollConflictManager at runtime. * Updated Example
- Updated the new Input system switch and tested against 2021
#### Deprecated #### Deprecated
@ -71,20 +68,15 @@ None
#### Fixed #### Fixed
- Fix to add a "RequireComponent" to Primitives as Unity 2020 does not add them by default - Reordering issue resolved with ScrollRectOcclusion.
- Remove old Examples submodule - Fixed Sorting at min and max positions for ScrollRect
- Updated submodules to hide Examples folder Additionally, updated Package manifest to allow importing of examples direct from UPM package. - Updated ScrollToSelect script provided by zero3growlithe, tested and vastly reduces the previous jitter. Still present but barely noticeable now.
- Fixed hard swipe to ensure it only ever moves one page, no matter how far you swipe. - Fixed Issue # 363 Update Combobox control that takes multiple items programmatically, to only allow distinct items
- Fixed a conflict when using the ScrollConflictManager in child content of a HSS or VSS - Fixed the issues where dragging outside the range slider handle causes the range to update. - Resolves #369
- Fix for UI Particle system looping - Resolves an issue with Unity putting the previous controls vertex array in an uninitialised control.
- Fixed public GoToScreen call to only raise events internally (not multiple) - Applied J.R. Mitchell's fix for the Accordion Controls/Accordion/AccordionElement.cs - resolves: #364
- Final roll-up and fix. Resolved race condition for associated pagination controls. - Resolved issue where the Content Scroll snap issue with only 1 child. Resolves #362
- Fixed issue with page events not being raised when inertia was disabled (velocity was always zero) - Updated the PaginationManager to override if the ScrollSnap is in motion.
- When cloned, reorderable list was creating a second List Content component that was not initialized. Refactored to ensure only one list content was present and is initialized correctly
- Reorderable list items marked as transferable, remain transferable after being dropped
- Patch to resolve issues without the new Input System installed
- Refined magnetic scroll and dependencies while documenting Updated example
- Patch Tooltip
#### Removed #### Removed

View File

@ -806,7 +806,8 @@ namespace UnityEditor.UI
//Setup Template //Setup Template
itemTemplate.name = "ItemTemplate"; itemTemplate.name = "ItemTemplate";
var itemTemplateRT = itemTemplate.GetComponent<RectTransform>(); var itemTemplateRT = itemTemplate.GetComponent<RectTransform>();
itemTemplateRT.sizeDelta = cbbRT.sizeDelta; itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10,0);
itemTemplateRT.anchoredPosition = new Vector2(-5, 0);
var itemTemplateButton = itemTemplate.GetComponent<Button>(); var itemTemplateButton = itemTemplate.GetComponent<Button>();
itemTemplateButton.transition = Selectable.Transition.None; itemTemplateButton.transition = Selectable.Transition.None;
var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>(); var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>();
@ -902,7 +903,8 @@ namespace UnityEditor.UI
//Setup Template //Setup Template
itemTemplate.name = "ItemTemplate"; itemTemplate.name = "ItemTemplate";
var itemTemplateRT = itemTemplate.GetComponent<RectTransform>(); var itemTemplateRT = itemTemplate.GetComponent<RectTransform>();
itemTemplateRT.sizeDelta = cbbRT.sizeDelta; itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10, 0);
itemTemplateRT.anchoredPosition = new Vector2(-5, 0);
var itemTemplateButton = itemTemplate.GetComponent<Button>(); var itemTemplateButton = itemTemplate.GetComponent<Button>();
itemTemplateButton.transition = Selectable.Transition.None; itemTemplateButton.transition = Selectable.Transition.None;
var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>(); var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>();
@ -1002,7 +1004,8 @@ namespace UnityEditor.UI
//Setup Template //Setup Template
itemTemplate.name = "ItemTemplate"; itemTemplate.name = "ItemTemplate";
var itemTemplateRT = itemTemplate.GetComponent<RectTransform>(); var itemTemplateRT = itemTemplate.GetComponent<RectTransform>();
itemTemplateRT.sizeDelta = cbbRT.sizeDelta; itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10, 0);
itemTemplateRT.anchoredPosition = new Vector2(-5, 0);
var itemTemplateButton = itemTemplate.GetComponent<Button>(); var itemTemplateButton = itemTemplate.GetComponent<Button>();
itemTemplateButton.transition = Selectable.Transition.None; itemTemplateButton.transition = Selectable.Transition.None;
var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>(); var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>();

@ -1 +1 @@
Subproject commit 44871685f1c817afe556c761a4bf12bff7a509ef Subproject commit d08257d62c3c95771540f51f77f50a491715d3b7

View File

@ -68,61 +68,50 @@ To get started with the project, here's a little guide:
## [Updates:](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/ReleaseNotes/RELEASENOTES) ## [Updates:](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/ReleaseNotes/RELEASENOTES)
## Update 2019.5 - 2.3 - Accelerated Deployment ## Maintenance release 2019.6 - 2.5 - Bug squash
Its been a while since the last update and although Unity keeps changing, thankfully the parts underneath do not. THanks to some awesome work by our contributors and the test teams, we made a run on some underlying bugs and issues. If you spot anything else, please log it on the BitBucket site for resolution.
Since the move to UPM, the team have been able to react quicker and push out fixes a lot easier, without affecting previous installation (whilst still adhering to Unity's backwards compatibility pattern). So it is with great news we announce this new release, faster that ever :D (and thanks to UPM, easier to upgrade than ever).
Be sure to also check out the "Examples" option in the Package Manager window to import the samples to your project. Be sure to also check out the "Examples" option in the Package Manager window to import the samples to your project.
> Be sure to logon to the new [Gitter Chat](https://gitter.im/Unity-UI-Extensions/Lobby) site for the UI Extensions project, if you have any questions, queries or suggestions > Be sure to logon to the new [Gitter Chat](https://gitter.im/Unity-UI-Extensions/Lobby) site for the UI Extensions project, if you have any questions, queries or suggestions
> >
> Much easier that posting a question / issue on YouTube, Twitter or Facebook :D > Much easier that posting a question / issue on YouTube, Twitter or Facebook :D
> >
> ## [UIExtensions Gitter Chanel](https://gitter.im/Unity-UI-Extensions/Lobby) > ## [UIExtensions Gitter Channel](https://gitter.im/Unity-UI-Extensions/Lobby)
### New / updated features ### New / updated features
* Add squircle primitive - Updated UI Line connector to use relative position instead of anchored position to verify if the Lines need updating.
* Adding new magnetic scroll control - Allow menu prefabs to not have to have canvas components. This allows you to use any type of prefab as a "menu". Adam Kapos mentions the concept on the Unite talk, https://youtu.be/wbmjturGbAQ?t=1654
* Added a static library to collate shaders on first use. - Updated segment line drawing for Line Lists. Seems Unity no longer needs UV's to be wrapped manually.
* Finalized new InputManagerHelper, which translates input based on the operating input system, new or old Updated CardStack2D to have defined keyboard input or specific gamepad input over the older axisname for new input system. - Updated the AutoCompleteComboBox to display text as entered (instead of all lowercase)
* Examples now included with UPM delivery and available as a button on the UPM package manager window - Updated the ComboBox to display text as entered (instead of all lowercase)
* Updated DropDown and Autocomplete controls based on feedback in #204 - Updated ComboBox Examples to include programmatic versions
* Updated Accordion to support both Vertical as well as Horizontal layout - Further ComboBox improvements including:
* Updated ComboBox controls to improve better programmatic controls * Upwards panel
* Updates to the Infinite scroll to support content of various sizes * Start fixes
* Updated UI Knob control - enabled dragging outside the target area, added example scene * Item Template resize
* Minor update to MagneticInfinite Scroll * Disabled sorting on combobox as it wasn't working
* Refactored and extended the ContentScrollSnap control * Disabled Slider handle when not in use
* Added protection against errors and empty scrollrect content * Updated Example
* Added new SetNewItems function to add children programmatically to the control and reset accordingly - Updated the new Input system switch and tested against 2021
* Patch supplied by a contributor to improve the texture sheet use with the UIParticlesystem
* Added "SetKnobValue" function which allows the setting of Value and loops
* Added the programmatic capability to change the parent scroll rect on the ScrollConflictManager at runtime.
### Examples / Examples / Examples ### Examples / Examples / Examples
Examples now have their own package, this simplifies their use and deployment. Especially in 2019 with the UPM deployment. Examples can be found either in the UPM package manager window or via the extra downloadable UnityAsset from the Bitbucket site - https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Downloads
* New UI Knob examples
* New Magnetic Scroll Example
* Updated ComboBox examples for programmatic testing
### Fixes ### Fixes
* Fix to add a "RequireComponent" to Primitives as Unity 2020 does not add them by default - Reordering issue resolved with ScrollRectOcclusion.
* Remove old Examples submodule - Fixed Sorting at min and max positions for ScrollRect
* Updated submodules to hide Examples folder Additionally, updated Package manifest to allow importing of examples direct from UPM package. - Updated ScrollToSelect script provided by zero3growlithe, tested and vastly reduces the previous jitter. Still present but barely noticeable now.
* Fixed hard swipe to ensure it only ever moves one page, no matter how far you swipe. - Fixed Issue # 363 Update Combobox control that takes multiple items programmatically, to only allow distinct items
* Fixed a conflict when using the ScrollConflictManager in child content of a HSS or VSS - Fixed the issues where dragging outside the range slider handle causes the range to update. - Resolves #369
* Fix for UI Particle system looping - Resolves an issue with Unity putting the previous controls vertex array in an uninitialised control.
* Fixed public GoToScreen call to only raise events internally (not multiple) - Applied J.R. Mitchell's fix for the Accordion Controls/Accordion/AccordionElement.cs - resolves: #364
* Final roll-up and fix. Resolved race condition for associated pagination controls. - Resolved issue where the Content Scroll snap issue with only 1 child. Resolves #362
* Fixed issue with page events not being raised when inertia was disabled (velocity was always zero) - Updated the PaginationManager to override if the ScrollSnap is in motion.
* When cloned, reorderable list was creating a second List Content component that was not initialized. Refactored to ensure only one list content was present and is initialized correctly
* Reorderable list items marked as transferable, remain transferable after being dropped
* Patch to resolve issues without the new Input System installed
* Refined magnetic scroll and dependencies while documenting Updated example
* Patch Tooltip
### Known issues ### Known issues
@ -132,9 +121,7 @@ No new issues in this release, but check the issues list for things we are curre
## Upgrade Notes ## Upgrade Notes
Due to the restructure of the package to meet Unity's new package guidelines, we recommend **Deleting the current Unity UI Extensions** folder prior to importing the new package. We recommend using the UPM delivery method. If you are using the Unity asset, there should be no issues updating but if you have a problem, just deleted the old Unity-UI-Extensions folder and import the asset new.
For Unity 2019 users using the new UPM deployment, be sure to delete the existing folder in your assets folder before adding the new package to avoid conflict.
----- -----
@ -159,7 +146,7 @@ There are almost 70+ extension controls / effect and other utilities in the proj
## [UI Extensions controls list](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls) ## [UI Extensions controls list](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls)
[Controls](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls#markdown-header-controls)||||| [Controls](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls#markdown-header-controls)|||||
------|------|------|------| ------|------|------|------|------|
Accordion|ColorPicker|Selection Box|UI Flippable|ComboBox Accordion|ColorPicker|Selection Box|UI Flippable|ComboBox
AutoComplete ComboBox|DropDown List|BoundToolTip|UIWindowBase|UI Knob AutoComplete ComboBox|DropDown List|BoundToolTip|UIWindowBase|UI Knob
TextPic|Input Focus|Box Slider|Cooldown Button|Segmented Control TextPic|Input Focus|Box Slider|Cooldown Button|Segmented Control
@ -167,27 +154,27 @@ Stepper|Range Slider|Radial Slider|MultiTouch Scroll Rect|
|||| ||||
[Primitives](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls#markdown-header-primitives)||||| [Primitives](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls#markdown-header-primitives)|||||
------|------|------|------| ------|------|------|------|------|
UILineRenderer|UILineTextureRenderer|UICircle|DiamondGraph|UICornerCut UILineRenderer|UILineTextureRenderer|UICircle|DiamondGraph|UICornerCut
UIPolygon|||| UIPolygon||||
|||| ||||
[Layouts](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls#markdown-header-layouts)||||| [Layouts](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls#markdown-header-layouts)|||||
------|------|------|------| ------|------|------|------|------|
Horizontal Scroll Snap|Vertical Scroll Snap|Flow Layout Group|Radial Layout|Tile Size Fitter Horizontal Scroll Snap|Vertical Scroll Snap|Flow Layout Group|Radial Layout|Tile Size Fitter
Scroll Snap (alt implementation)|Reorderable List|UI Vertical Scroller|Curved Layout|Table Layout Scroll Snap (alt implementation)|Reorderable List|UI Vertical Scroller|Curved Layout|Table Layout
FancyScrollView|Card UI|Scroll Position Controller|| FancyScrollView|Card UI|Scroll Position Controller||
|||| ||||
[Effects](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls#markdown-header-effect_components)||||| [Effects](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls#markdown-header-effect_components)|||||
------|------|------|------| ------|------|------|------|------|
Best Fit Outline|Curved Text|Gradient|Gradient2|Letter Spacing Best Fit Outline|Curved Text|Gradient|Gradient2|Letter Spacing
NicerOutline|RaycastMask|UIFlippable|UIImageCrop|SoftAlphaMask NicerOutline|RaycastMask|UIFlippable|UIImageCrop|SoftAlphaMask
CylinderText|UIParticleSystem|CurlyUI|Shine Effect|Shader Effects CylinderText|UIParticleSystem|CurlyUI|Shine Effect|Shader Effects
|||| ||||
[Additional Components](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls#markdown-header-additional_components)||||| [Additional Components](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls#markdown-header-additional_components)|||||
------|------|------|------| ------|------|------|------|------|
ReturnKeyTrigger|TabNavigation|uGUITools|ScrollRectTweener|ScrollRectLinker ReturnKeyTrigger|TabNavigation|uGUITools|ScrollRectTweener|ScrollRectLinker
ScrollRectEx|UI_InfiniteScroll|UI_ScrollRectOcclusion|UIScrollToSelection|UISelectableExtension ScrollRectEx|UI_InfiniteScroll|UI_ScrollRectOcclusion|UIScrollToSelection|UISelectableExtension
switchToRectTransform|ScrollConflictManager|CLFZ2 (Encryption)|DragCorrector|PPIViewer switchToRectTransform|ScrollConflictManager|CLFZ2 (Encryption)|DragCorrector|PPIViewer
@ -218,9 +205,9 @@ Got a script you want added? Then just fork the bitbucket repository and submit
Just ensure: Just ensure:
* The header of the script should match the standard used in all scripts * The header of the script should match the standard used in all scripts.
* The script uses the **Unity.UI.Extensions** namespace so they do not affect any other developments * The script uses the **Unity.UI.Extensions** namespace so they do not affect any other developments.
* (optional) Add Component and Editor options where possible (editor options are in the Editor\UIExtensionsMenuOptions.cs file) * (optional) Add Component and Editor options where possible. (editor options are in the Editor\UIExtensionsMenuOptions.cs file)
## [License](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/License) ## [License](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/License)

View File

@ -62,8 +62,8 @@ namespace UnityEngine.UI.Extensions
} }
LayoutElement le = this.gameObject.GetComponent<LayoutElement>(); LayoutElement le = this.gameObject.GetComponent<LayoutElement>();
if (le != null) if (le != null && m_Accordion != null)
{ {
if (this.isOn) if (this.isOn)
{ {
@ -98,8 +98,8 @@ namespace UnityEngine.UI.Extensions
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) if (transition == Accordion.Transition.Instant && m_Accordion != null)
{ {
if (state) if (state)
{ {

View File

@ -19,6 +19,11 @@ namespace UnityEngine.UI.Extensions
public Color disabledTextColor; public Color disabledTextColor;
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
/// <summary>
/// Contains the included items. To add and remove items to/from this list, use the <see cref="AddItem(string)"/>,
/// <see cref="RemoveItem(string)"/> and <see cref="SetAvailableOptions(List{string})"/> methods as these also execute
/// the required methods to update to the current collection.
/// </summary>
public List<string> AvailableOptions; public List<string> AvailableOptions;
//private bool isInitialized = false; //private bool isInitialized = false;
@ -36,7 +41,7 @@ namespace UnityEngine.UI.Extensions
private RectTransform _scrollPanelRT; private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT; private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT; private RectTransform _slidingAreaRT;
// private RectTransform scrollHandleRT; private RectTransform _scrollHandleRT;
private RectTransform _itemsPanelRT; private RectTransform _itemsPanelRT;
private Canvas _canvas; private Canvas _canvas;
private RectTransform _canvasRT; private RectTransform _canvasRT;
@ -104,6 +109,9 @@ namespace UnityEngine.UI.Extensions
public AutoCompleteSearchType autocompleteSearchType = AutoCompleteSearchType.Linq; public AutoCompleteSearchType autocompleteSearchType = AutoCompleteSearchType.Linq;
[SerializeField]
private bool _displayPanelAbove = false;
private bool _selectionIsValid = false; private bool _selectionIsValid = false;
[System.Serializable] [System.Serializable]
@ -129,13 +137,15 @@ namespace UnityEngine.UI.Extensions
{ {
Initialize(); Initialize();
} }
public void Start() public void Start()
{ {
if (SelectFirstItemOnStart && AvailableOptions.Count > 0) { if (SelectFirstItemOnStart && AvailableOptions.Count > 0) {
ToggleDropdownPanel (false); ToggleDropdownPanel (false);
OnItemClicked (AvailableOptions [0]); OnItemClicked (AvailableOptions [0]);
} }
} RedrawPanel();
}
private bool Initialize() private bool Initialize()
{ {
@ -155,7 +165,7 @@ namespace UnityEngine.UI.Extensions
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>(); _scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>(); _scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>(); _slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>(); _scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>(); _itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>(); //itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
@ -182,39 +192,75 @@ namespace UnityEngine.UI.Extensions
_panelItems = new List<string>(); _panelItems = new List<string>();
RebuildPanel(); RebuildPanel();
//RedrawPanel(); - causes an initialisation failure in U5
return success; return success;
} }
/// <summary>
/// Adds the item to <see cref="this.AvailableOptions"/> if it is not a duplicate and rebuilds the panel.
/// </summary>
/// <param name="item">Item to add.</param>
public void AddItem(string item) public void AddItem(string item)
{ {
AvailableOptions.Add(item); if (!this.AvailableOptions.Contains(item))
RebuildPanel(); {
this.AvailableOptions.Add(item);
this.RebuildPanel();
}
else
{
Debug.LogWarning($"{nameof(AutoCompleteComboBox)}.{nameof(AddItem)}: items may only exists once. '{item}' can not be added.");
}
} }
/// <summary>
/// Removes the item from <see cref="this.AvailableOptions"/> and rebuilds the panel.
/// </summary>
/// <param name="item">Item to remove.</param>
public void RemoveItem(string item) public void RemoveItem(string item)
{ {
AvailableOptions.Remove(item); if (this.AvailableOptions.Contains(item))
RebuildPanel(); {
this.AvailableOptions.Remove(item);
this.RebuildPanel();
}
} }
/// <summary>
/// Sets the given items as new content for the comboBox. Previous entries will be cleared.
/// </summary>
/// <param name="newOptions">New entries.</param>
public void SetAvailableOptions(List<string> newOptions) public void SetAvailableOptions(List<string> newOptions)
{ {
AvailableOptions.Clear(); var uniqueOptions = newOptions.Distinct().ToList();
AvailableOptions = newOptions; if (newOptions.Count != uniqueOptions.Count)
RebuildPanel();
}
public void SetAvailableOptions(string[] newOptions)
{
AvailableOptions.Clear();
for (int i = 0; i < newOptions.Length; i++)
{ {
AvailableOptions.Add(newOptions[i]); Debug.LogWarning($"{nameof(AutoCompleteComboBox)}.{nameof(SetAvailableOptions)}: items may only exists once. {newOptions.Count - uniqueOptions.Count} duplicates.");
} }
RebuildPanel(); this.AvailableOptions.Clear();
this.AvailableOptions = uniqueOptions;
this.RebuildPanel();
}
/// <summary>
/// Sets the given items as new content for the comboBox. Previous entries will be cleared.
/// </summary>
/// <param name="newOptions">New entries.</param>
public void SetAvailableOptions(string[] newOptions)
{
var uniqueOptions = newOptions.Distinct().ToList();
if (newOptions.Length != uniqueOptions.Count)
{
Debug.LogWarning($"{nameof(AutoCompleteComboBox)}.{nameof(SetAvailableOptions)}: items may only exists once. {newOptions.Length - uniqueOptions.Count} duplicates.");
}
this.AvailableOptions.Clear();
for (int i = 0; i < newOptions.Length; i++)
{
this.AvailableOptions.Add(newOptions[i]);
}
this.RebuildPanel();
} }
public void ResetItems() public void ResetItems()
@ -264,7 +310,7 @@ 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];
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = _panelItems[i]; //set the text value itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
Button itemBtn = itemObjs[i].GetComponent<Button>(); Button itemBtn = itemObjs[i].GetComponent<Button>();
itemBtn.onClick.RemoveAllListeners(); itemBtn.onClick.RemoveAllListeners();
@ -331,7 +377,9 @@ namespace UnityEngine.UI.Extensions
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y); _inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay _scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button _scrollPanelRT.anchoredPosition = _displayPanelAbove ?
new Vector2(0, DropdownOffset + _rectTransform.sizeDelta.y * _panelItems.Count - 1) :
new Vector2(0, -_rectTransform.sizeDelta.y);
//make the overlay fill the screen //make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object _overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
@ -354,6 +402,7 @@ namespace UnityEngine.UI.Extensions
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth); _scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight); _scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0); _slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x); _slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);

View File

@ -21,8 +21,12 @@ namespace UnityEngine.UI.Extensions
[SerializeField] [SerializeField]
private int _itemsToDisplay; private int _itemsToDisplay;
//Sorting disabled as it causes issues.
//[SerializeField]
//private bool _sortItems = true;
[SerializeField] [SerializeField]
private bool _sortItems = true; private bool _displayPanelAbove = false;
[System.Serializable] [System.Serializable]
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<string> public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<string>
@ -45,7 +49,7 @@ namespace UnityEngine.UI.Extensions
private RectTransform _scrollPanelRT; private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT; private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT; private RectTransform _slidingAreaRT;
// private RectTransform scrollHandleRT; private RectTransform _scrollHandleRT;
private RectTransform _itemsPanelRT; private RectTransform _itemsPanelRT;
private Canvas _canvas; private Canvas _canvas;
private RectTransform _canvasRT; private RectTransform _canvasRT;
@ -88,6 +92,11 @@ namespace UnityEngine.UI.Extensions
Initialize(); Initialize();
} }
public void Start()
{
RedrawPanel();
}
private bool Initialize() private bool Initialize()
{ {
bool success = true; bool success = true;
@ -104,7 +113,7 @@ namespace UnityEngine.UI.Extensions
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>(); _scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>(); _scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>(); _slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>(); _scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>(); _itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>(); //itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
@ -181,7 +190,7 @@ namespace UnityEngine.UI.Extensions
{ {
_panelItems.Add(option.ToLower()); _panelItems.Add(option.ToLower());
} }
if(_sortItems) _panelItems.Sort(); //if(_sortItems) _panelItems.Sort();
List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values); List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values);
panelObjects.Clear(); panelObjects.Clear();
@ -202,7 +211,7 @@ 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];
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = _panelItems[i]; //set the text value itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
Button itemBtn = itemObjs[i].GetComponent<Button>(); Button itemBtn = itemObjs[i].GetComponent<Button>();
itemBtn.onClick.RemoveAllListeners(); itemBtn.onClick.RemoveAllListeners();
@ -268,7 +277,9 @@ namespace UnityEngine.UI.Extensions
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y); _inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay _scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button _scrollPanelRT.anchoredPosition = _displayPanelAbove ?
new Vector2(0, _rectTransform.sizeDelta.y * ItemsToDisplay - 1) :
new Vector2(0, -_rectTransform.sizeDelta.y);
//make the overlay fill the screen //make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object _overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
@ -291,6 +302,7 @@ namespace UnityEngine.UI.Extensions
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth); _scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight); _scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0); _slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x); _slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);

View File

@ -31,7 +31,7 @@ namespace UnityEngine.UI.Extensions
private RectTransform _scrollPanelRT; private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT; private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT; private RectTransform _slidingAreaRT;
// private RectTransform scrollHandleRT; private RectTransform _scrollHandleRT;
private RectTransform _itemsPanelRT; private RectTransform _itemsPanelRT;
private Canvas _canvas; private Canvas _canvas;
private RectTransform _canvasRT; private RectTransform _canvasRT;
@ -57,7 +57,6 @@ namespace UnityEngine.UI.Extensions
// private int scrollOffset; //offset of the selected item // private int scrollOffset; //offset of the selected item
private int _selectedIndex = -1; private int _selectedIndex = -1;
[SerializeField] [SerializeField]
private int _itemsToDisplay; private int _itemsToDisplay;
public int ItemsToDisplay public int ItemsToDisplay
@ -72,6 +71,9 @@ namespace UnityEngine.UI.Extensions
public bool SelectFirstItemOnStart = false; public bool SelectFirstItemOnStart = false;
[SerializeField]
private bool _displayPanelAbove = false;
[System.Serializable] [System.Serializable]
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<int> { public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<int> {
} }
@ -86,6 +88,7 @@ namespace UnityEngine.UI.Extensions
ToggleDropdownPanel (false); ToggleDropdownPanel (false);
OnItemClicked (0); OnItemClicked (0);
} }
RedrawPanel();
} }
private bool Initialize() private bool Initialize()
@ -103,7 +106,7 @@ namespace UnityEngine.UI.Extensions
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>(); _scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>(); _scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>(); _slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>(); _scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>(); _itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>(); //itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
@ -332,7 +335,9 @@ namespace UnityEngine.UI.Extensions
_mainButton.txt.rectTransform.offsetMax = new Vector2(4, 0); _mainButton.txt.rectTransform.offsetMax = new Vector2(4, 0);
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay _scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button _scrollPanelRT.anchoredPosition = _displayPanelAbove ?
new Vector2(0, _rectTransform.sizeDelta.y * ItemsToDisplay - 1) :
new Vector2(0, -_rectTransform.sizeDelta.y);
//make the overlay fill the screen //make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object _overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
@ -355,6 +360,7 @@ namespace UnityEngine.UI.Extensions
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth); _scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight); _scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0); _slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x); _slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);

View File

@ -563,7 +563,10 @@ namespace UnityEngine.UI.Extensions
{ {
//outside the handles, move the entire slider along //outside the handles, move the entire slider along
UpdateDrag(eventData, eventData.pressEventCamera); UpdateDrag(eventData, eventData.pressEventCamera);
interactionState = InteractionState.Bar; if (eventData.pointerCurrentRaycast.gameObject == m_FillRect.gameObject)
{
interactionState = InteractionState.Bar;
}
if (transition == Transition.ColorTint) if (transition == Transition.ColorTint)
{ {
targetGraphic = m_FillImage; targetGraphic = m_FillImage;
@ -578,6 +581,7 @@ namespace UnityEngine.UI.Extensions
{ {
return; return;
} }
UpdateDrag(eventData, eventData.pressEventCamera); UpdateDrag(eventData, eventData.pressEventCamera);
} }

View File

@ -73,6 +73,11 @@ namespace UnityEngine.UI.Extensions
value = Math.Max(value, -1); value = Math.Max(value, -1);
value = Math.Min(value, segments.Length - 1); value = Math.Min(value, segments.Length - 1);
if (m_selectedSegmentIndex == value)
{
return;
}
m_selectedSegmentIndex = value; m_selectedSegmentIndex = value;
if (selectedSegment) if (selectedSegment)

View File

@ -103,7 +103,7 @@ namespace UnityEngine.UI.Extensions
private ScrollRect scrollRect = null; private ScrollRect scrollRect = null;
private RectTransform scrollRectTransform = null; private RectTransform scrollRectTransform = null;
private RectTransform contentTransform = null; private RectTransform contentTransform = null;
private List<Vector3> contentPositions = null; private List<Vector3> contentPositions = new List<Vector3>();
private Vector3 lerpTarget = Vector3.zero; private Vector3 lerpTarget = Vector3.zero;
private float totalScrollableWidth = 0; private float totalScrollableWidth = 0;
private DrivenRectTransformTracker tracker ; private DrivenRectTransformTracker tracker ;
@ -514,6 +514,11 @@ namespace UnityEngine.UI.Extensions
#region Behind the Scenes Movement stuff #region Behind the Scenes Movement stuff
public void OnBeginDrag(PointerEventData ped) public void OnBeginDrag(PointerEventData ped)
{ {
if (contentPositions.Count < 2)
{
return;
}
StopMovement(); StopMovement();
if (!Moving) if (!Moving)
{ {
@ -523,6 +528,11 @@ namespace UnityEngine.UI.Extensions
public void OnEndDrag(PointerEventData ped) public void OnEndDrag(PointerEventData ped)
{ {
if (contentPositions.Count <= 1)
{
return;
}
if (IsScrollRectAvailable) if (IsScrollRectAvailable)
{ {
StartCoroutine("SlideAndLerp"); StartCoroutine("SlideAndLerp");

View File

@ -359,11 +359,12 @@ namespace UnityEngine.UI.Extensions
/// *Note, this is based on a 0 starting index - 0 to x /// *Note, this is based on a 0 starting index - 0 to x
/// </summary> /// </summary>
/// <param name="screenIndex">0 starting index of page to jump to</param> /// <param name="screenIndex">0 starting index of page to jump to</param>
public void GoToScreen(int screenIndex) /// <param name="pagination">Override the screen movement if driven from a pagination control</param>
public void GoToScreen(int screenIndex, bool pagination = false)
{ {
if (screenIndex <= _screens - 1 && screenIndex >= 0) if (screenIndex <= _screens - 1 && screenIndex >= 0)
{ {
if (!_lerp) StartScreenChange(); if (!_lerp || pagination) StartScreenChange();
_lerp = true; _lerp = true;
CurrentPage = screenIndex; CurrentPage = screenIndex;

View File

@ -83,9 +83,17 @@ namespace UnityEngine.UI.Extensions
} }
} }
var topCanvas = menuInstance.GetComponent<Canvas>(); Canvas topCanvas = menuInstance.GetComponent<Canvas>();
var previousCanvas = menuStack.Peek().GetComponent<Canvas>(); if (topCanvas != null)
topCanvas.sortingOrder = previousCanvas.sortingOrder + 1; {
Canvas previousCanvas = menuStack.Peek().GetComponent<Canvas>();
if(previousCanvas != null)
{
topCanvas.sortingOrder = previousCanvas.sortingOrder + 1;
}
}
} }
menuStack.Push(menuInstance); menuStack.Push(menuInstance);

View File

@ -178,6 +178,7 @@ namespace UnityEngine.UI.Extensions
// Generate the quads that make up the wide line // Generate the quads that make up the wide line
var segments = new List<UIVertex[]> (); var segments = new List<UIVertex[]> ();
if (lineList) { if (lineList) {
//Loop through list in line pairs, skipping drawing between lines
for (var i = 1; i < pointsToDraw.Length; i += 2) { for (var i = 1; i < pointsToDraw.Length; i += 2) {
var start = pointsToDraw [i - 1]; var start = pointsToDraw [i - 1];
var end = pointsToDraw [i]; var end = pointsToDraw [i];
@ -188,13 +189,15 @@ namespace UnityEngine.UI.Extensions
segments.Add (CreateLineCap (start, end, SegmentType.Start)); segments.Add (CreateLineCap (start, end, SegmentType.Start));
} }
segments.Add(CreateLineSegment(start, end, SegmentType.Middle, segments.Count > 1 ? segments[segments.Count - 2] : null)); // Originally, UV's had to be wrapped per segment to ensure textures rendered correctly, however when tested in 2019.4, this no longer seems to be an issue.
segments.Add(CreateLineSegment(start, end, SegmentType.Middle));
if (lineCaps) { if (lineCaps) {
segments.Add (CreateLineCap (start, end, SegmentType.End)); segments.Add (CreateLineCap (start, end, SegmentType.End));
} }
} }
} else { } else {
//Draw full lines
for (var i = 1; i < pointsToDraw.Length; i++) { for (var i = 1; i < pointsToDraw.Length; i++) {
var start = pointsToDraw [i - 1]; var start = pointsToDraw [i - 1];
var end = pointsToDraw [i]; var end = pointsToDraw [i];
@ -459,5 +462,14 @@ namespace UnityEngine.UI.Extensions
float t = Mathf.Clamp01(dot); float t = Mathf.Clamp01(dot);
return p1 + from_p1_to_p2 * t; return p1 + from_p1_to_p2 * t;
} }
protected override void OnEnable()
{
base.OnEnable();
if (m_points.Length == 0)
{
m_points = new Vector2[1];
}
}
} }
} }

View File

@ -76,7 +76,7 @@ namespace UnityEngine.UI.Extensions
/// <param name="pageNo"></param> /// <param name="pageNo"></param>
public void GoToScreen(int pageNo) public void GoToScreen(int pageNo)
{ {
scrollSnap.GoToScreen(pageNo); scrollSnap.GoToScreen(pageNo, true);
} }

View File

@ -1,10 +1,14 @@
/// Credit SimonDarksideJ /// Credit SimonDarksideJ
/// Sourced from: https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/348/menu-manager-does-not-work-with-the-new /// Sourced from: https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/348/menu-manager-does-not-work-with-the-new
#if UNITY_2019_1_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
#define NEW_INPUT_SYSTEM
#endif
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls; using UnityEngine.InputSystem.Controls;
#endif #endif
@ -13,7 +17,7 @@ namespace UnityEngine.UI.Extensions
{ {
public static class UIExtensionsInputManager public static class UIExtensionsInputManager
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
private static bool[] mouseButtons = new bool[3] { false, false, false }; private static bool[] mouseButtons = new bool[3] { false, false, false };
private static Dictionary<KeyCode, bool> keys = new Dictionary<KeyCode, bool>(); private static Dictionary<KeyCode, bool> keys = new Dictionary<KeyCode, bool>();
private static Dictionary<String, bool> buttons = new Dictionary<String, bool>(); private static Dictionary<String, bool> buttons = new Dictionary<String, bool>();
@ -21,7 +25,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetMouseButton(int button) public static bool GetMouseButton(int button)
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
if (Mouse.current == null) if (Mouse.current == null)
{ {
return false; return false;
@ -35,7 +39,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetMouseButtonDown(int button) public static bool GetMouseButtonDown(int button)
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
if (Mouse.current == null) if (Mouse.current == null)
{ {
return false; return false;
@ -57,7 +61,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetMouseButtonUp(int button) public static bool GetMouseButtonUp(int button)
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
if (Mouse.current == null) if (Mouse.current == null)
{ {
return false; return false;
@ -76,7 +80,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetButton(string input) public static bool GetButton(string input)
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
ButtonControl buttonPressed = GetButtonControlFromString(input); ButtonControl buttonPressed = GetButtonControlFromString(input);
if (!buttons.ContainsKey(input)) if (!buttons.ContainsKey(input))
@ -90,7 +94,7 @@ namespace UnityEngine.UI.Extensions
#endif #endif
} }
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
private static ButtonControl GetButtonControlFromString(string input) private static ButtonControl GetButtonControlFromString(string input)
{ {
if (Gamepad.current == null) if (Gamepad.current == null)
@ -112,7 +116,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetButtonDown(string input) public static bool GetButtonDown(string input)
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
ButtonControl buttonPressed = GetButtonControlFromString(input); ButtonControl buttonPressed = GetButtonControlFromString(input);
if (buttonPressed.isPressed) if (buttonPressed.isPressed)
@ -140,7 +144,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetButtonUp(string input) public static bool GetButtonUp(string input)
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
ButtonControl buttonPressed = GetButtonControlFromString(input); ButtonControl buttonPressed = GetButtonControlFromString(input);
if (buttons[input] && !buttonPressed.isPressed) if (buttons[input] && !buttonPressed.isPressed)
@ -156,7 +160,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetKey(KeyCode key) public static bool GetKey(KeyCode key)
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
KeyControl keyPressed = GetKeyControlFromKeyCode(key); KeyControl keyPressed = GetKeyControlFromKeyCode(key);
if (!keys.ContainsKey(key)) if (!keys.ContainsKey(key))
{ {
@ -169,7 +173,7 @@ namespace UnityEngine.UI.Extensions
#endif #endif
} }
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
private static KeyControl GetKeyControlFromKeyCode(KeyCode key) private static KeyControl GetKeyControlFromKeyCode(KeyCode key)
{ {
if (Keyboard.current == null) if (Keyboard.current == null)
@ -203,7 +207,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetKeyDown(KeyCode key) public static bool GetKeyDown(KeyCode key)
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
KeyControl keyPressed = GetKeyControlFromKeyCode(key); KeyControl keyPressed = GetKeyControlFromKeyCode(key);
if (keyPressed.isPressed) if (keyPressed.isPressed)
{ {
@ -230,7 +234,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetKeyUp(KeyCode key) public static bool GetKeyUp(KeyCode key)
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
KeyControl keyPressed = GetKeyControlFromKeyCode(key); KeyControl keyPressed = GetKeyControlFromKeyCode(key);
if (keys[key] && !keyPressed.isPressed) if (keys[key] && !keyPressed.isPressed)
{ {
@ -245,7 +249,7 @@ namespace UnityEngine.UI.Extensions
public static float GetAxisRaw(string axis) public static float GetAxisRaw(string axis)
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
if (Gamepad.current == null) if (Gamepad.current == null)
{ {
return 0f; return 0f;
@ -269,7 +273,7 @@ namespace UnityEngine.UI.Extensions
{ {
get get
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
return Mouse.current.position.ReadValue(); return Mouse.current.position.ReadValue();
#else #else
return Input.mousePosition; return Input.mousePosition;
@ -281,7 +285,7 @@ namespace UnityEngine.UI.Extensions
{ {
get get
{ {
#if (UNITY_2019 || UNITY_2020) && !ENABLE_LEGACY_INPUT_MANAGER #if NEW_INPUT_SYSTEM
return Mouse.current.position.ReadValue(); return Mouse.current.position.ReadValue();
#else #else
return Input.mouseScrollDelta; return Input.mouseScrollDelta;

View File

@ -11,7 +11,7 @@ namespace UnityEngine.UI.Extensions
// The elements between which line segments should be drawn // The elements between which line segments should be drawn
public RectTransform[] transforms; public RectTransform[] transforms;
private Vector2[] previousPositions; private Vector3[] previousPositions;
private RectTransform canvas; private RectTransform canvas;
private RectTransform rt; private RectTransform rt;
private UILineRenderer lr; private UILineRenderer lr;
@ -36,7 +36,7 @@ namespace UnityEngine.UI.Extensions
bool updateLine = false; bool updateLine = false;
for (int i = 0; i < transforms.Length; i++) for (int i = 0; i < transforms.Length; i++)
{ {
if (!updateLine && previousPositions[i] != transforms[i].anchoredPosition) if (!updateLine && previousPositions[i] != transforms[i].position)
{ {
updateLine = true; updateLine = true;
} }
@ -76,10 +76,10 @@ namespace UnityEngine.UI.Extensions
lr.RelativeSize = false; lr.RelativeSize = false;
lr.drivenExternally = true; lr.drivenExternally = true;
previousPositions = new Vector2[transforms.Length]; previousPositions = new Vector3[transforms.Length];
for (int i = 0; i < transforms.Length; i++) for (int i = 0; i < transforms.Length; i++)
{ {
previousPositions[i] = transforms[i].anchoredPosition; previousPositions[i] = transforms[i].position;
} }
} }
} }

View File

@ -2,225 +2,302 @@
/// sourced from: http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-2011648 /// sourced from: http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-2011648
/*USAGE: /*USAGE:
Simply place the script on the ScrollRect that contains the selectable children we'll be scrolling to Simply place the script on the ScrollRect that contains the selectable children you will be scrolling
and drag'n'drop the RectTransform of the options "container" that we'll be scrolling.*/ */
using System.Collections.Generic; using System;
using System.Collections;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
[RequireComponent(typeof(ScrollRect))] [RequireComponent(typeof(ScrollRect))]
[AddComponentMenu("UI/Extensions/UIScrollToSelection")] [AddComponentMenu("UI/Extensions/UIScrollToSelection")]
public class UIScrollToSelection : MonoBehaviour public class UIScrollToSelection : MonoBehaviour
{ {
#region MEMBERS
//*** ATTRIBUTES ***// [Header("[ References ]")]
[Header("[ Settings ]")] [SerializeField, Tooltip("View (boundaries/mask) rect transform. Used to check if automatic scroll to selection is required.")]
[SerializeField] private RectTransform viewportRectTransform;
private ScrollType scrollDirection = ScrollType.BOTH; [SerializeField, Tooltip("Scroll rect used to reach selected element.")]
[SerializeField] private ScrollRect targetScrollRect;
private float scrollSpeed = 10f;
[Header("[ Input ]")] [Header("[ Scrolling ]")]
[SerializeField] [SerializeField, Tooltip("Allow automatic scrolling only on these axes.")]
private bool cancelScrollOnInput = false; private Axis scrollAxes = Axis.ANY;
[SerializeField] [SerializeField, Tooltip("MOVE_TOWARDS: stiff movement, LERP: smoothed out movement")]
private List<KeyCode> cancelScrollKeycodes = new List<KeyCode>(); private ScrollMethod usedScrollMethod = ScrollMethod.MOVE_TOWARDS;
[SerializeField]
private float scrollSpeed = 50;
//*** PROPERTIES ***// [Space(5)]
// REFERENCES [SerializeField, Tooltip("Scroll speed used when element to select is out of \"JumpOffsetThreshold\" range")]
protected RectTransform LayoutListGroup private float endOfListJumpScrollSpeed = 150;
{ [SerializeField, Range(0, 1), Tooltip("If next element to scroll to is located over this screen percentage, use \"EndOfListJumpScrollSpeed\" to reach this element faster.")]
get { return TargetScrollRect != null ? TargetScrollRect.content : null; } private float jumpOffsetThreshold = 1;
}
// SETTINGS [Header("[ Input ]")]
protected ScrollType ScrollDirection [SerializeField]
{ private MouseButton cancelScrollMouseButtons = MouseButton.ANY;
get { return scrollDirection; } [SerializeField]
} private KeyCode[] cancelScrollKeys = new KeyCode[0];
protected float ScrollSpeed
{
get { return scrollSpeed; }
}
// INPUT // INTERNAL - MEMBERS ONLY
protected bool CancelScrollOnInput private Vector3[] viewRectCorners = new Vector3[4];
{ private Vector3[] selectedElementCorners = new Vector3[4];
get { return cancelScrollOnInput; }
}
protected List<KeyCode> CancelScrollKeycodes
{
get { return cancelScrollKeycodes; }
}
// CACHED REFERENCES #endregion
protected RectTransform ScrollWindow { get; set; }
protected ScrollRect TargetScrollRect { get; set; }
// SCROLLING #region PROPERTIES
protected EventSystem CurrentEventSystem
{
get { return EventSystem.current; }
}
protected GameObject LastCheckedGameObject { get; set; }
protected GameObject CurrentSelectedGameObject
{
get { return EventSystem.current.currentSelectedGameObject; }
}
protected RectTransform CurrentTargetRectTransform { get; set; }
protected bool IsManualScrollingAvailable { get; set; }
//*** METHODS - PUBLIC ***// // REFERENCES
public RectTransform ViewRectTransform
{
get { return viewportRectTransform; }
set { viewportRectTransform = value; }
}
public ScrollRect TargetScrollRect
{
get { return targetScrollRect; }
set { targetScrollRect = value; }
}
// SCROLLING
public Axis ScrollAxes => scrollAxes;
public ScrollMethod UsedScrollMethod => usedScrollMethod;
public float ScrollSpeed => scrollSpeed;
public float EndOfListJumpScrollSpeed => endOfListJumpScrollSpeed;
public float JumpOffsetThreshold => jumpOffsetThreshold;
//*** METHODS - PROTECTED ***// // INPUT
protected virtual void Awake() public MouseButton CancelScrollMouseButtons => cancelScrollMouseButtons;
{ public KeyCode[] CancelScrollKeys => cancelScrollKeys;
TargetScrollRect = GetComponent<ScrollRect>();
ScrollWindow = TargetScrollRect.GetComponent<RectTransform>();
}
protected virtual void Start() // VARIABLES
{ private RectTransform scrollRectContentTransform;
private GameObject lastCheckedSelection;
} // COROUTINES
private Coroutine animationCoroutine;
protected virtual void Update() #endregion
{
UpdateReferences();
CheckIfScrollingShouldBeLocked();
ScrollRectToLevelSelection();
}
//*** METHODS - PRIVATE ***// #region FUNCTIONS
private void UpdateReferences()
{ protected void Awake()
// update current selected rect transform {
if (CurrentSelectedGameObject != LastCheckedGameObject) ValidateReferences();
}
protected void LateUpdate()
{
TryToScrollToSelection();
}
protected void Reset()
{
TargetScrollRect = gameObject.GetComponentInParent<ScrollRect>() ?? gameObject.GetComponentInChildren<ScrollRect>();
ViewRectTransform = gameObject.GetComponent<RectTransform>();
}
private void ValidateReferences()
{
if (!targetScrollRect)
{ {
CurrentTargetRectTransform = (CurrentSelectedGameObject != null) ? targetScrollRect = GetComponent<ScrollRect>();
CurrentSelectedGameObject.GetComponent<RectTransform>() :
null;
// unlock automatic scrolling
if (CurrentSelectedGameObject != null &&
CurrentSelectedGameObject.transform.parent == LayoutListGroup.transform)
{
IsManualScrollingAvailable = false;
}
} }
LastCheckedGameObject = CurrentSelectedGameObject; if (!targetScrollRect)
}
private void CheckIfScrollingShouldBeLocked()
{
if (CancelScrollOnInput == false || IsManualScrollingAvailable == true)
{ {
return; Debug.LogError("[UIScrollToSelection] No ScrollRect found. Either attach this script to a ScrollRect or assign on in the 'Target Scroll Rect' property");
} gameObject.SetActive(false);
return;
}
for (int i = 0; i < CancelScrollKeycodes.Count; i++) if (ViewRectTransform == null)
{ {
if (UIExtensionsInputManager.GetKeyDown(CancelScrollKeycodes[i]) == true) ViewRectTransform = TargetScrollRect.GetComponent<RectTransform>();
{ }
IsManualScrollingAvailable = true;
break; if (TargetScrollRect != null)
} {
} scrollRectContentTransform = TargetScrollRect.content;
} }
private void ScrollRectToLevelSelection() if (EventSystem.current == null)
{ {
// check main references Debug.LogError("[UIScrollToSelection] Unity UI EventSystem not found. It is required to check current selected object.");
bool referencesAreIncorrect = (TargetScrollRect == null || LayoutListGroup == null || ScrollWindow == null); gameObject.SetActive(false);
return;
}
}
if (referencesAreIncorrect == true || IsManualScrollingAvailable == true) private void TryToScrollToSelection()
{ {
return; // update references if selection changed
} GameObject selection = EventSystem.current.currentSelectedGameObject;
RectTransform selection = CurrentTargetRectTransform; if (selection == null || selection.activeInHierarchy == false || selection == lastCheckedSelection ||
selection.transform.IsChildOf(transform) == false)
{
return;
}
// check if scrolling is possible RectTransform selectionRect = selection.GetComponent<RectTransform>();
if (selection == null || selection.transform.parent != LayoutListGroup.transform)
{
return;
}
// depending on selected scroll direction move the scroll rect to selection ViewRectTransform.GetWorldCorners(viewRectCorners);
switch (ScrollDirection) selectionRect.GetWorldCorners(selectedElementCorners);
{
case ScrollType.VERTICAL:
UpdateVerticalScrollPosition(selection);
break;
case ScrollType.HORIZONTAL:
UpdateHorizontalScrollPosition(selection);
break;
case ScrollType.BOTH:
UpdateVerticalScrollPosition(selection);
UpdateHorizontalScrollPosition(selection);
break;
}
}
private void UpdateVerticalScrollPosition(RectTransform selection) ScrollToSelection(selection);
{
// move the current scroll rect to correct position
float selectionPosition = -selection.anchoredPosition.y - (selection.rect.height * (1 - selection.pivot.y));
float elementHeight = selection.rect.height; lastCheckedSelection = selection;
float maskHeight = ScrollWindow.rect.height; }
float listAnchorPosition = LayoutListGroup.anchoredPosition.y;
// get the element offset value depending on the cursor move direction private void ScrollToSelection(GameObject selection)
float offlimitsValue = GetScrollOffset(selectionPosition, listAnchorPosition, elementHeight, maskHeight); {
// initial check if we can scroll at all
if (selection == null)
{
return;
}
// move the target scroll rect // this is just to make names shorter a bit
TargetScrollRect.verticalNormalizedPosition += Vector3[] corners = viewRectCorners;
(offlimitsValue / LayoutListGroup.rect.height) * Time.unscaledDeltaTime * scrollSpeed; Vector3[] selectionCorners = selectedElementCorners;
}
private void UpdateHorizontalScrollPosition(RectTransform selection) // calculate scroll offset
{ Vector2 offsetToSelection = Vector2.zero;
// move the current scroll rect to correct position
float selectionPosition = -selection.anchoredPosition.x - (selection.rect.width * (1 - selection.pivot.x));
float elementWidth = selection.rect.width; offsetToSelection.x =
float maskWidth = ScrollWindow.rect.width; (selectionCorners[0].x < corners[0].x ? selectionCorners[0].x - corners[0].x : 0) +
float listAnchorPosition = -LayoutListGroup.anchoredPosition.x; (selectionCorners[2].x > corners[2].x ? selectionCorners[2].x - corners[2].x : 0);
offsetToSelection.y =
(selectionCorners[0].y < corners[0].y ? selectionCorners[0].y - corners[0].y : 0) +
(selectionCorners[1].y > corners[1].y ? selectionCorners[1].y - corners[1].y : 0);
// get the element offset value depending on the cursor move direction // calculate final scroll speed
float offlimitsValue = -GetScrollOffset(selectionPosition, listAnchorPosition, elementWidth, maskWidth); float finalScrollSpeed = ScrollSpeed;
// move the target scroll rect if (Math.Abs(offsetToSelection.x) / Screen.width >= JumpOffsetThreshold || Math.Abs(offsetToSelection.y) / Screen.height >= JumpOffsetThreshold)
TargetScrollRect.horizontalNormalizedPosition += {
(offlimitsValue / LayoutListGroup.rect.width) * Time.unscaledDeltaTime * scrollSpeed; finalScrollSpeed = EndOfListJumpScrollSpeed;
} }
private float GetScrollOffset(float position, float listAnchorPosition, float targetLength, float maskLength) // initiate animation coroutine
{ Vector2 targetPosition = (Vector2)scrollRectContentTransform.localPosition - offsetToSelection;
if (position < listAnchorPosition + (targetLength / 2))
{
return (listAnchorPosition + maskLength) - (position - targetLength);
}
else if (position + targetLength > listAnchorPosition + maskLength)
{
return (listAnchorPosition + maskLength) - (position + targetLength);
}
return 0; if (animationCoroutine != null)
} {
StopCoroutine(animationCoroutine);
}
//*** ENUMS ***// animationCoroutine = StartCoroutine(ScrollToPosition(targetPosition, finalScrollSpeed));
public enum ScrollType }
{
VERTICAL, private IEnumerator ScrollToPosition(Vector2 targetPosition, float speed)
HORIZONTAL, {
BOTH Vector3 startPosition = scrollRectContentTransform.localPosition;
}
} // cancel movement on axes not specified in ScrollAxes mask
targetPosition.x = ((ScrollAxes | Axis.HORIZONTAL) == ScrollAxes) ? targetPosition.x : startPosition.x;
targetPosition.y = ((ScrollAxes | Axis.VERTICAL) == ScrollAxes) ? targetPosition.y : startPosition.y;
// move to target position
Vector2 currentPosition2D = startPosition;
float horizontalSpeed = (Screen.width / Screen.dpi) * speed;
float verticalSpeed = (Screen.height / Screen.dpi) * speed;
while (currentPosition2D != targetPosition && CheckIfScrollInterrupted() == false)
{
currentPosition2D.x = MoveTowardsValue(currentPosition2D.x, targetPosition.x, horizontalSpeed, UsedScrollMethod);
currentPosition2D.y = MoveTowardsValue(currentPosition2D.y, targetPosition.y, verticalSpeed, UsedScrollMethod);
scrollRectContentTransform.localPosition = currentPosition2D;
yield return null;
}
scrollRectContentTransform.localPosition = currentPosition2D;
}
private bool CheckIfScrollInterrupted()
{
bool mouseButtonClicked = false;
// check mouse buttons
switch (CancelScrollMouseButtons)
{
case MouseButton.LEFT:
mouseButtonClicked |= Input.GetMouseButtonDown(0);
break;
case MouseButton.RIGHT:
mouseButtonClicked |= Input.GetMouseButtonDown(1);
break;
case MouseButton.MIDDLE:
mouseButtonClicked |= Input.GetMouseButtonDown(2);
break;
}
if (mouseButtonClicked == true)
{
return true;
}
// check keyboard buttons
for (int i = 0; i < CancelScrollKeys.Length; i++)
{
if (Input.GetKeyDown(CancelScrollKeys[i]) == true)
{
return true;
}
}
return false;
}
private float MoveTowardsValue(float from, float to, float delta, ScrollMethod method)
{
switch (method)
{
case ScrollMethod.MOVE_TOWARDS:
return Mathf.MoveTowards(from, to, delta * Time.unscaledDeltaTime);
case ScrollMethod.LERP:
return Mathf.Lerp(from, to, delta * Time.unscaledDeltaTime);
default:
return from;
}
}
#endregion
#region CLASS_ENUMS
[Flags]
public enum Axis
{
NONE = 0x00000000,
HORIZONTAL = 0x00000001,
VERTICAL = 0x00000010,
ANY = 0x00000011
}
[Flags]
public enum MouseButton
{
NONE = 0x00000000,
LEFT = 0x00000001,
RIGHT = 0x00000010,
MIDDLE = 0x00000100,
ANY = 0x00000111
}
public enum ScrollMethod
{
MOVE_TOWARDS,
LERP
}
#endregion
}
} }

View File

@ -27,6 +27,7 @@ namespace UnityEngine.UI.Extensions
{ {
//if true user will need to call Init() method manually (in case the contend of the scrollview is generated from code or requires special initialization) //if true user will need to call Init() method manually (in case the contend of the scrollview is generated from code or requires special initialization)
public bool InitByUser = false; public bool InitByUser = false;
private bool _initialised = false;
private ScrollRect _scrollRect; private ScrollRect _scrollRect;
private ContentSizeFitter _contentSizeFitter; private ContentSizeFitter _contentSizeFitter;
private VerticalLayoutGroup _verticalLayoutGroup; private VerticalLayoutGroup _verticalLayoutGroup;
@ -36,8 +37,9 @@ namespace UnityEngine.UI.Extensions
private bool _isHorizontal = false; private bool _isHorizontal = false;
private float _disableMarginX = 0; private float _disableMarginX = 0;
private float _disableMarginY = 0; private float _disableMarginY = 0;
private bool hasDisabledGridComponents = false; private bool _hasDisabledGridComponents = false;
private List<RectTransform> items = new List<RectTransform>(); private List<RectTransform> _items = new List<RectTransform>();
private bool _reset = false;
void Awake() void Awake()
{ {
@ -45,13 +47,19 @@ namespace UnityEngine.UI.Extensions
return; return;
Init(); Init();
} }
public void Init() public void Init()
{ {
if (_initialised)
{
Debug.LogError("Control already initialized\nYou have to enable the InitByUser setting on the control in order to use Init() when running");
return;
}
if (GetComponent<ScrollRect>() != null) if (GetComponent<ScrollRect>() != null)
{ {
_initialised = true;
_scrollRect = GetComponent<ScrollRect>(); _scrollRect = GetComponent<ScrollRect>();
_scrollRect.onValueChanged.AddListener(OnScroll); _scrollRect.onValueChanged.AddListener(OnScroll);
@ -60,7 +68,7 @@ namespace UnityEngine.UI.Extensions
for (int i = 0; i < _scrollRect.content.childCount; i++) for (int i = 0; i < _scrollRect.content.childCount; i++)
{ {
items.Add(_scrollRect.content.GetChild(i).GetComponent<RectTransform>()); _items.Add(_scrollRect.content.GetChild(i).GetComponent<RectTransform>());
} }
if (_scrollRect.content.GetComponent<VerticalLayoutGroup>() != null) if (_scrollRect.content.GetComponent<VerticalLayoutGroup>() != null)
{ {
@ -78,7 +86,6 @@ namespace UnityEngine.UI.Extensions
{ {
_contentSizeFitter = _scrollRect.content.GetComponent<ContentSizeFitter>(); _contentSizeFitter = _scrollRect.content.GetComponent<ContentSizeFitter>();
} }
} }
else else
{ {
@ -86,80 +93,108 @@ namespace UnityEngine.UI.Extensions
} }
} }
void DisableGridComponents() void ToggleGridComponents(bool toggle)
{ {
if (_isVertical) if (_isVertical)
_disableMarginY = _scrollRect.GetComponent<RectTransform>().rect.height / 2 + items[0].sizeDelta.y; _disableMarginY = _scrollRect.GetComponent<RectTransform>().rect.height / 2 + _items[0].sizeDelta.y;
if (_isHorizontal) if (_isHorizontal)
_disableMarginX = _scrollRect.GetComponent<RectTransform>().rect.width / 2 + items[0].sizeDelta.x; _disableMarginX = _scrollRect.GetComponent<RectTransform>().rect.width / 2 + _items[0].sizeDelta.x;
if (_verticalLayoutGroup) if (_verticalLayoutGroup)
{ {
_verticalLayoutGroup.enabled = false; _verticalLayoutGroup.enabled = toggle;
} }
if (_horizontalLayoutGroup) if (_horizontalLayoutGroup)
{ {
_horizontalLayoutGroup.enabled = false; _horizontalLayoutGroup.enabled = toggle;
} }
if (_contentSizeFitter) if (_contentSizeFitter)
{ {
_contentSizeFitter.enabled = false; _contentSizeFitter.enabled = toggle;
} }
if (_gridLayoutGroup) if (_gridLayoutGroup)
{ {
_gridLayoutGroup.enabled = false; _gridLayoutGroup.enabled = toggle;
} }
hasDisabledGridComponents = true; _hasDisabledGridComponents = !toggle;
} }
public void OnScroll(Vector2 pos) public void OnScroll(Vector2 pos)
{ {
if (_reset)
{
return;
}
if (!hasDisabledGridComponents) if (!_hasDisabledGridComponents)
DisableGridComponents(); {
ToggleGridComponents(false);
}
for (int i = 0; i < items.Count; i++) for (int i = 0; i < _items.Count; i++)
{ {
if (_isVertical && _isHorizontal) if (_isVertical && _isHorizontal)
{ {
if (_scrollRect.transform.InverseTransformPoint(items[i].position).y < -_disableMarginY || _scrollRect.transform.InverseTransformPoint(items[i].position).y > _disableMarginY if (_scrollRect.transform.InverseTransformPoint(_items[i].position).y < -_disableMarginY || _scrollRect.transform.InverseTransformPoint(_items[i].position).y > _disableMarginY
|| _scrollRect.transform.InverseTransformPoint(items[i].position).x < -_disableMarginX || _scrollRect.transform.InverseTransformPoint(items[i].position).x > _disableMarginX) || _scrollRect.transform.InverseTransformPoint(_items[i].position).x < -_disableMarginX || _scrollRect.transform.InverseTransformPoint(_items[i].position).x > _disableMarginX)
{ {
items[i].gameObject.SetActive(false); _items[i].gameObject.SetActive(false);
} }
else else
{ {
items[i].gameObject.SetActive(true); _items[i].gameObject.SetActive(true);
} }
} }
else else
{ {
if (_isVertical) if (_isVertical)
{ {
if (_scrollRect.transform.InverseTransformPoint(items[i].position).y < -_disableMarginY || _scrollRect.transform.InverseTransformPoint(items[i].position).y > _disableMarginY) if (_scrollRect.transform.InverseTransformPoint(_items[i].position).y < -_disableMarginY || _scrollRect.transform.InverseTransformPoint(_items[i].position).y > _disableMarginY)
{ {
items[i].gameObject.SetActive(false); _items[i].gameObject.SetActive(false);
} }
else else
{ {
items[i].gameObject.SetActive(true); _items[i].gameObject.SetActive(true);
} }
} }
if (_isHorizontal) if (_isHorizontal)
{ {
if (_scrollRect.transform.InverseTransformPoint(items[i].position).x < -_disableMarginX || _scrollRect.transform.InverseTransformPoint(items[i].position).x > _disableMarginX) if (_scrollRect.transform.InverseTransformPoint(_items[i].position).x < -_disableMarginX || _scrollRect.transform.InverseTransformPoint(_items[i].position).x > _disableMarginX)
{ {
items[i].gameObject.SetActive(false); _items[i].gameObject.SetActive(false);
} }
else else
{ {
items[i].gameObject.SetActive(true); _items[i].gameObject.SetActive(true);
} }
} }
} }
} }
} }
public void SetDirty()
{
_reset = true;
}
private void LateUpdate()
{
if (_reset)
{
_reset = false;
_items.Clear();
for (int i = 0; i < _scrollRect.content.childCount; i++)
{
_items.Add(_scrollRect.content.GetChild(i).GetComponent<RectTransform>());
_items[i].gameObject.SetActive(true);
}
ToggleGridComponents(true);
}
}
} }
} }

View File

@ -1,14 +1,14 @@
{ {
"name": "com.unity.uiextensions", "name": "com.unity.uiextensions",
"displayName": "Unity UI Extensions", "displayName": "Unity UI Extensions",
"version": "2.2.4", "version": "2.2.5",
"description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community", "description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community",
"author": "Simon darkside Jackson <@SimonDarksideJ>", "author": "Simon darkside Jackson <@SimonDarksideJ>",
"contributors": [{ "contributors": [{
"name": "SimonDarksideJ", "name": "SimonDarksideJ",
"twitter": "@SimonDarksideJ" "twitter": "@SimonDarksideJ"
}], }],
"unity": "2019.3", "unity": "2019.4",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://bitbucket.org/UnityUIExtensions/unity-ui-extensions.git" "url": "git+https://bitbucket.org/UnityUIExtensions/unity-ui-extensions.git"