diff --git a/.github/workflows/buildupmpackages.yml b/.github/workflows/development-buildandtestupmrelease.yml similarity index 65% rename from .github/workflows/buildupmpackages.yml rename to .github/workflows/development-buildandtestupmrelease.yml index 01e1795..a61beba 100644 --- a/.github/workflows/buildupmpackages.yml +++ b/.github/workflows/development-buildandtestupmrelease.yml @@ -1,10 +1,10 @@ -name: Build and test UPM packages for platforms on all available Unity Versions +name: Build and test UPM packages for platforms, all branches except main on: pull_request: branches-ignore: - 'release' - # Ignore PRs targetting main + # Ignore PRs targeting main # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -14,6 +14,7 @@ concurrency: cancel-in-progress: true jobs: + # Check Unity version required by the package # Run Unity build unit tests defined in the package for a single version for feature branches Run-Partial-Unit-Tests: name: Run Unity Unit Tests @@ -26,12 +27,4 @@ jobs: Run-Full-Unit-Tests: name: Run Unity Unit Tests if: github.ref == 'refs/heads/development' - uses: ./.github/workflows/rununitybuildmultiversion.yml - - # Update the package release version - Update-Version: - name: Update Package Version - uses: ./.github/workflows/tagrelease.yml - with: - build-target: windows - secrets: inherit + uses: ./.github/workflows/rununitybuildmultiversion.yml \ No newline at end of file diff --git a/.github/workflows/development-publish.yml b/.github/workflows/development-publish.yml new file mode 100644 index 0000000..a770e9d --- /dev/null +++ b/.github/workflows/development-publish.yml @@ -0,0 +1,26 @@ +name: Publish development branch on Merge + +on: + pull_request: + types: + - closed + branches: + - development + # On close of PR targeting development + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + release_on_merge: + if: github.event.pull_request.merged == true + name: Tag and Publish UPM package + uses: ./.github/workflows/upversionandtagrelease.yml + with: + build-host: ubuntu-latest + build-type: pre-release + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/main-publish.yml b/.github/workflows/main-publish.yml new file mode 100644 index 0000000..9120cb9 --- /dev/null +++ b/.github/workflows/main-publish.yml @@ -0,0 +1,91 @@ +name: Publish main branch and increment version + +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + # Get Version to tag and release the branch, no up-version - [no-ver] included in PR title + validate-environment: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver') + name: Get Version from UPM package + uses: ./.github/workflows/getpackageversionfrompackage.yml + with: + build-host: ubuntu-latest + + # Perform tagging + release-Package-only: + needs: validate-environment + name: Release package only, no upversion + uses: ./.github/workflows/tagrelease.yml + with: + build-host: ubuntu-latest + version: ${{ needs.validate-environment.outputs.packageversion }} + secrets: inherit + + # Up version the release and publish major release + upversion-major-Package: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver') == false && contains(github.event.pull_request.title, 'major-release') + name: Major Version package and release + uses: ./.github/workflows/upversionandtagrelease.yml + with: + build-host: ubuntu-latest + build-type: major + secrets: inherit + + # Up version the release and publish minor release + upversion-minor-Package: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver') == false && contains(github.event.pull_request.title, 'minor-release') + name: Minor Version package and release + uses: ./.github/workflows/upversionandtagrelease.yml + with: + build-host: ubuntu-latest + build-type: minor + secrets: inherit + + # Up version the release and publish patch release (default) + upversion-patch-Package: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver') == false && contains(github.event.pull_request.title, 'minor-release') == false && contains(github.event.pull_request.title, 'major-release') == false + name: Patch Version package and release + uses: ./.github/workflows/upversionandtagrelease.yml + with: + build-host: ubuntu-latest + build-type: patch-release + secrets: inherit + + release-Complete: + if: ${{ always() }} + needs: [upversion-major-Package, upversion-minor-Package, upversion-patch-Package, release-Package-only] + name: Release complete + runs-on: ubuntu-latest + steps: + - name: Script Version + run: echo "Release done, updating Development" + + # Refresh the development branch with the main publish + refresh-development: + if: ${{ always() }} + needs: [release-Complete] + name: Refresh development branch + uses: ./.github/workflows/refreshbranch.yml + with: + build-host: ubuntu-latest + target-branch: development + source-branch: main + secrets: inherit + + # Up version the development branch ready for future development + upversion-development: + if: ${{ always() }} + needs: [refresh-development] + name: UpVersion the development branch for the next release + uses: ./.github/workflows/upversionandtagrelease.yml + with: + build-host: ubuntu-latest + build-type: patch + target-branch: development + createTag: false + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/refreshbranch.yml b/.github/workflows/refreshbranch.yml new file mode 100644 index 0000000..fb8a021 --- /dev/null +++ b/.github/workflows/refreshbranch.yml @@ -0,0 +1,43 @@ +name: Refresh branch + +on: + workflow_call: + inputs: + build-host: + required: true + type: string + target-branch: + required: true + type: string + source-branch: + required: true + type: string + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + packageRelease: + name: Refresh ${{ inputs.target-branch }} branch from ${{ inputs.source-branch }} branch + runs-on: ${{ inputs.build-host }} + steps: + - name: Script Version + run: | + echo "::group::Script Versioning" + $scriptVersion = "1.0.1" + echo "Build Script Version: $scriptVersion" + echo "::endgroup::" + shell: pwsh + - uses: actions/checkout@v3 + with: + ref: ${{ inputs.target-branch }} + clean: true + token: ${{ secrets.GIT_PAT }} + - name: Refresh from Source Branch + run: | + git pull origin ${{ inputs.source-branch }} + git commit -m "Branch ${{ inputs.target-branch }} updated with changes from ${{ inputs.source-branch }} [skip ci]" + git push origin ${{ inputs.target-branch }} + echo "Branch ${{ inputs.target-branch }} updated with changes from ${{ inputs.source-branch }}" + shell: pwsh \ No newline at end of file diff --git a/.github/workflows/rununitybuildmultiversion.yml b/.github/workflows/rununitybuildmultiversion.yml index bd98ccf..3a5a542 100644 --- a/.github/workflows/rununitybuildmultiversion.yml +++ b/.github/workflows/rununitybuildmultiversion.yml @@ -80,7 +80,7 @@ jobs: name: 'Run Unity Builds' run: | echo "::group::Set Hub and editor locations" - $unityVersion = ${{ matrix.unityVersion }} + $unityVersion = '${{ matrix.unityVersion }}' echo "::group::Set Hub and editor locations" @@ -90,6 +90,7 @@ jobs: $hubPath = "C:\Program Files\Unity Hub\Unity Hub.exe" $editorRootPath = "C:\Program Files\Unity\Hub\Editor\" $editorFileEx = "\Editor\Unity.exe" + $directorySeparatorChar = "\" #"Unity Hub.exe" -- --headless help #. 'C:\Program Files\Unity Hub\Unity Hub.exe' -- --headless help @@ -103,6 +104,7 @@ jobs: $hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" $editorRootPath = "/Applications/Unity/Hub/Editor/" $editorFileEx = "/Unity.app/Contents/MacOS/Unity" + $directorySeparatorChar = "/" # /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help function unity-hub @@ -115,6 +117,7 @@ jobs: $hubPath = "$HOME/Unity Hub/UnityHub.AppImage" $editorRootPath = "$HOME/Unity/Hub/Editor/" $editorFileEx = "/Editor/Unity" + $directorySeparatorChar = "/" # /UnityHub.AppImage --headless help # xvfb-run --auto-servernum "$HOME/Unity Hub/UnityHub.AppImage" --headless help @@ -126,8 +129,6 @@ jobs: echo "::endgroup::" - - echo "::group::Get String function to query a string for a value" function GetString($InputString, $InputPattern, $MatchIndex) @@ -151,10 +152,9 @@ jobs: echo "::endgroup::" echo "::group::Get Installed Unity version based on Matrix" - echo 'Script Start' echo "Unity hub path is {$hubPath}" echo "Requested unity version is {$unityVersion}" - + $InstalledUnityVersions = unity-hub editors $editorRootPath = unity-hub ip -g echo "Installed unity versions are {$InstalledUnityVersions}" @@ -171,7 +171,7 @@ jobs: $queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion" -MatchIndex 0 } - echo "Found unity version is {$queryUnityVersion}" + echo "Found unity version is {$queryUnityVersion} for input {$unityVersion}" if ($queryUnityVersion -ne 0) { @@ -456,4 +456,4 @@ jobs: if: always() with: name: unity-build-log - path: Logs/** \ No newline at end of file + path: Logs/** \ No newline at end of file diff --git a/.github/workflows/rununitysinglebuild.yml b/.github/workflows/rununitysinglebuild.yml index 58404ce..a6f2e8a 100644 --- a/.github/workflows/rununitysinglebuild.yml +++ b/.github/workflows/rununitysinglebuild.yml @@ -40,12 +40,11 @@ jobs: with: submodules: recursive clean: true - - id: build name: 'Run Unity Builds' run: | echo "::group::Set Hub and editor locations" - $unityVersion = ${{ inputs.unityVersion }} + $unityVersion = '${{ inputs.unityVersion }}' echo "::group::Set Hub and editor locations" @@ -55,6 +54,7 @@ jobs: $hubPath = "C:\Program Files\Unity Hub\Unity Hub.exe" $editorRootPath = "C:\Program Files\Unity\Hub\Editor\" $editorFileEx = "\Editor\Unity.exe" + $directorySeparatorChar = "\" #"Unity Hub.exe" -- --headless help #. 'C:\Program Files\Unity Hub\Unity Hub.exe' -- --headless help @@ -68,6 +68,7 @@ jobs: $hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" $editorRootPath = "/Applications/Unity/Hub/Editor/" $editorFileEx = "/Unity.app/Contents/MacOS/Unity" + $directorySeparatorChar = "/" # /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help function unity-hub @@ -80,6 +81,7 @@ jobs: $hubPath = "$HOME/Unity Hub/UnityHub.AppImage" $editorRootPath = "$HOME/Unity/Hub/Editor/" $editorFileEx = "/Editor/Unity" + $directorySeparatorChar = "/" # /UnityHub.AppImage --headless help # xvfb-run --auto-servernum "$HOME/Unity Hub/UnityHub.AppImage" --headless help @@ -91,8 +93,6 @@ jobs: echo "::endgroup::" - - echo "::group::Get String function to query a string for a value" function GetString($InputString, $InputPattern, $MatchIndex) @@ -115,8 +115,7 @@ jobs: } echo "::endgroup::" - echo "::group::Get Installed Unity version based on Matrix" - echo 'Script Start' + echo "::group::Find Installed Unity version based on input" echo "Unity hub path is {$hubPath}" echo "Requested unity version is {$unityVersion}" @@ -136,7 +135,7 @@ jobs: $queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion" -MatchIndex 0 } - echo "Found unity version is {$queryUnityVersion}" + echo "Found unity version is {$queryUnityVersion} for input {$unityVersion}" if ($queryUnityVersion -ne 0) { @@ -421,4 +420,4 @@ jobs: if: always() with: name: unity-build-log - path: Logs/** \ No newline at end of file + path: Logs/** \ No newline at end of file diff --git a/.github/workflows/tagrelease.yml b/.github/workflows/tagrelease.yml index c690863..d572d76 100644 --- a/.github/workflows/tagrelease.yml +++ b/.github/workflows/tagrelease.yml @@ -1,33 +1,26 @@ -name: Package UPM project and deploy +name: Tag Release on: workflow_call: inputs: - build-target: + build-host: + required: true + type: string + version: required: true type: string - build-type: - required: false - default: 'pre-release' - type: string -# options: -# - major -# - minor -# - patch -# - pre-release -# - build - outputs: - packageversion: - description: "Returns the version of Unity the UPM package requires" - value: ${{ jobs.packageRelease.outputs.packageversion }} - secrets: - GIT_USER_NAME: - required: false + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true jobs: packageRelease: name: Package UPM Project and tag - runs-on: ${{ inputs.build-target }} + runs-on: ${{ inputs.build-host }} outputs: packageversion: ${{ steps.getpackageversion.outputs.packageversion }} steps: @@ -40,6 +33,7 @@ jobs: shell: pwsh - uses: actions/checkout@v3 with: + fetch-depth: 0 submodules: recursive clean: true token: ${{ secrets.GIT_PAT }} @@ -60,87 +54,26 @@ jobs: $gitUser = "${{ secrets.GIT_USER_NAME }}" $gitEmail = "$gitUser@users.noreply.github.com" } - echo "email $gitUser@users.noreply.github.com" git config --global user.email "$gitUser@users.noreply.github.com" git config --global user.name "$gitUser" - shell: pwsh - - id: getpackageversion - name: Bump UPM Package version + shell: pwsh + - name: Check if Tag Exists run: | - function UpdateProjectVersionJSON { - param ( - [Parameter(Mandatory)] - $type, - $packageFile = 'package.json' - ) - <# - Type of build can be one of the following - - 'build' # Build release - 1.0.0-pre-release.0+1 - - 'pre-release' # Pre-Release release - 1.0.0-pre-release.1 - - 'patch' # Patch release - 1.0.1 - - 'minor' # Minor release - 1.1.0 - - 'major' # Major release - 2.0.0 - #> - - if ( -not (Test-Path -Path $packageFile) ) { - Write-Error "Failed to find a valid project manifest at `"$packageFile`"" - return $null + $tagVersion = "${{ inputs.version }}" + $tags = git tag + echo "Tags found are [$tags], searching for [$tagVersion]" + foreach ($tag in $tags) + { + if($tag.Trim() -eq "$tagVersion") + { + Write-Error "$tagVersion tag already exists" + exit 1 } - - $packageInfo = (Get-Content $packageFile -Raw) | ConvertFrom-Json - Write-Host "Detected Project Version:" $packageInfo.version - function IfNull($a, $b, $c) { if ($null -eq $a) { return $b } else { return $c } } - - $packageSemVer = [System.Management.Automation.SemanticVersion]$packageInfo.version - $majorVersion = if($null -eq $packageSemVer.Major) {0} else {$packageSemVer.Major} - $minorVersion = if($null -eq $packageSemVer.Minor) {0} else {$packageSemVer.Minor} - $patchVersion = if($null -eq $packageSemVer.Patch) {0} else {$packageSemVer.Patch} - $prereleaseVersion = if($null -eq $packageSemVer.PreReleaseLabel) {0} else {$packageSemVer.PreReleaseLabel.Replace('pre-release.','')} - $buildVersion = if($null -eq $packageSemVer.BuildLabel) {0} else {$packageSemVer.BuildLabel} - - # work out new version - switch ($type) { - 'build' { - [int]$buildVersion += 1 - $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre-release." + $prereleaseVersion, $buildVersion) - } - 'pre-release' { - [int]$prereleaseVersion += 1 - $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre-release." + $prereleaseVersion) - } - 'patch' { - [int]$patchVersion += 1 - $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion) - } - 'minor' { - [int]$minorVersion += 1 - $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, 0) - } - 'major' { - [int]$majorVersion += 1 - $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, 0, 0) - } - } - - Write-Host "Upgrading project version [$packageSemVer] to [$newPackageSemVer]" - - # Write out updated package info - - $packageInfo.version = $newPackageSemVer.ToString() - $packageInfo | ConvertTo-Json | Set-Content $packageFile - - return $packageInfo.version } - - $packageFile = 'package.json' - $result = UpdateProjectVersionJSON("${{ inputs.build-type }}","$packageFile") - if([string]::IsNullOrEmpty($result)) { - echo "Version patch failed" - exit 1 - } - echo "packageversion=$result" >> $env:GITHUB_OUTPUT - git add "$packageFile" - git commit -m "Auto increment pre-release version to $result [skip ci]" - git tag -fa "$result" "${GITHUB_SHA}" -m "$result Release" - git push origin --force - shell: pwsh \ No newline at end of file + shell: pwsh + - name: Create tag and push + run: | + $tagVersion = "${{ inputs.version }}" + git tag -fa "v$tagVersion" "${GITHUB_SHA}" -m "v$tagVersion Release [skip ci]" + git push origin "v$tagVersion" --force + shell: pwsh \ No newline at end of file diff --git a/.github/workflows/upversionandtagrelease.yml b/.github/workflows/upversionandtagrelease.yml new file mode 100644 index 0000000..4e630ba --- /dev/null +++ b/.github/workflows/upversionandtagrelease.yml @@ -0,0 +1,181 @@ +name: UpVersion Package UPM project and create new tag + +on: + workflow_call: + inputs: + build-host: + required: true + type: string + build-type: + required: false + default: 'pre-release' + type: string +# options: +# - major +# - minor +# - patch +# - patch-release +# - pre-release +# - build + target-branch: + required: false + type: string + default: ${{ github.ref }} + createTag: + required: false + type: boolean + default: true + + outputs: + packageversion: + description: "Returns the version of Unity the UPM package requires" + value: ${{ jobs.packageRelease.outputs.packageversion }} + secrets: + GIT_PAT: + required: true + +jobs: + packageRelease: + name: Package UPM Project and tag + runs-on: ${{ inputs.build-host }} + outputs: + packageversion: ${{ steps.getpackageversion.outputs.packageversion }} + steps: + - name: Script Version + run: | + echo "::group::Script Versioning" + $scriptVersion = "1.0.2" + echo "Build Script Version: $scriptVersion" + echo "::endgroup::" + shell: pwsh + - uses: actions/checkout@v3 + with: + ref: ${{ inputs.target-branch }} + fetch-depth: 0 + submodules: recursive + clean: true + token: ${{ secrets.GIT_PAT }} + - uses: actions/setup-node@v3 + - name: Set Github vars + run: | + if([string]::IsNullOrEmpty('${{ secrets.GIT_USER_NAME }}')){ + if([string]::IsNullOrEmpty('${{ secrets.GIT_USER_NAME }}')){ + $gitUser = "action" + $gitEmail = "action@github.com" + } + else { + $gitUser = "${GITHUB_ACTOR}" + $gitEmail = "$gitUser@users.noreply.github.com" + } + } + else { + $gitUser = "${{ secrets.GIT_USER_NAME }}" + $gitEmail = "$gitUser@users.noreply.github.com" + } + git config --global user.email "$gitUser@users.noreply.github.com" + git config --global user.name "$gitUser" + shell: pwsh + - id: getpackageversion + name: Bump UPM Package version + run: | + function UpdateProjectVersionJSON { + param ( + [Parameter(Mandatory)] + $type, + $packageFile = 'package.json' + ) + <# + Type of build can be one of the following + - 'build' # Build release - 1.0.0-pre.0+1 + - 'pre-release' # Pre-Release - 1.0.0-pre.1 + - 'patch-release' # Patch release - 1.0.1 (reset preview version to current patch, no increase) + - 'patch' # Patch release - 1.0.1 + - 'minor' # Minor release - 1.1.0 + - 'major' # Major release - 2.0.0 + #> + + if ( -not (Test-Path -Path $packageFile) ) { + Write-Error "Failed to find a valid project manifest at `"$packageFile`"" + return $null + } + + $packageInfo = (Get-Content $packageFile -Raw) | ConvertFrom-Json + Write-Host "Detected Project Version:" $packageInfo.version + function IfNull($a, $b, $c) { if ($null -eq $a) { return $b } else { return $c } } + + $packageSemVer = [System.Management.Automation.SemanticVersion]$packageInfo.version + $majorVersion = if($null -eq $packageSemVer.Major) {0} else {$packageSemVer.Major} + $minorVersion = if($null -eq $packageSemVer.Minor) {0} else {$packageSemVer.Minor} + $patchVersion = if($null -eq $packageSemVer.Patch) {0} else {$packageSemVer.Patch} + $prereleaseVersion = if($null -eq $packageSemVer.PreReleaseLabel) {0} else {$packageSemVer.PreReleaseLabel.Replace('pre.','')} + $buildVersion = if($null -eq $packageSemVer.BuildLabel) {0} else {$packageSemVer.BuildLabel} + + # work out new version + switch ($type) { + 'build' { + [int]$buildVersion += 1 + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre." + $prereleaseVersion, $buildVersion) + } + 'pre-release' { + [int]$prereleaseVersion += 1 + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre." + $prereleaseVersion) + } + 'patch-release' { + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion) + } + 'patch' { + [int]$patchVersion += 1 + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion) + } + 'minor' { + [int]$minorVersion += 1 + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, 0) + } + 'major' { + [int]$majorVersion += 1 + $newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, 0, 0) + } + } + + Write-Host "Upgrading project version [$packageSemVer] to [$newPackageSemVer]" + + # Write out updated package info + + $packageInfo.version = $newPackageSemVer.ToString() + $packageInfo | ConvertTo-Json | Set-Content $packageFile + + return $packageInfo.version + } + + $packageFile = 'package.json' + $result = UpdateProjectVersionJSON("${{ inputs.build-type }}","$packageFile") + if([string]::IsNullOrEmpty($result)) { + echo "Version patch failed" + exit 1 + } + git add "$packageFile" + git commit -m "Auto increment pre-release version to $result [skip ci]" + git push origin + echo "packageversion=$result" >> $env:GITHUB_OUTPUT + shell: pwsh + - name: Check if Tag Exists + run: | + $tagVersion = '${{steps.getpackageversion.outputs.packageversion }}' + $tags = git tag + echo "Tags found are [$tags], searching for [$tagVersion]" + foreach ($tag in $tags) + { + if($tag.Trim() -eq "$tagVersion") + { + Write-Error "$tagVersion tag already exists" + exit 1 + } + } + shell: pwsh + - name: Publish package tag + if: ${{inputs.createTag == true}} + run: | + $outputVersion = '${{steps.getpackageversion.outputs.packageversion }}' + git tag -fa "v$outputVersion" "${GITHUB_SHA}" -m "v$outputVersion Release" + git push origin "v$outputVersion" --force --tags + shell: pwsh \ No newline at end of file diff --git a/README.md b/README.md index 454e909..90bc0bb 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,8 @@ There are almost 70+ extension controls / effect and other utilities in the proj |NicerOutline|RaycastMask|UIFlippable|UIImageCrop|SoftAlphaMask| |CylinderText|UIParticleSystem|CurlyUI|Shine Effect|Shader Effects| +> Text Effects are not supported with TextMeshPro due to its architecture, try using the native TextMeshPro effects instead. + [Additional Components](https://unity-ui-extensions.github.io/Controls.html#additional-components) |ReturnKeyTrigger|TabNavigation|uGUITools|ScrollRectTweener|ScrollRectLinker| diff --git a/Runtime/Scripts/Effects/CurvedText.cs b/Runtime/Scripts/Effects/CurvedText.cs index b26d01d..1f69c7e 100644 --- a/Runtime/Scripts/Effects/CurvedText.cs +++ b/Runtime/Scripts/Effects/CurvedText.cs @@ -1,13 +1,10 @@ /// Credit Breyer /// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1777407 +#if !UNITY_2022_1_OR_NEWER namespace UnityEngine.UI.Extensions { -#if UNITY_2022_1_OR_NEWER - [RequireComponent(typeof(TMPro.TMP_Text))] -#else [RequireComponent(typeof(Text))] -#endif [RequireComponent(typeof(RectTransform))] [AddComponentMenu("UI/Effects/Extensions/Curved Text")] public class CurvedText : BaseMeshEffect @@ -87,3 +84,4 @@ namespace UnityEngine.UI.Extensions } } } +#endif \ No newline at end of file diff --git a/Runtime/Scripts/Effects/CylinderText.cs b/Runtime/Scripts/Effects/CylinderText.cs index 541f8e0..a303cb4 100644 --- a/Runtime/Scripts/Effects/CylinderText.cs +++ b/Runtime/Scripts/Effects/CylinderText.cs @@ -1,14 +1,11 @@ /// adaption for cylindrical bending by herbst /// Credit Breyer /// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1777407 +#if UNITY_2022_1_OR_NEWER namespace UnityEngine.UI.Extensions { -#if UNITY_2022_1_OR_NEWER - [RequireComponent(typeof(TMPro.TMP_Text))] -#else [RequireComponent(typeof(Text))] -#endif [RequireComponent(typeof(RectTransform))] [AddComponentMenu("UI/Effects/Extensions/Cylinder Text")] public class CylinderText : BaseMeshEffect @@ -57,3 +54,4 @@ namespace UnityEngine.UI.Extensions } } } +#endif \ No newline at end of file diff --git a/Runtime/Scripts/Effects/LetterSpacing.cs b/Runtime/Scripts/Effects/LetterSpacing.cs index e9fea6c..8b3b14e 100644 --- a/Runtime/Scripts/Effects/LetterSpacing.cs +++ b/Runtime/Scripts/Effects/LetterSpacing.cs @@ -40,7 +40,7 @@ use HTML-like tags in your text. Try it out, you'll see what I mean. It doesn't break down entirely, but it doesn't really do what you'd want either. */ - +#if !UNITY_2022_1_OR_NEWER using System.Collections.Generic; namespace UnityEngine.UI.Extensions @@ -74,6 +74,11 @@ namespace UnityEngine.UI.Extensions } } + protected override void Awake() + { + Debug.Log($"Awake, [{m_spacing}]"); + } + public override void ModifyMesh(VertexHelper vh) { if (! IsActive()) return; @@ -81,11 +86,8 @@ namespace UnityEngine.UI.Extensions List verts = new List(); vh.GetUIVertexStream(verts); -#if UNITY_2022_1_OR_NEWER - var text = GetComponent(); -#else var text = GetComponent(); -#endif + if (text == null) { Debug.LogWarning("LetterSpacing: Missing Text component"); @@ -98,28 +100,6 @@ namespace UnityEngine.UI.Extensions float alignmentFactor = 0; int glyphIdx = 0; -#if UNITY_2022_1_OR_NEWER - switch (text.alignment) - { - case TMPro.TextAlignmentOptions.BottomLeft: - case TMPro.TextAlignmentOptions.MidlineLeft: - case TMPro.TextAlignmentOptions.TopLeft: - alignmentFactor = 0f; - break; - - case TMPro.TextAlignmentOptions.BottomJustified: - case TMPro.TextAlignmentOptions.MidlineJustified: - case TMPro.TextAlignmentOptions.TopJustified: - alignmentFactor = 0.5f; - break; - - case TMPro.TextAlignmentOptions.BottomRight: - case TMPro.TextAlignmentOptions.MidlineRight: - case TMPro.TextAlignmentOptions.TopRight: - alignmentFactor = 1f; - break; - } -#else switch (text.alignment) { case TextAnchor.LowerLeft: @@ -140,8 +120,7 @@ namespace UnityEngine.UI.Extensions alignmentFactor = 1f; break; } -#endif - + for (int lineIdx=0; lineIdx < lines.Length; lineIdx++) { string line = lines[lineIdx]; @@ -193,3 +172,4 @@ namespace UnityEngine.UI.Extensions } } } +#endif \ No newline at end of file diff --git a/Runtime/Scripts/Effects/MonoSpacing.cs b/Runtime/Scripts/Effects/MonoSpacing.cs index 465f547..66877dd 100644 --- a/Runtime/Scripts/Effects/MonoSpacing.cs +++ b/Runtime/Scripts/Effects/MonoSpacing.cs @@ -40,17 +40,14 @@ use HTML-like tags in your text. Try it out, you'll see what I mean. It doesn't break down entirely, but it doesn't really do what you'd want either. */ +#if !UNITY_2022_1_OR_NEWER using System.Collections.Generic; namespace UnityEngine.UI.Extensions { [AddComponentMenu("UI/Effects/Extensions/Mono Spacing")] -#if UNITY_2022_1_OR_NEWER - [RequireComponent(typeof(TMPro.TMP_Text))] -#else [RequireComponent(typeof(Text))] -#endif [RequireComponent(typeof(RectTransform))] ///Summary /// Note, Vertex Count has changed in 5.2.1+, is now 6 (two tris) instead of 4 (tri strip). @@ -62,21 +59,15 @@ namespace UnityEngine.UI.Extensions public bool UseHalfCharWidth = false; private RectTransform rectTransform; -#if UNITY_2022_1_OR_NEWER - private TMPro.TMP_Text text; -#else + private Text text; -#endif protected MonoSpacing() { } protected override void Awake() { -#if UNITY_2022_1_OR_NEWER - text = GetComponent(); -#else text = GetComponent(); -#endif + if (text == null) { Debug.LogWarning("MonoSpacing: Missing Text component"); @@ -117,28 +108,6 @@ namespace UnityEngine.UI.Extensions float alignmentFactor = 0; int glyphIdx = 0; -#if UNITY_2022_1_OR_NEWER - switch (text.alignment) - { - case TMPro.TextAlignmentOptions.BottomLeft: - case TMPro.TextAlignmentOptions.MidlineLeft: - case TMPro.TextAlignmentOptions.TopLeft: - alignmentFactor = 0f; - break; - - case TMPro.TextAlignmentOptions.BottomJustified: - case TMPro.TextAlignmentOptions.MidlineJustified: - case TMPro.TextAlignmentOptions.TopJustified: - alignmentFactor = 0.5f; - break; - - case TMPro.TextAlignmentOptions.BottomRight: - case TMPro.TextAlignmentOptions.MidlineRight: - case TMPro.TextAlignmentOptions.TopRight: - alignmentFactor = 1f; - break; - } -#else switch (text.alignment) { case TextAnchor.LowerLeft: @@ -159,7 +128,7 @@ namespace UnityEngine.UI.Extensions alignmentFactor = 1f; break; } -#endif + for (int lineIdx=0; lineIdx < lines.Length; lineIdx++) { string line = lines[lineIdx]; @@ -221,4 +190,5 @@ namespace UnityEngine.UI.Extensions vh.AddUIVertexTriangleStream(verts); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Runtime/Scripts/Layout/FlowLayoutGroup.cs b/Runtime/Scripts/Layout/FlowLayoutGroup.cs index 1aaccd9..fd16a25 100644 --- a/Runtime/Scripts/Layout/FlowLayoutGroup.cs +++ b/Runtime/Scripts/Layout/FlowLayoutGroup.cs @@ -6,6 +6,7 @@ /// Vertical Flow by Ramon Molossi using System.Collections.Generic; +using System.Text; namespace UnityEngine.UI.Extensions { @@ -17,27 +18,32 @@ namespace UnityEngine.UI.Extensions { public enum Axis { Horizontal = 0, Vertical = 1 } - public float SpacingX = 0f; + private float _layoutHeight; + private float _layoutWidth; + + public float SpacingX = 0f; public float SpacingY = 0f; public bool ExpandHorizontalSpacing = false; - public bool ChildForceExpandWidth = false; public bool ChildForceExpandHeight = false; public bool invertOrder = false; - private float _layoutHeight; - private float _layoutWidth; - [SerializeField] protected Axis m_StartAxis = Axis.Horizontal; - public Axis startAxis { get { return m_StartAxis; } set { SetProperty(ref m_StartAxis, value); } } + [SerializeField] + protected Axis m_StartAxis = Axis.Horizontal; + + public Axis StartAxis { get { return m_StartAxis; } set { SetProperty(ref m_StartAxis, value); } } public override void CalculateLayoutInputHorizontal() { - if (startAxis == Axis.Horizontal) { - base.CalculateLayoutInputHorizontal (); - var minWidth = GetGreatestMinimumChildWidth () + padding.left + padding.right; - SetLayoutInputForAxis (minWidth, -1, -1, 0); - } else { - _layoutWidth = SetLayout (0, true); + if (StartAxis == Axis.Horizontal) + { + base.CalculateLayoutInputHorizontal(); + var minWidth = GetGreatestMinimumChildWidth() + padding.left + padding.right; + SetLayoutInputForAxis(minWidth, -1, -1, 0); + } + else + { + _layoutWidth = SetLayout(0, true); } } @@ -54,55 +60,42 @@ namespace UnityEngine.UI.Extensions public override void CalculateLayoutInputVertical() { - if (startAxis == Axis.Horizontal) { - _layoutHeight = SetLayout (1, true); - } else { - base.CalculateLayoutInputHorizontal (); - var minHeight = GetGreatestMinimumChildHeigth () + padding.bottom + padding.top; - SetLayoutInputForAxis (minHeight, -1, -1, 1); + if (StartAxis == Axis.Horizontal) + { + _layoutHeight = SetLayout(1, true); + } + else + { + base.CalculateLayoutInputHorizontal(); + var minHeight = GetGreatestMinimumChildHeigth() + padding.bottom + padding.top; + SetLayoutInputForAxis(minHeight, -1, -1, 1); } } protected bool IsCenterAlign { - get - { - return childAlignment == TextAnchor.LowerCenter || childAlignment == TextAnchor.MiddleCenter || - childAlignment == TextAnchor.UpperCenter; - } + get => childAlignment == TextAnchor.LowerCenter || childAlignment == TextAnchor.MiddleCenter || childAlignment == TextAnchor.UpperCenter; } protected bool IsRightAlign { - get - { - return childAlignment == TextAnchor.LowerRight || childAlignment == TextAnchor.MiddleRight || - childAlignment == TextAnchor.UpperRight; - } + get => childAlignment == TextAnchor.LowerRight || childAlignment == TextAnchor.MiddleRight || childAlignment == TextAnchor.UpperRight; } protected bool IsMiddleAlign { - get - { - return childAlignment == TextAnchor.MiddleLeft || childAlignment == TextAnchor.MiddleRight || - childAlignment == TextAnchor.MiddleCenter; - } + get => childAlignment == TextAnchor.MiddleLeft || childAlignment == TextAnchor.MiddleRight || childAlignment == TextAnchor.MiddleCenter; } protected bool IsLowerAlign { - get - { - return childAlignment == TextAnchor.LowerLeft || childAlignment == TextAnchor.LowerRight || - childAlignment == TextAnchor.LowerCenter; - } + get => childAlignment == TextAnchor.LowerLeft || childAlignment == TextAnchor.LowerRight || childAlignment == TextAnchor.LowerCenter; } /// /// Holds the rects that will make up the current bar being processed /// - private readonly IList _itemList = new List(); + private readonly IList _itemList = new List(); /// /// Main layout method @@ -122,25 +115,34 @@ namespace UnityEngine.UI.Extensions float counterOffset = 0; float groupSize = 0; float workingSize = 0; - if (startAxis == Axis.Horizontal) { + if (StartAxis == Axis.Horizontal) + { groupSize = groupHeight; workingSize = groupWidth - padding.left - padding.right; - if (IsLowerAlign) { + if (IsLowerAlign) + { offset = (float)padding.bottom; counterOffset = (float)padding.top; - } else { + } + else + { offset = (float)padding.top; counterOffset = (float)padding.bottom; } spacingBetweenBars = SpacingY; spacingBetweenElements = SpacingX; - } else if (startAxis == Axis.Vertical) { + } + else if (StartAxis == Axis.Vertical) + { groupSize = groupWidth; workingSize = groupHeight - padding.top - padding.bottom; - if (IsRightAlign) { + if (IsRightAlign) + { offset = (float)padding.right; counterOffset = (float)padding.left; - } else { + } + else + { offset = (float)padding.left; counterOffset = (float)padding.right; } @@ -151,50 +153,59 @@ namespace UnityEngine.UI.Extensions var currentBarSize = 0f; var currentBarSpace = 0f; - for (var i = 0; i < rectChildren.Count; i++) { - + for (var i = 0; i < rectChildren.Count; i++) + { int index = i; - var child = rectChildren [index]; + var child = rectChildren[index]; float childSize = 0; float childOtherSize = 0; //get height and width of elements. - if (startAxis == Axis.Horizontal) { - if (invertOrder) { - index = IsLowerAlign ? rectChildren.Count - 1 - i : i; + if (StartAxis == Axis.Horizontal) + { + if (invertOrder) + { + index = IsLowerAlign ? rectChildren.Count - 1 - i : i; } - child = rectChildren [index]; - childSize = LayoutUtility.GetPreferredSize (child, 0); - childSize = Mathf.Min (childSize, workingSize); - childOtherSize = LayoutUtility.GetPreferredSize (child, 1); - } else if (startAxis == Axis.Vertical) { - if (invertOrder) { + child = rectChildren[index]; + childSize = LayoutUtility.GetPreferredSize(child, 0); + childSize = Mathf.Min(childSize, workingSize); + childOtherSize = LayoutUtility.GetPreferredSize(child, 1); + } + else if (StartAxis == Axis.Vertical) + { + if (invertOrder) + { index = IsRightAlign ? rectChildren.Count - 1 - i : i; } - child = rectChildren [index]; - childSize = LayoutUtility.GetPreferredSize (child, 1); - childSize = Mathf.Min (childSize, workingSize); - childOtherSize = LayoutUtility.GetPreferredSize (child, 0); + child = rectChildren[index]; + childSize = LayoutUtility.GetPreferredSize(child, 1); + childSize = Mathf.Min(childSize, workingSize); + childOtherSize = LayoutUtility.GetPreferredSize(child, 0); } // If adding this element would exceed the bounds of the container, // go to a new bar after processing the current bar - if (currentBarSize + childSize > workingSize) { - + if (currentBarSize + childSize > workingSize) + { currentBarSize -= spacingBetweenElements; // Process current bar elements positioning - if (!layoutInput) { - if (startAxis == Axis.Horizontal) { - float newOffset = CalculateRowVerticalOffset (groupSize, offset, currentBarSpace); - LayoutRow (_itemList, currentBarSize, currentBarSpace, workingSize, padding.left, newOffset, axis); - } else if (startAxis == Axis.Vertical) { - float newOffset = CalculateColHorizontalOffset (groupSize, offset, currentBarSpace); - LayoutCol (_itemList, currentBarSpace, currentBarSize, workingSize, newOffset, padding.top, axis); + if (!layoutInput) + { + if (StartAxis == Axis.Horizontal) + { + float newOffset = CalculateRowVerticalOffset(groupSize, offset, currentBarSpace); + LayoutRow(_itemList, currentBarSize, currentBarSpace, workingSize, padding.left, newOffset, axis); + } + else if (StartAxis == Axis.Vertical) + { + float newOffset = CalculateColHorizontalOffset(groupSize, offset, currentBarSpace); + LayoutCol(_itemList, currentBarSpace, currentBarSize, workingSize, newOffset, padding.top, axis); } } // Clear existing bar - _itemList.Clear (); + _itemList.Clear(); // Add the current bar space to total barSpace accumulator, and reset to 0 for the next row offset += currentBarSpace; @@ -202,31 +213,28 @@ namespace UnityEngine.UI.Extensions currentBarSpace = 0; currentBarSize = 0; - } currentBarSize += childSize; - _itemList.Add (child); + _itemList.Add(child); // We need the largest element height to determine the starting position of the next line - if (childOtherSize > currentBarSpace) { - currentBarSpace = childOtherSize; - } + currentBarSpace = childOtherSize > currentBarSpace ? childOtherSize : currentBarSpace; - // Don't do this for the last one - if (i < rectChildren.Count - 1){ - currentBarSize += spacingBetweenElements; - } - + currentBarSize += spacingBetweenElements; } // Layout the final bar - if (!layoutInput) { - if (startAxis == Axis.Horizontal) { - float newOffset = CalculateRowVerticalOffset (groupHeight, offset, currentBarSpace); + if (!layoutInput) + { + if (StartAxis == Axis.Horizontal) + { + float newOffset = CalculateRowVerticalOffset(groupHeight, offset, currentBarSpace); currentBarSize -= spacingBetweenElements; - LayoutRow (_itemList, currentBarSize, currentBarSpace, workingSize, padding.left, newOffset, axis); - }else if (startAxis == Axis.Vertical) { + LayoutRow(_itemList, currentBarSize, currentBarSpace, workingSize, padding.left, newOffset, axis); + } + else if (StartAxis == Axis.Vertical) + { float newOffset = CalculateColHorizontalOffset(groupWidth, offset, currentBarSpace); currentBarSize -= spacingBetweenElements; LayoutCol(_itemList, currentBarSpace, currentBarSize, workingSize, newOffset, padding.top, axis); @@ -239,7 +247,8 @@ namespace UnityEngine.UI.Extensions offset += currentBarSpace; offset += counterOffset; - if (layoutInput) { + if (layoutInput) + { SetLayoutInputForAxis(offset, offset, -1, axis); } return offset; @@ -247,87 +256,109 @@ namespace UnityEngine.UI.Extensions private float CalculateRowVerticalOffset(float groupHeight, float yOffset, float currentRowHeight) { - if (IsLowerAlign) { + if (IsLowerAlign) + { return groupHeight - yOffset - currentRowHeight; - } else if (IsMiddleAlign) { - return groupHeight * 0.5f - _layoutHeight * 0.5f + yOffset; - } else { - return yOffset; } + else if (IsMiddleAlign) + { + return groupHeight * 0.5f - _layoutHeight * 0.5f + yOffset; + } + return yOffset; } private float CalculateColHorizontalOffset(float groupWidth, float xOffset, float currentColWidth) { - if (IsRightAlign) { + if (IsRightAlign) + { return groupWidth - xOffset - currentColWidth; - } else if (IsCenterAlign) { - return groupWidth * 0.5f - _layoutWidth * 0.5f + xOffset; - } else { - return xOffset; } + else if (IsCenterAlign) + { + return groupWidth * 0.5f - _layoutWidth * 0.5f + xOffset; + } + return xOffset; } protected void LayoutRow(IList contents, float rowWidth, float rowHeight, float maxWidth, float xOffset, float yOffset, int axis) { var xPos = xOffset; - if (!ChildForceExpandWidth && IsCenterAlign) { + if (!ChildForceExpandWidth && IsCenterAlign) + { xPos += (maxWidth - rowWidth) * 0.5f; - } else if (!ChildForceExpandWidth && IsRightAlign) { + } + else if (!ChildForceExpandWidth && IsRightAlign) + { xPos += (maxWidth - rowWidth); } var extraWidth = 0f; var extraSpacing = 0f; - if (ChildForceExpandWidth) { - extraWidth = (maxWidth - rowWidth)/_itemList.Count; + if (ChildForceExpandWidth) + { + extraWidth = (maxWidth - rowWidth) / contents.Count; } - else if (ExpandHorizontalSpacing) { - extraSpacing = (maxWidth - rowWidth)/(_itemList.Count - 1); - if (_itemList.Count > 1) { - if (IsCenterAlign) { - xPos -= extraSpacing * 0.5f * (_itemList.Count - 1); - } else if (IsRightAlign) { - xPos -= extraSpacing * (_itemList.Count - 1); + else if (ExpandHorizontalSpacing) + { + extraSpacing = (maxWidth - rowWidth) / (contents.Count - 1); + if (contents.Count > 1) + { + if (IsCenterAlign) + { + xPos -= extraSpacing * 0.5f * (contents.Count - 1); + } + else if (IsRightAlign) + { + xPos -= extraSpacing * (contents.Count - 1); } } } - for (var j = 0; j < _itemList.Count; j++) { + for (var j = 0; j < contents.Count; j++) + { + var index = IsLowerAlign ? contents.Count - 1 - j : j; - var index = IsLowerAlign ? _itemList.Count - 1 - j : j; - - var rowChild = _itemList[index]; + var rowChild = contents[index]; var rowChildWidth = LayoutUtility.GetPreferredSize(rowChild, 0) + extraWidth; var rowChildHeight = LayoutUtility.GetPreferredSize(rowChild, 1); if (ChildForceExpandHeight) + { rowChildHeight = rowHeight; + } rowChildWidth = Mathf.Min(rowChildWidth, maxWidth); - var yPos = yOffset; - if (IsMiddleAlign) { + if (IsMiddleAlign) + { yPos += (rowHeight - rowChildHeight) * 0.5f; - } else if (IsLowerAlign) { + } + else if (IsLowerAlign) + { yPos += (rowHeight - rowChildHeight); } - if (ExpandHorizontalSpacing && j > 0) { + if (ExpandHorizontalSpacing && j > 0) + { xPos += extraSpacing; } - if (axis == 0) { - SetChildAlongAxis (rowChild, 0, xPos, rowChildWidth); - } else { - SetChildAlongAxis (rowChild, 1, yPos, rowChildHeight); + if (axis == 0) + { + SetChildAlongAxis(rowChild, 0, xPos, rowChildWidth); + } + else + { + SetChildAlongAxis(rowChild, 1, yPos, rowChildHeight); } // Don't do horizontal spacing for the last one - if (j < _itemList.Count - 1) { + if (j < contents.Count - 1) + { xPos += rowChildWidth + SpacingX; } } @@ -337,39 +368,49 @@ namespace UnityEngine.UI.Extensions { var yPos = yOffset; - if (!ChildForceExpandHeight && IsMiddleAlign) { + if (!ChildForceExpandHeight && IsMiddleAlign) + { yPos += (maxHeight - colHeight) * 0.5f; - } else if (!ChildForceExpandHeight && IsLowerAlign) { + } + else if (!ChildForceExpandHeight && IsLowerAlign) + { yPos += (maxHeight - colHeight); } var extraHeight = 0f; var extraSpacing = 0f; - if (ChildForceExpandHeight) { - extraHeight = (maxHeight - colHeight)/_itemList.Count; + if (ChildForceExpandHeight) + { + extraHeight = (maxHeight - colHeight) / contents.Count; } - else if (ExpandHorizontalSpacing) { - extraSpacing = (maxHeight - colHeight)/(_itemList.Count - 1); - if (_itemList.Count > 1) { - if (IsMiddleAlign) { - yPos -= extraSpacing * 0.5f * (_itemList.Count - 1); - } else if (IsLowerAlign) { - yPos -= extraSpacing * (_itemList.Count - 1); + else if (ExpandHorizontalSpacing) + { + extraSpacing = (maxHeight - colHeight) / (contents.Count - 1); + if (contents.Count > 1) + { + if (IsMiddleAlign) + { + yPos -= extraSpacing * 0.5f * (contents.Count - 1); + } + else if (IsLowerAlign) + { + yPos -= extraSpacing * (contents.Count - 1); } } } - for (var j = 0; j < _itemList.Count; j++) { + for (var j = 0; j < contents.Count; j++) + { + var index = IsRightAlign ? contents.Count - 1 - j : j; - var index = IsRightAlign ? _itemList.Count - 1 - j : j; + var rowChild = contents[index]; - var rowChild = _itemList[index]; - - var rowChildWidth = LayoutUtility.GetPreferredSize(rowChild, 0) ; + var rowChildWidth = LayoutUtility.GetPreferredSize(rowChild, 0); var rowChildHeight = LayoutUtility.GetPreferredSize(rowChild, 1) + extraHeight; - if (ChildForceExpandWidth) { + if (ChildForceExpandWidth) + { rowChildWidth = colWidth; } @@ -377,25 +418,32 @@ namespace UnityEngine.UI.Extensions var xPos = xOffset; - if (IsCenterAlign) { + if (IsCenterAlign) + { xPos += (colWidth - rowChildWidth) * 0.5f; - } else if (IsRightAlign) { + } + else if (IsRightAlign) + { xPos += (colWidth - rowChildWidth); } - // - if (ExpandHorizontalSpacing && j > 0) { + if (ExpandHorizontalSpacing && j > 0) + { yPos += extraSpacing; } - if (axis == 0) { - SetChildAlongAxis (rowChild, 0, xPos, rowChildWidth); - } else { - SetChildAlongAxis (rowChild, 1, yPos, rowChildHeight); + if (axis == 0) + { + SetChildAlongAxis(rowChild, 0, xPos, rowChildWidth); + } + else + { + SetChildAlongAxis(rowChild, 1, yPos, rowChildHeight); } // Don't do vertical spacing for the last one - if (j < _itemList.Count - 1) { + if (j < contents.Count - 1) + { yPos += rowChildHeight + SpacingY; } } @@ -404,9 +452,9 @@ namespace UnityEngine.UI.Extensions public float GetGreatestMinimumChildWidth() { var max = 0f; - for (var i = 0; i < rectChildren.Count; i++) { + for (var i = 0; i < rectChildren.Count; i++) + { var w = LayoutUtility.GetMinWidth(rectChildren[i]); - max = Mathf.Max(w, max); } return max; @@ -415,20 +463,18 @@ namespace UnityEngine.UI.Extensions public float GetGreatestMinimumChildHeigth() { var max = 0f; - for (var i = 0; i < rectChildren.Count; i++) { + for (var i = 0; i < rectChildren.Count; i++) + { var w = LayoutUtility.GetMinHeight(rectChildren[i]); - max = Mathf.Max(w, max); } return max; } - protected override void OnDisable() - { - m_Tracker.Clear(); - LayoutRebuilder.MarkLayoutForRebuild(rectTransform); - } - - - } + protected override void OnDisable() + { + m_Tracker.Clear(); + LayoutRebuilder.MarkLayoutForRebuild(rectTransform); + } + } } \ No newline at end of file diff --git a/Runtime/Scripts/Layout/HorizontalScrollSnap.cs b/Runtime/Scripts/Layout/HorizontalScrollSnap.cs index 9fc2a4c..846d2a3 100644 --- a/Runtime/Scripts/Layout/HorizontalScrollSnap.cs +++ b/Runtime/Scripts/Layout/HorizontalScrollSnap.cs @@ -328,6 +328,10 @@ namespace UnityEngine.UI.Extensions } } } + else if (distance == 0) + { + EndScreenChange(); + } } } } diff --git a/Runtime/Scripts/Layout/VerticalScrollSnap.cs b/Runtime/Scripts/Layout/VerticalScrollSnap.cs index 2b4fe70..8690856 100644 --- a/Runtime/Scripts/Layout/VerticalScrollSnap.cs +++ b/Runtime/Scripts/Layout/VerticalScrollSnap.cs @@ -321,6 +321,10 @@ namespace UnityEngine.UI.Extensions } } } + else if (distance == 0) + { + EndScreenChange(); + } } } } diff --git a/Runtime/Scripts/Primitives/UILineRenderer.cs b/Runtime/Scripts/Primitives/UILineRenderer.cs index d3b5d3d..019c3b6 100644 --- a/Runtime/Scripts/Primitives/UILineRenderer.cs +++ b/Runtime/Scripts/Primitives/UILineRenderer.cs @@ -296,8 +296,6 @@ namespace UnityEngine.UI.Extensions PopulateMesh (vh, pointsToDraw); } } - - } private UIVertex[] CreateLineCap(Vector2 start, Vector2 end, SegmentType type) @@ -419,7 +417,7 @@ namespace UnityEngine.UI.Extensions { return Segments[segmentIndex - 1][index - 1]; } - else if (Segments.Count > 0) + else if (Segments?.Count > 0) { var segmentIndexCount = 0; var indexCount = index; @@ -443,6 +441,29 @@ namespace UnityEngine.UI.Extensions } } + /// + /// Calculates the position of a point on the curve, given t (0-1), start point, control points and end point. + /// + /// Required Percentage between start and end point, in the range 0 to 1 + /// Required Starting point + /// Required Control point 1 + /// Required Control point 2 + /// Required End point + /// Vector2 position of point on curve at t percentage between p1 and p4 + public Vector2 CalculatePointOnCurve(float t, Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4) + { + var t2 = t * t; + var t3 = t2 * t; + + var x = p1.x + (-p1.x * 3 + t * (3 * p1.x - p1.x * t)) * t + (3 * p2.x + t * (-6 * p2.x + p2.x * 3 * t)) * t + + (p3.x * 3 - p3.x * 3 * t) * t2 + p4.x * t3; + + var y = p1.y + (-p1.y * 3 + t * (3 * p1.y - p1.y * t)) * t + (3 * p2.y + t * (-6 * p2.y + p2.y * 3 * t)) * t + + (p3.y * 3 - p3.y * 3 * t) * t2 + p4.y * t3; + + return new Vector2(x, y); + } + /// /// Get the Vector2 position of a line within a specific segment /// @@ -478,6 +499,10 @@ namespace UnityEngine.UI.Extensions { 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."); + } } } -} \ No newline at end of file +} diff --git a/Runtime/Scripts/Utilities/ResetSelectableHighlight.cs b/Runtime/Scripts/Utilities/ResetSelectableHighlight.cs index 19b9590..5f4c647 100644 --- a/Runtime/Scripts/Utilities/ResetSelectableHighlight.cs +++ b/Runtime/Scripts/Utilities/ResetSelectableHighlight.cs @@ -1,29 +1,24 @@ /// Credit SimonDarksideJ +using UnityEngine.EventSystems; + namespace UnityEngine.UI.Extensions { - /* - Handy Selectable script to un-highlight a selectable component in Unity (e.g. a Button) when the user moves away from it, EVEN IF the user has holding a button on it. - - Resolves the situation where Unity UI Components remain in a highlighted state even after the pointer has moved away (e.g. user holding a button, mouse, pointer down). - Now whenever the cursor leaves the component, it will force the UI component to revert to un-highlighted. - */ - - using UnityEngine; - using UnityEngine.EventSystems; - using UnityEngine.UI; - + /// + /// Handy Selectable script to un-highlight a selectable component in Unity (e.g. a Button) when the user moves away from it, EVEN IF the user has holding a button on it. + /// Resolves the situation where Unity UI Components remain in a highlighted state even after the pointer has moved away (e.g. user holding a button, mouse, pointer down). + /// Now whenever the cursor leaves the component, it will force the UI component to revert to un-highlighted. + /// [AddComponentMenu("UI/Extensions/ResetSelectableHighlight", 31)] [RequireComponent(typeof(Selectable))] public class ResetSelectableHighlight : MonoBehaviour, IPointerExitHandler { [SerializeField] - private Selectable attachedSelectable; + private Selectable attachedSelectable = null; - // Start is called before the first frame update - void Awake() + private void Awake() { - if (!attachedSelectable) + if (attachedSelectable == null || !attachedSelectable) { attachedSelectable = GetComponent(); } @@ -31,7 +26,12 @@ namespace UnityEngine.UI.Extensions public void OnPointerExit(PointerEventData eventData) { + if (!attachedSelectable.interactable) + { + return; + } + attachedSelectable.targetGraphic.CrossFadeColor(attachedSelectable.colors.normalColor, 0f, true, true); } } -} \ No newline at end of file +} diff --git a/Runtime/Scripts/Utilities/UILineConnector.cs b/Runtime/Scripts/Utilities/UILineConnector.cs index 487dec5..77a3fc9 100644 --- a/Runtime/Scripts/Utilities/UILineConnector.cs +++ b/Runtime/Scripts/Utilities/UILineConnector.cs @@ -40,6 +40,10 @@ namespace UnityEngine.UI.Extensions bool updateLine = false; for (int i = 0; i < transforms.Length; i++) { + if (transforms[i] == null) + { + continue; + } if (!updateLine && previousPositions[i] != transforms[i].position) { updateLine = true; @@ -60,6 +64,10 @@ namespace UnityEngine.UI.Extensions // First, convert the pivot to worldspace for (int i = 0; i < transforms.Length; i++) { + if (transforms[i] == null) + { + continue; + } worldSpaces[i] = transforms[i].TransformPoint(thisPivot); } @@ -83,6 +91,10 @@ namespace UnityEngine.UI.Extensions previousPositions = new Vector3[transforms.Length]; for (int i = 0; i < transforms.Length; i++) { + if (transforms[i] == null) + { + continue; + } previousPositions[i] = transforms[i].position; } } diff --git a/package.json b/package.json index 1764052..deda485 100644 --- a/package.json +++ b/package.json @@ -1,35 +1,35 @@ -{ - "name": "com.unity.uiextensions", - "displayName": "Unity UI Extensions", - "version": "2.3.0", - "description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community", - "author": "Simon darkside Jackson <@SimonDarksideJ>", - "contributors": [ - { - "name": "SimonDarksideJ", - "twitter": "@SimonDarksideJ" - } - ], - "unity": "2020.3", - "repository": { - "type": "git", - "url": "git+https://github.com/Unity-UI-Extensions/com.unity.uiextensions.git" - }, - "bugs": { - "url": "https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues" - }, - "keywords": [ - "Unity3D", - "Unity", - "Unity UI", - "UI Extensions" - ], - "samples": [ - { - "displayName": "UI Extensions Samples", - "description": "Examples and demonstrations of the Unity UI Extensions controls", - "path": "Examples~" - } - ], - "license": "BSD3" -} +{ + "name": "com.unity.uiextensions", + "displayName": "Unity UI Extensions", + "version": "2.3.2-pre.3", + "description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community", + "author": "Simon darkside Jackson <@SimonDarksideJ>", + "contributors": [ + { + "name": "SimonDarksideJ", + "twitter": "@SimonDarksideJ" + } + ], + "unity": "2020.3", + "repository": { + "type": "git", + "url": "git+https://github.com/Unity-UI-Extensions/com.unity.uiextensions.git" + }, + "bugs": { + "url": "https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues" + }, + "keywords": [ + "Unity3D", + "Unity", + "Unity UI", + "UI Extensions" + ], + "samples": [ + { + "displayName": "UI Extensions Samples", + "description": "Examples and demonstrations of the Unity UI Extensions controls", + "path": "Examples~" + } + ], + "license": "BSD3" +}