Skip to content

Commit 36599aa

Browse files
committed
Merge branch 'master' into 2022.1-urp
2 parents e6ae2ff + 30356de commit 36599aa

File tree

21 files changed

+756
-190
lines changed

21 files changed

+756
-190
lines changed

.github/workflows/release.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
TAG: ${{ steps.set_tag.outputs.VERSION }}
1616
BUILD_NAME: ${{ steps.set_build_name.outputs.VERSION }}
1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1919
with:
2020
fetch-depth: 0
2121
lfs: true
@@ -55,7 +55,7 @@ jobs:
5555

5656
- name: Version missmatch ❌
5757
if: ${{ !startsWith(needs.variables.outputs.TAG, needs.variables.outputs.UNITY_VERSION) }}
58-
uses: actions/github-script@v3
58+
uses: actions/github-script@v4
5959
with:
6060
script: |
6161
core.setFailed('Unity version does not match tag version')
@@ -69,7 +69,7 @@ jobs:
6969
strategy:
7070
fail-fast: false
7171
steps:
72-
- uses: actions/checkout@v3
72+
- uses: actions/checkout@v4
7373
with:
7474
fetch-depth: 0
7575
lfs: true
@@ -92,9 +92,11 @@ jobs:
9292
restore-keys: Library-201x-
9393

9494
- name: Build project
95-
uses: game-ci/unity-builder@v2
95+
uses: game-ci/unity-builder@v4
9696
env:
9797
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
98+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
99+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
98100
with:
99101
buildMethod: UnityBuilderAction.BuildScript.BuildWithCommandlineArgs
100102
customParameters: -tag ${{ needs.variables.outputs.TAG }}
@@ -136,7 +138,7 @@ jobs:
136138
runs-on: ubuntu-latest
137139
steps:
138140
- name: Checkout code
139-
uses: actions/checkout@v3
141+
uses: actions/checkout@v4
140142

141143
- uses: actions/download-artifact@v3
142144
with:

