diff --git a/.github/workflows/getpackageversionfrompackage.yml b/.github/workflows/getpackageversionfrompackage.yml index 32c56da3..30d93aef 100644 --- a/.github/workflows/getpackageversionfrompackage.yml +++ b/.github/workflows/getpackageversionfrompackage.yml @@ -25,11 +25,11 @@ jobs: - name: Script Version run: | echo "::group::Script Versioning" - $scriptVersion = "1.0.0" + $scriptVersion = "1.0.1" echo "Build Script Version: $scriptVersion" echo "::endgroup::" shell: pwsh - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive clean: true diff --git a/.github/workflows/rununitybuildmultiversion.yml b/.github/workflows/rununitybuildmultiversion.yml index ee228ee9..50e88d7f 100644 --- a/.github/workflows/rununitybuildmultiversion.yml +++ b/.github/workflows/rununitybuildmultiversion.yml @@ -64,26 +64,30 @@ jobs: unityVersion: 2022.3 build-target: WSAPlayer - os: windows - unityVersion: 2023.1 + unityVersion: 6000.0 build-target: Android - - os: macOS - unityVersion: 2023.1 - build-target: iOS - os: windows - unityVersion: 2023.1 + unityVersion: 6000.0 build-target: StandaloneWindows64 - os: windows - unityVersion: 2023.1 - build-target: WSAPlayer + unityVersion: 6000.0 + build-target: WSAPlayer + - os: macos + unityVersion: 6000.0 + build-target: iOS + - os: macos + unityVersion: 6000.0 + build-target: StandaloneOSX + steps: - name: Script Version run: | echo "::group::Script Versioning" - $scriptVersion = "1.0.0" + $scriptVersion = "1.0.1" echo "Build Script Version: $scriptVersion" echo "::endgroup::" shell: pwsh - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive clean: true @@ -91,8 +95,8 @@ jobs: - id: build name: 'Run Unity Builds' run: | - echo "::group::Set Hub and editor locations" $unityVersion = '${{ matrix.unityVersion }}' + $unityMajorVersion = $unityVersion.Substring(0, 4) echo "::group::Set Hub and editor locations" @@ -100,43 +104,46 @@ jobs: if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) { $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 function unity-hub + { + & $hubPath -- --headless $args.Split(" ") | Out-String + } + function unity-hub-raw { & $hubPath -- --headless $args.Split(" ") | Out-String -NoNewline - } + } } elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) { - $hubPath = "/Applications/Unity Hub.app/Contents/macOS/Unity Hub" - $editorRootPath = "/Applications/Unity/Hub/Editor/" - $editorFileEx = "/Unity.app/Contents/macOS/Unity" - $directorySeparatorChar = "/" + $hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" - # /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 + } + function unity-hub-raw { & $hubPath -- --headless $args.Split(" ") | Out-String -NoNewline - } + } } elseif ( $global:PSVersionTable.OS.Contains("Linux") ) { $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 function unity-hub { xvfb-run --auto-servernum "$hubPath" --headless $args.Split(" ") - } + } + function unity-hub-raw + { + xvfb-run --auto-servernum "$hubPath" --headless $args.Split(" ") + } } echo "::endgroup::" @@ -168,7 +175,7 @@ jobs: echo "Requested unity version is {$unityVersion}" $InstalledUnityVersions = unity-hub editors - $editorRootPath = unity-hub ip -g + $editorRootPath = unity-hub-raw ip -g echo "Installed unity versions are {$InstalledUnityVersions}" echo "Unity install path is {$editorRootPath}" @@ -230,7 +237,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 { @@ -267,7 +274,7 @@ jobs: echo "::endgroup::" - echo "::group::Setup logging and run Unit tests" + echo "::group::Setup logging and run Unit tests" # Log detail $logDirectory = "Logs" @@ -283,14 +290,13 @@ jobs: # If run manually, the Refname is actually blank, so just use date if([string]::IsNullOrEmpty(${GITHUB_REF_NAME})) { - $logName = "$logDirectory$directorySeparatorChar$date" - } - else{ - $logName = "$logDirectory$directorySeparatorChar${GITHUB_REF_NAME}-$date" + $logName = Join-Path $logDirectory $date + }else { + $logName = Join-Path $logDirectory ${GITHUB_REF_NAME}-$date } - $logPath = "$logName.log" - $testsLogPath = "$logName-tests.xml" + $logPath = "$unityMajorVersion_${{ matrix.build-target }}_$logName.log" + $testsLogPath = "$unityMajorVersion_${{ matrix.build-target }}_$logName-tests.xml" echo "Logpath [$logPath]" echo "TestsPath [$testsLogPath]" @@ -313,9 +319,20 @@ jobs: $TempUnityProjectName = 'P' - unity-editor '-createProject' $TempUnityProjectName -quit + unity-editor '-createProject' $TempUnityProjectName '-logFile' $logPath '-quit' + + if ( -not (Test-Path "$TempUnityProjectName") ) + { + $ProjectPath = Get-Location + Write-Error "Editor failed to create project not Found $ProjectPath/$TempUnityProjectName" + exit 1 + } + else { + $ProjectPath = Get-Location + echo "Editor project created at $ProjectPath/$TempUnityProjectName" + } - $destinationPath = $TempUnityProjectName + $directorySeparatorChar + 'packages' + $destinationPath = Join-Path $TempUnityProjectName 'packages' Move-Item -Path $UPMFolderName -Destination $destinationPath echo "::endgroup::" @@ -348,10 +365,9 @@ jobs: # Read dependancy input value $dependencies = '${{ inputs.dependencies }}' - if([string]::IsNullOrEmpty('${{ secrets.GIT_USER_NAME }}') -or [string]::IsNullOrEmpty('${{ secrets.GIT_PAT }}')){ + if([string]::IsNullOrEmpty('${{ github.actor }}') -or [string]::IsNullOrEmpty('${{ secrets.GITHUB_TOKEN }}')){ echo "" - echo "Secrets for GIT_USER_NAME or GIT_PAT missing, please register them with access to this runner" - echo "*Note, Organisation secrets are not accessible to Forked repos and need registering in the local fork" + echo "Insufficient credentials supplied to activate the workflow" exit 1 } @@ -362,7 +378,7 @@ jobs: echo $JSONdependencies # Read current Manifest json - $manifestPath = $destinationPath + $directorySeparatorChar + 'manifest.json' + $manifestPath = Join-Path $destinationPath 'manifest.json' $projectManifest = Get-Content -Path $manifestPath | ConvertFrom-Json $strArray = $projectManifest.dependencies.PsObject.Properties | ForEach-Object {"$($_.Name)@$($_.Value),"} @@ -375,7 +391,7 @@ jobs: $dependencyURL = $_.Value echo "---------------------------------------------" echo "Cloning dependency - Name [$dependencyName] - Path [$dependencyPath] - URL [$dependencyURL]" - $cloneURL = "https://${{ secrets.GIT_USER_NAME }}:${{ secrets.GIT_PAT }}@$dependencyURL" + $cloneURL = "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@$dependencyURL" echo "cloning $dependencyName from $dependencyURL and moving to $destinationPath" echo "git path - $cloneURL" @@ -431,7 +447,7 @@ jobs: echo "::endgroup::" - echo "::group::Run build" + echo "::group::Run build" echo "---------------------------------------------" echo "Start Testing" @@ -461,11 +477,10 @@ jobs: exit $LASTEXITCODE } - echo "::endgroup::" shell: pwsh - uses: actions/upload-artifact@v3 if: always() with: - name: unity-build-log + name: unity-build-log-${{ matrix.unityVersion }}-${{ matrix.build-target }} path: Logs/** \ No newline at end of file diff --git a/.github/workflows/rununitysinglebuild.yml b/.github/workflows/rununitysinglebuild.yml index d6ba2836..7d792f4d 100644 --- a/.github/workflows/rununitysinglebuild.yml +++ b/.github/workflows/rununitysinglebuild.yml @@ -32,18 +32,17 @@ jobs: - name: Script Version run: | echo "::group::Script Versioning" - $scriptVersion = "1.0.0" + $scriptVersion = "1.0.1" echo "Build Script Version: $scriptVersion" echo "::endgroup::" shell: pwsh - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive clean: true - id: build name: 'Run Unity Builds' run: | - echo "::group::Set Hub and editor locations" $unityVersion = '${{ inputs.unityVersion }}' echo "::group::Set Hub and editor locations" @@ -53,8 +52,6 @@ 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 @@ -67,8 +64,6 @@ 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,8 +75,6 @@ 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 @@ -235,10 +228,9 @@ jobs: # If run manually, the Refname is actually blank, so just use date if([string]::IsNullOrEmpty(${GITHUB_REF_NAME})) { - $logName = "$logDirectory$directorySeparatorChar$date" - } - else{ - $logName = "$logDirectory$directorySeparatorChar${GITHUB_REF_NAME}-$date" + $logName = Join-Path $logDirectory $date + }else { + $logName = Join-Path $logDirectory ${GITHUB_REF_NAME}-$date } $logPath = "$logName.log" @@ -265,9 +257,20 @@ jobs: $TempUnityProjectName = 'P' - unity-editor '-createProject' $TempUnityProjectName -quit + unity-editor '-createProject' $TempUnityProjectName '-logFile' $logPath '-quit' - $destinationPath = $TempUnityProjectName + $directorySeparatorChar + 'packages' + if ( -not (Test-Path "$TempUnityProjectName") ) + { + $ProjectPath = Get-Location + Write-Error "Editor failed to create project not Found $ProjectPath/$TempUnityProjectName" + exit 1 + } + else { + $ProjectPath = Get-Location + echo "Editor project created at $ProjectPath/$TempUnityProjectName" + } + + $destinationPath = Join-Path $TempUnityProjectName 'packages' Move-Item -Path $UPMFolderName -Destination $destinationPath echo "::endgroup::" @@ -300,10 +303,9 @@ jobs: # Read dependancy input value $dependencies = '${{ inputs.dependencies }}' - if([string]::IsNullOrEmpty('${{ secrets.GIT_USER_NAME }}') -or [string]::IsNullOrEmpty('${{ secrets.GIT_PAT }}')){ + if([string]::IsNullOrEmpty('${{ github.actor }}') -or [string]::IsNullOrEmpty('${{ secrets.GITHUB_TOKEN }}')){ echo "" - echo "Secrets for GIT_USER_NAME or GIT_PAT missing, please register them with access to this runner" - echo "*Note, Organisation secrets are not accessible to Forked repos and need registering in the local fork" + echo "Insufficient credentials supplied to activate the workflow" exit 1 } @@ -314,7 +316,7 @@ jobs: echo $JSONdependencies # Read current Manifest json - $manifestPath = $destinationPath + $directorySeparatorChar + 'manifest.json' + $manifestPath = Join-Path $destinationPath 'manifest.json' $projectManifest = Get-Content -Path $manifestPath | ConvertFrom-Json $strArray = $projectManifest.dependencies.PsObject.Properties | ForEach-Object {"$($_.Name)@$($_.Value),"} @@ -327,7 +329,7 @@ jobs: $dependencyURL = $_.Value echo "---------------------------------------------" echo "Cloning dependency - Name [$dependencyName] - Path [$dependencyPath] - URL [$dependencyURL]" - $cloneURL = "https://${{ secrets.GIT_USER_NAME }}:${{ secrets.GIT_PAT }}@$dependencyURL" + $cloneURL = "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@$dependencyURL" echo "cloning $dependencyName from $dependencyURL and moving to $destinationPath" echo "git path - $cloneURL" @@ -413,11 +415,10 @@ jobs: exit $LASTEXITCODE } - echo "::endgroup::" shell: pwsh - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: always() with: - name: unity-build-log - path: Logs/** \ No newline at end of file + name: unity-build-log-${{ matrix.build-target }} + path: Logs/** \ No newline at end of file diff --git a/.github/workflows/tagrelease.yml b/.github/workflows/tagrelease.yml index d572d768..fddc3822 100644 --- a/.github/workflows/tagrelease.yml +++ b/.github/workflows/tagrelease.yml @@ -27,17 +27,17 @@ jobs: - name: Script Version run: | echo "::group::Script Versioning" - $scriptVersion = "1.0.2" + $scriptVersion = "1.0.3" echo "Build Script Version: $scriptVersion" echo "::endgroup::" shell: pwsh - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 submodules: recursive clean: true token: ${{ secrets.GIT_PAT }} - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 - name: Set Github vars run: | if([string]::IsNullOrEmpty('${{ secrets.GIT_USER_NAME }}')){ @@ -74,6 +74,6 @@ jobs: - name: Create tag and push run: | $tagVersion = "${{ inputs.version }}" - git tag -fa "v$tagVersion" "${GITHUB_SHA}" -m "v$tagVersion Release [skip ci]" + git tag -fa "v$tagVersion" -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 index 4e630ba9..8c8882ba 100644 --- a/.github/workflows/upversionandtagrelease.yml +++ b/.github/workflows/upversionandtagrelease.yml @@ -31,8 +31,8 @@ on: description: "Returns the version of Unity the UPM package requires" value: ${{ jobs.packageRelease.outputs.packageversion }} secrets: - GIT_PAT: - required: true + GIT_USER_NAME: + required: false jobs: packageRelease: @@ -44,18 +44,18 @@ jobs: - name: Script Version run: | echo "::group::Script Versioning" - $scriptVersion = "1.0.2" + $scriptVersion = "1.0.3" echo "Build Script Version: $scriptVersion" echo "::endgroup::" shell: pwsh - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ inputs.target-branch }} fetch-depth: 0 submodules: recursive clean: true token: ${{ secrets.GIT_PAT }} - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 - name: Set Github vars run: | if([string]::IsNullOrEmpty('${{ secrets.GIT_USER_NAME }}')){ @@ -176,6 +176,6 @@ jobs: if: ${{inputs.createTag == true}} run: | $outputVersion = '${{steps.getpackageversion.outputs.packageversion }}' - git tag -fa "v$outputVersion" "${GITHUB_SHA}" -m "v$outputVersion Release" + git tag -fa "v$outputVersion" -m "v$outputVersion Release" git push origin "v$outputVersion" --force --tags shell: pwsh \ No newline at end of file diff --git a/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs b/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs index 5ef840c2..8063906c 100644 --- a/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs +++ b/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs @@ -32,6 +32,9 @@ public class ReorderableList : MonoBehaviour [Tooltip("Should items being dragged over this list have their sizes equalized?")] public bool EqualizeSizesOnDrag = false; + [Tooltip("Should items keep the original rotation?")] + public bool KeepItemRotation = false; + [Tooltip("Maximum number of items this container can hold")] public int maxItems = int.MaxValue; diff --git a/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs b/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs index eb1484cd..8a09c32b 100644 --- a/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs +++ b/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs @@ -266,7 +266,10 @@ private void displaceElement(int targetIndex, Transform displaced) _displacedObjectLE.preferredWidth = _draggingObjectOriginalSize.x; _displacedObjectLE.preferredHeight = _draggingObjectOriginalSize.y; _displacedObject.SetParent(_reorderableList.Content, false); - _displacedObject.rotation = _reorderableList.transform.rotation; + if (!_reorderableList.KeepItemRotation) + { + _displacedObject.rotation = _reorderableList.transform.rotation; + } _displacedObject.SetSiblingIndex(_fromIndex); // Force refreshing both lists because otherwise we get inappropriate FromList in ReorderableListEventStruct _reorderableList.Refresh(); @@ -310,7 +313,10 @@ private void revertDisplacedElement() _displacedObjectLE.preferredWidth = _displacedObjectOriginalSize.x; _displacedObjectLE.preferredHeight = _displacedObjectOriginalSize.y; _displacedObject.SetParent(_displacedObjectOriginList.Content, false); - _displacedObject.rotation = _displacedObjectOriginList.transform.rotation; + if (!_reorderableList.KeepItemRotation) + { + _displacedObject.rotation = _displacedObjectOriginList.transform.rotation; + } _displacedObject.SetSiblingIndex(_displacedFromIndex); _displacedObject.gameObject.SetActive(true); @@ -382,7 +388,10 @@ public void OnEndDrag(PointerEventData eventData) RefreshSizes(); _draggingObject.SetParent(_currentReorderableListRaycasted.Content, false); - _draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation; + if (!_reorderableList.KeepItemRotation) + { + _draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation; + } _draggingObject.SetSiblingIndex(_fakeElement.GetSiblingIndex()); //If the item is transferable, it can be dragged out again @@ -474,7 +483,10 @@ private void CancelDrag() { RefreshSizes(); _draggingObject.SetParent(_reorderableList.Content, false); - _draggingObject.rotation = _reorderableList.Content.transform.rotation; + if (!_reorderableList.KeepItemRotation) + { + _draggingObject.rotation = _reorderableList.Content.transform.rotation; + } _draggingObject.SetSiblingIndex(_fromIndex); diff --git a/Runtime/Scripts/Effects/Gradient2.cs b/Runtime/Scripts/Effects/Gradient2.cs index 624326a2..cbb0485d 100644 --- a/Runtime/Scripts/Effects/Gradient2.cs +++ b/Runtime/Scripts/Effects/Gradient2.cs @@ -9,6 +9,12 @@ /// using System; using System.Collections.Generic; +#if UNITY_2021_2_OR_NEWER +using System.Buffers; +#endif +#if UNITY_2021_1_OR_NEWER +using UnityEngine.Pool; +#endif namespace UnityEngine.UI.Extensions { @@ -36,6 +42,9 @@ public class Gradient2 : BaseMeshEffect [SerializeField] UnityEngine.Gradient _effectGradient = new UnityEngine.Gradient() { colorKeys = new GradientColorKey[] { new GradientColorKey(Color.black, 0), new GradientColorKey(Color.white, 1) } }; + private GradientColorKey[] _colorKeys; + private GradientAlphaKey[] _alphaKeys; + #region Properties public Blend BlendMode { @@ -103,7 +112,11 @@ public override void ModifyMesh(VertexHelper helper) if (!IsActive() || helper.currentVertCount == 0) return; +#if UNITY_2021_1_OR_NEWER + List _vertexList = ListPool.Get(); +#else List _vertexList = new List(); +#endif helper.GetUIVertexStream(_vertexList); @@ -218,7 +231,7 @@ public override void ModifyMesh(VertexHelper helper) helper.AddVert(centralVertex); - for (int i = 1; i < steps; i++) helper.AddTriangle(i - 1, i, steps); + for (int i = 1; i < steps; i++) helper.AddTriangle(i, i-1, steps); helper.AddTriangle(0, steps - 1, steps); } @@ -238,6 +251,10 @@ public override void ModifyMesh(VertexHelper helper) } break; } + +#if UNITY_2021_1_OR_NEWER + ListPool.Release(_vertexList); +#endif } Rect GetBounds(List vertices) @@ -264,7 +281,11 @@ Rect GetBounds(List vertices) void SplitTrianglesAtGradientStops(List _vertexList, Rect bounds, float zoomOffset, VertexHelper helper) { - List stops = FindStops(zoomOffset, bounds); +#if UNITY_2021_1_OR_NEWER + List stops = FindStops(zoomOffset, bounds, ListPool.Get()); +#else + List stops = FindStops(zoomOffset, bounds, new List()); +#endif if (stops.Count > 0) { helper.Clear(); @@ -272,10 +293,23 @@ void SplitTrianglesAtGradientStops(List _vertexList, Rect bounds, floa int nCount = _vertexList.Count; for (int i = 0; i < nCount; i += 3) { - float[] positions = GetPositions(_vertexList, i); +#if UNITY_2021_2_OR_NEWER + var positions = ArrayPool.Shared.Rent(3); +#else + var positions = new float[3]; +#endif + + GetPositions(_vertexList, i, ref positions); + +#if UNITY_2021_1_OR_NEWER + List originIndices = ListPool.Get(); + List starts = ListPool.Get(); + List ends = ListPool.Get(); +#else List originIndices = new List(3); List starts = new List(3); List ends = new List(2); +#endif for (int s = 0; s < stops.Count; s++) { @@ -403,13 +437,24 @@ void SplitTrianglesAtGradientStops(List _vertexList, Rect bounds, floa int vertexCount = helper.currentVertCount; helper.AddTriangle(vertexCount - 3, vertexCount - 2, vertexCount - 1); } + +#if UNITY_2021_2_OR_NEWER + ArrayPool.Shared.Return(positions); +#endif +#if UNITY_2021_1_OR_NEWER + ListPool.Release(originIndices); + ListPool.Release(starts); + ListPool.Release(ends); +#endif } } +#if UNITY_2021_1_OR_NEWER + ListPool.Release(stops); +#endif } - float[] GetPositions(List _vertexList, int index) + void GetPositions(List _vertexList, int index, ref float[] positions) { - float[] positions = new float[3]; if (GradientType == Type.Horizontal) { positions[0] = _vertexList[index].position.x; @@ -422,24 +467,27 @@ float[] GetPositions(List _vertexList, int index) positions[1] = _vertexList[index + 1].position.y; positions[2] = _vertexList[index + 2].position.y; } - return positions; } - - List FindStops(float zoomOffset, Rect bounds) + + List FindStops(float zoomOffset, Rect bounds, List stops) { - List stops = new List(); var offset = Offset * (1 - zoomOffset); var startBoundary = zoomOffset - offset; var endBoundary = (1 - zoomOffset) - offset; - foreach (var color in EffectGradient.colorKeys) + if (_colorKeys == null) _colorKeys = EffectGradient.colorKeys; + + foreach (var color in _colorKeys) { if (color.time >= endBoundary) break; if (color.time > startBoundary) stops.Add((color.time - startBoundary) * Zoom); } - foreach (var alpha in EffectGradient.alphaKeys) + + if (_alphaKeys == null) _alphaKeys = _effectGradient.alphaKeys; + + foreach (var alpha in _alphaKeys) { if (alpha.time >= endBoundary) break; @@ -455,7 +503,13 @@ List FindStops(float zoomOffset, Rect bounds) size = bounds.height; } - stops.Sort(); + stops.Sort((x, y) => + { + if (x > y) return 1; + if (x == y) return 0; + return -1; + }); + for (int i = 0; i < stops.Count; i++) { stops[i] = (stops[i] * size) + min; diff --git a/Runtime/Scripts/Layout/CardUI/2D Cards/CardPopup2D.cs b/Runtime/Scripts/Layout/CardUI/2D Cards/CardPopup2D.cs index 14ce7899..a3c4c68d 100644 --- a/Runtime/Scripts/Layout/CardUI/2D Cards/CardPopup2D.cs +++ b/Runtime/Scripts/Layout/CardUI/2D Cards/CardPopup2D.cs @@ -57,8 +57,12 @@ void Update() { isFalling = false; rbody.useGravity = false; - rbody.velocity = Vector3.zero; - transform.position = new Vector3(0, 8, startZPos); +#if UNITY_6000_0_OR_NEWER + rbody.linearVelocity = Vector3.zero; +#else + rbody.velocity = Vector3.zero; +#endif + transform.position = new Vector3(0, 8, startZPos); if (singleScene) { CardEnter(); diff --git a/Runtime/Scripts/Layout/ScrollSnapBase.cs b/Runtime/Scripts/Layout/ScrollSnapBase.cs index d200bef0..bca4aa1b 100644 --- a/Runtime/Scripts/Layout/ScrollSnapBase.cs +++ b/Runtime/Scripts/Layout/ScrollSnapBase.cs @@ -189,6 +189,11 @@ void Awake() _screensContainer = _scroll_rect.content; + //ScrollRect.content RT anchors has to be stretched first in order for HSS/VSS.DistributePages() to have the correct result + _screensContainer.anchorMin = Vector2.zero; + _screensContainer.anchorMax = Vector2.one; + _screensContainer.sizeDelta = Vector2.zero; + InitialiseChildObjects(); if (NextButton) diff --git a/Runtime/Scripts/Primitives/UILineRenderer.cs b/Runtime/Scripts/Primitives/UILineRenderer.cs index 4f836c2c..35f4381d 100644 --- a/Runtime/Scripts/Primitives/UILineRenderer.cs +++ b/Runtime/Scripts/Primitives/UILineRenderer.cs @@ -499,10 +499,6 @@ protected override void OnEnable() { m_points = new Vector2[1]; } - if (transform.GetComponent().position != Vector3.zero) - { - Debug.LogWarning("A Line Renderer component should be on a RectTransform positioned at (0,0,0), do not use in child Objects.\nFor best results, create separate RectTransforms as children of the canvas positioned at (0,0) for a UILineRenderer and do not move."); - } } } } diff --git a/Runtime/Scripts/Utilities/UILineConnector.cs b/Runtime/Scripts/Utilities/UILineConnector.cs index 77a3fc93..7423d53e 100644 --- a/Runtime/Scripts/Utilities/UILineConnector.cs +++ b/Runtime/Scripts/Utilities/UILineConnector.cs @@ -12,32 +12,50 @@ public class UILineConnector : MonoBehaviour // The elements between which line segments should be drawn public RectTransform[] transforms; private Vector3[] previousPositions; - private RectTransform canvas; + private Vector3 previousLrPos; + private Vector3 previousGlobalScale; private RectTransform rt; private UILineRenderer lr; private void Awake() { - var canvasParent = GetComponentInParent().GetParentCanvas(); - if (canvasParent != null) - { - canvas = canvasParent.GetComponent(); - } rt = GetComponent(); lr = GetComponent(); } - // Update is called once per frame - void Update() + private void OnEnable() { if (transforms == null || transforms.Length < 1) { return; } - //Performance check to only redraw when the child transforms move - if (previousPositions != null && previousPositions.Length == transforms.Length) + + CalculateLinePoints(); + } + + private void Update() + { + if (lr.RelativeSize) + { + Debug.LogWarning("While using UILineConnector, UILineRenderer should not use relative size, so that even if this RectTransform has a zero-size Rect, the positions of the points can still be calculated"); + lr.RelativeSize = false; + } + + if (transforms == null || transforms.Length < 1) + { + return; + } + + // Get world position of UILineRenderer + Vector3 lrWorldPos = rt.position; + + /*Performance check to only redraw when the child transforms move, + or the world position of UILineRenderer moves */ + bool updateLine = lrWorldPos != previousLrPos; + updateLine = rt.lossyScale != previousGlobalScale; + + if (!updateLine && previousPositions != null && previousPositions.Length == transforms.Length) { - bool updateLine = false; for (int i = 0; i < transforms.Length; i++) { if (transforms[i] == null) @@ -47,56 +65,48 @@ void Update() if (!updateLine && previousPositions[i] != transforms[i].position) { updateLine = true; + break; } } - if (!updateLine) return; - } + } + if (!updateLine) return; - // Get the pivot points - Vector2 thisPivot = rt.pivot; - Vector2 canvasPivot = canvas.pivot; - // Set up some arrays of coordinates in various reference systems - Vector3[] worldSpaces = new Vector3[transforms.Length]; - Vector3[] canvasSpaces = new Vector3[transforms.Length]; - Vector2[] points = new Vector2[transforms.Length]; + // Calculate delta from the local position + CalculateLinePoints(); + - // First, convert the pivot to worldspace + //save previous states + previousLrPos = lrWorldPos; + previousGlobalScale = rt.lossyScale; + previousPositions = new Vector3[transforms.Length]; for (int i = 0; i < transforms.Length; i++) { if (transforms[i] == null) { continue; } - worldSpaces[i] = transforms[i].TransformPoint(thisPivot); - } - - // Then, convert to canvas space - for (int i = 0; i < transforms.Length; i++) - { - canvasSpaces[i] = canvas.InverseTransformPoint(worldSpaces[i]); - } - - // Calculate delta from the canvas pivot point - for (int i = 0; i < transforms.Length; i++) - { - points[i] = new Vector2(canvasSpaces[i].x, canvasSpaces[i].y); + previousPositions[i] = transforms[i].position; } + } - // And assign the converted points to the line renderer - lr.Points = points; - lr.RelativeSize = false; - lr.drivenExternally = true; - - previousPositions = new Vector3[transforms.Length]; + private void CalculateLinePoints() + { + Vector2[] points = new Vector2[transforms.Length]; for (int i = 0; i < transforms.Length; i++) { if (transforms[i] == null) { continue; } - previousPositions[i] = transforms[i].position; + var offsetPos = rt.InverseTransformPoint(transforms[i].position); + points[i] = new Vector2(offsetPos.x, offsetPos.y); } + + // And assign the converted points to the line renderer + lr.Points = points; + lr.RelativeSize = false; + lr.drivenExternally = true; } } } \ No newline at end of file diff --git a/package.json b/package.json index 591a6824..ae04d038 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.uiextensions", "displayName": "Unity UI Extensions", - "version": "2.3.2", + "version": "2.3.3-pre.1", "description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community", "author": "Simon darkside Jackson <@SimonDarksideJ>", "contributors": [