.github/workflows/upgrade-unity.yml

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ on:
66
workflow_dispatch:
77
inputs:
88
unityVersion:
9-
description: 'Unity Version'
9+
description: 'Unity version'
1010
required: true
1111
type: string
1212
createTags:
1313
description: 'Create Tags'
1414
required: false
1515
type: boolean
1616
default: true
17-
urp:
18-
description: 'URP branch'
19-
required: true
20-
type: boolean
21-
default: false
2217
tagsOnly:
2318
description: 'Only create tags'
2419
required: true
2520
type: boolean
2621
default: false
22+
mergeMaster:
23+
description: 'Merge master into branch'
24+
required: true
25+
type: boolean
26+
default: true
2727
customParameters:
2828
description: 'Custom cli arguments'
2929
required: false
@@ -39,24 +39,51 @@ jobs:
3939
steps:
4040
- name: Log input parameter
4141
run: |
42-
echo "Upgrading to Unity Version: $UNITY_VERSION"
42+
BRANCH_NAME=${GITHUB_REF#refs/heads/}
43+
44+
echo "Branch: $BRANCH_NAME"
45+
echo "Unity version: $UNITY_VERSION"
4346
echo "Create tags: $CREATE_TAGS"
44-
echo "URP branch: $URP_BRANCH"
47+
echo "Only create tags: $TAGS_ONLY"
48+
echo "Merge master into branch: $MERGE_MASTER"
4549
echo "Custom cli arguments: $CUSTOM_PARAMETERS"
50+
if [[ "$BRANCH_NAME" == *"urp"* ]]
51+
then
52+
echo "urp: true"
53+
else
54+
echo "urp: false"
55+
fi
4656
env:
4757
UNITY_VERSION: ${{ inputs.unityVersion }}
4858
CREATE_TAGS: ${{ inputs.createTags }}
49-
URP_BRANCH: ${{ inputs.urp }}
5059
TAGS_ONLY: ${{ inputs.tagsOnly }}
60+
MERGE_MASTER: ${{ inputs.mergeMaster }}
5161
CUSTOM_PARAMETERS: ${{ inputs.customParameters }}
5262

53-
- uses: actions/checkout@v3
63+
- uses: actions/checkout@v4
5464
with:
5565
fetch-depth: 0
5666
lfs: true
5767
# Makes sure, that pushing new tags will trigger workflows
5868
token: ${{ secrets.PR_GITHUB_TOKEN }}
5969

70+
- name: Set git user
71+
run: |
72+
git status
73+
git config --global user.email "$GIT_USER@users.noreply.github.com"
74+
git config --global user.name "$GIT_USER"
75+
env:
76+
GIT_USER: ${{ github.actor }}
77+
78+
# Make sure the branch has the latest master changes in
79+
- name: Merge master into current branch
80+
if: ${{ inputs.mergeMaster }}
81+
run: |
82+
git fetch origin master
83+
git merge FETCH_HEAD
84+
git push
85+
git log -1
86+
6087
# Unity 2020 cache is not compatible with older versions
6188
- name: Unity Library Cache 2020 or higher
6289
if: ${{ !startsWith(inputs.unityVersion, '201') }}
@@ -83,15 +110,15 @@ jobs:
83110
- name: Set upgrade name
84111
id: upgrade_name
85112
run: |
86-
if [[ "$URP_BRANCH" == "true" ]]
113+
BRANCH_NAME=${GITHUB_REF#refs/heads/}
114+
if [[ "$BRANCH_NAME" == *"urp"* ]]
87115
then
88116
echo "NAME=$UNITY_VERSION-urp" >> $GITHUB_OUTPUT
89117
else
90118
echo "NAME=$UNITY_VERSION" >> $GITHUB_OUTPUT
91119
fi
92120
env:
93121
UNITY_VERSION: ${{ inputs.unityVersion }}
94-
URP_BRANCH: ${{ inputs.urp }}
95122

96123
- name: Log variables
97124
run: |
@@ -100,29 +127,24 @@ jobs:
100127
101128
- name: Build project
102129
if: ${{ !inputs.tagsOnly }}
103-
uses: JohannesDeml/unity-builder@no-quit-parameter
130+
uses: game-ci/unity-builder@v4
104131
env:
105132
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
133+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
134+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
106135
with:
107136
buildMethod: UnityBuilderAction.UnityPackageScripts.UpgradeAllPackagesToVerifiedVersion
108137
customParameters: ${{ inputs.customParameters }}
109138
unityVersion: ${{ inputs.unityVersion }}
110139
targetPlatform: WebGL
111140
buildName: ${{ needs.variables.outputs.BUILD_NAME }}
112141
allowDirtyBuild: true
142+
manualExit: true
113143

114144
- name: Delete build folder with elevated rights
115145
if: ${{ !inputs.tagsOnly }}
116146
run: sudo rm -rf ./build
117147

118-
- name: Set git user
119-
run: |
120-
git status
121-
git config --global user.email "$GIT_USER@users.noreply.github.com"
122-
git config --global user.name "$GIT_USER"
123-
env:
124-
GIT_USER: ${{ github.actor }}
125-
126148
- name: Render template
127149
if: ${{ !inputs.tagsOnly }}
128150
id: template
@@ -146,22 +168,30 @@ jobs:
146168
- name: Add tags
147169
if: ${{ inputs.createTags || inputs.tagsOnly }}
148170
run: |
149-
if [[ "$URP_BRANCH" == "true" ]]
171+
# Extract the first four characters of UNITY_VERSION
172+
UNITY_YEAR=${UNITY_VERSION:0:4}
173+
BRANCH_NAME=${GITHUB_REF#refs/heads/}
174+
175+
TAG_PREFIX=$UNITY_VERSION
176+
if [[ "$BRANCH_NAME" == *"urp"* ]]
177+
then
178+
TAG_PREFIX=$UNITY_VERSION-urp
179+
fi
180+
181+
if [[ "$UNITY_YEAR" < "2023" ]]
150182
then
151-
git tag -a -f $UNITY_VERSION-urp-webgl1 -m "[Automated workflow] Created by upgrade-unity"
152-
git tag -a -f $UNITY_VERSION-urp-webgl2 -m "[Automated workflow] Created by upgrade-unity"
153-
git tag -a -f $UNITY_VERSION-urp-webgl2-debug -m "[Automated workflow] Created by upgrade-unity"
183+
git tag -a -f $TAG_PREFIX-minsize-webgl1 -m "[Automated workflow] Created by upgrade-unity"
184+
git tag -a -f $TAG_PREFIX-webgl1 -m "[Automated workflow] Created by upgrade-unity"
154185
else
155-
git tag -a -f $UNITY_VERSION-minsize-webgl1 -m "[Automated workflow] Created by upgrade-unity"
156-
git tag -a -f $UNITY_VERSION-webgl1 -m "[Automated workflow] Created by upgrade-unity"
157-
git tag -a -f $UNITY_VERSION-webgl2 -m "[Automated workflow] Created by upgrade-unity"
158-
# Push tags in between - pushing more than 3 tags won't trigger tag workflows
159-
git push origin -f --tags
160-
git tag -a -f $UNITY_VERSION-webgl2-debug -m "[Automated workflow] Created by upgrade-unity"
186+
git tag -a -f $TAG_PREFIX-minsize-webgl2 -m "[Automated workflow] Created by upgrade-unity"
161187
fi
188+
# Push tags in between - pushing more than 3 tags won't trigger tag workflows
189+
git push origin -f --tags
190+
191+
git tag -a -f $TAG_PREFIX-webgl2 -m "[Automated workflow] Created by upgrade-unity"
192+
git tag -a -f $TAG_PREFIX-webgl2-debug -m "[Automated workflow] Created by upgrade-unity"
162193
163194
git push origin -f --tags
164195
env:
165196
UNITY_VERSION: ${{ inputs.unityVersion }}
166-
URP_BRANCH: ${{ inputs.urp }}
167197

Assets/Plugins/WebGL/WebGLTools/WebGlBridge.Commands.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,27 @@ public void ToggleInfoPanel()
123123
}
124124

125125
/// <summary>
126-
/// Log example messages to see if they are rendered and colored correctly
126+
/// Log the user agent of the browser and if this agent is classified as mobile
127+
/// Browser Usage: <code>unityGame.SendMessage("WebGL", "LogUserAgent");</code>
128+
/// </summary>
129+
[WebGlCommand(Description = "Log User Agent and isMobileDevice")]
130+
public void LogUserAgent()
131+
{
132+
string userAgent = WebGlPlugins.GetUserAgent();
133+
bool isMobileDevice = WebGlPlugins.IsMobileDevice();
134+
Debug.Log($"<color=#4D65A4>User Agent:</color> '{userAgent}', <color=#4D65A4>IsMobileDevice:</color> '{isMobileDevice}'");
135+
}
136+
137+
/// <summary>
138+
/// Log example messages to show off unity rich text parsing to html & console styling
127139
/// </summary>
128140
[WebGlCommand(Description = "Log example messages for Log, warning and error")]
129141
[ContextMenu(nameof(LogExampleMessages))]
130142
public void LogExampleMessages()
131143
{
132-
Debug.Log("This is an example <color=#2596be>log</color> message, showing off <color=#ff00ff>rich text support with <color=#ff0000>[nesting (I should be red - not supported yet)]</color></color>!");
133-
Debug.LogWarning("This is an example <color=#e28743>warning</color> message!");
134-
Debug.LogError("This is an example <color=#d36a33>error</color> message!");
144+
Debug.Log("Example unity rich text example with <color=red>red and <color=blue>nested blue</color> color tags</color> and <b>bold</b> + <i>italic</i> tags, and <size=20>custom size with <b><i>bold italic nesting</i></b></size> tag.");
145+
Debug.LogWarning("This is an <b>example <color=#e28743>warning</color></b> message!");
146+
Debug.LogError("This is an <b>example <color=#b50808>error</color></b> message!");
135147
}
136148

137149
/// <summary>

Assets/Plugins/WebGL/WebGLTools/WebGlPlugins.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public static class WebGlPlugins
2929
[DllImport("__Internal")]
3030
private static extern void _HideInfoPanel();
3131
[DllImport("__Internal")]
32+
private static extern string _GetUserAgent();
33+
[DllImport("__Internal")]
3234
private static extern uint _GetTotalMemorySize();
3335
[DllImport("__Internal")]
3436
private static extern uint _GetStaticMemorySize();
@@ -51,7 +53,7 @@ public static void SetVariable(string variableName, string value)
5153
#endif
5254
Debug.Log($"<color=#00CCCC>{nameof(WebGlPlugins)}.{nameof(SetVariable)} set {variableName}: {value}</color>");
5355
}
54-
56+
5557
/// <summary>
5658
/// Adds a time marker at the call time to the javascript map "unityTimeTrackers"
5759
/// The mapped value is performance.now() at the time of the call
@@ -65,7 +67,7 @@ public static void AddTimeTrackingEvent(string eventName)
6567
Debug.Log($"{nameof(WebGlPlugins)}.{nameof(AddTimeTrackingEvent)} called with {eventName}");
6668
#endif
6769
}
68-
70+
6971
/// <summary>
7072
/// Show the info panel in the top right corner
7173
/// By default triggered by <see cref="WebGlTimeTracker"/> in Awake
@@ -80,7 +82,7 @@ public static void ShowInfoPanel()
8082
Debug.Log($"{nameof(WebGlPlugins)}.{nameof(ShowInfoPanel)} called");
8183
#endif
8284
}
83-
85+
8486
/// <summary>
8587
/// Hide the info panel in the top right corner
8688
/// By default triggered by <see cref="WebGlTimeTracker"/> in Awake
@@ -111,6 +113,33 @@ public static void ToggleInfoPanel()
111113
}
112114
}
113115

116+
/// <summary>
117+
/// Get navigator.userAgent from the browser
118+
/// </summary>
119+
/// <returns>navigator.userAgent</returns>
120+
public static string GetUserAgent()
121+
{
122+
#if UNITY_WEBGL && !UNITY_EDITOR
123+
return _GetUserAgent();
124+
#else
125+
Debug.Log($"{nameof(WebGlPlugins)}.{nameof(GetUserAgent)} called");
126+
return "undefined";
127+
#endif
128+
}
129+
130+
/// <summary>
131+
/// Check user agent to determine if the game runs on a mobile device
132+
/// </summary>
133+
/// <returns>true if on phone or tablet</returns>
134+
public static bool IsMobileDevice()
135+
{
136+
string userAgent = GetUserAgent();
137+
return userAgent.Contains("iPhone") ||
138+
userAgent.Contains("iPad") ||
139+
userAgent.Contains("iPod") ||
140+
userAgent.Contains("Android");
141+
}
142+
114143
/// <summary>
115144
/// Get the total memory size used by the application in MB
116145
/// </summary>
@@ -194,7 +223,7 @@ public static float GetManagedMemorySize()
194223
var bytes = (uint) GC.GetTotalMemory(false);
195224
return GetMegaBytes(bytes);
196225
}
197-
226+
198227
/// <summary>
199228
/// Converts bytes (B) to mega bytes (MB)
200229
/// </summary>

Assets/Plugins/WebGL/WebGLTools/WebGlPlugins.jslib

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,26 @@ var WebGlPlugins =
6060
setInfoPanelVisible(false);
6161
}
6262
},
63-
63+
64+
_GetUserAgent: function () {
65+
var userAgent = navigator.userAgent;
66+
67+
//Get size of the string
68+
var bufferSize = lengthBytesUTF8(userAgent) + 1;
69+
//Allocate memory space
70+
var buffer = _malloc(bufferSize);
71+
72+
//Copy old data to the new one then return it
73+
if(typeof stringToUTF8 !== 'undefined') {
74+
stringToUTF8(userAgent, buffer, bufferSize);
75+
}
76+
else if(typeof writeStringToMemory !== 'undefined') {
77+
writeStringToMemory(userAgent, buffer);
78+
}
79+
80+
return buffer;
81+
},
82+
6483
_GetTotalMemorySize: function()
6584
{
6685
if(typeof TOTAL_MEMORY !== 'undefined') {

0 commit comments

Comments
 (0)