Skip to content

Commit e044726

Browse files
Merge branch 'release-2.1.8' into stable
2 parents 038a6b4 + 3472436 commit e044726

File tree

357 files changed

+10142
-24397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

357 files changed

+10142
-24397
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
# Visual Studio cache directory
3030
.vs/
3131

32+
#Rider cache directory
33+
.idea/
34+
3235
# Gradle cache directory
3336
.gradle/
3437

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eos-sdk.aar filter=lfs diff=lfs merge=lfs -text

Assets/Plugins/Android/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
EOS.meta
2+
EOS/*

Assets/Plugins/Android/AndroidFileIOHelper.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ public static string ReadAllText(string filePath)
1515
//Wait till webRequest completed
1616
while (!request.isDone) { }
1717

18+
#if UNITY_2020_1_OR_NEWER
1819
if (request.result != UnityEngine.Networking.UnityWebRequest.Result.Success)
1920
{
2021
Debug.Log("Requesting " + filePath + ", please make sure it exists and is a valid config");
2122
throw new Exception("UnityWebRequest didn't succeed, Result : " + request.result);
2223
}
23-
24+
#else
25+
if (request.isNetworkError || request.isHttpError)
26+
{
27+
Debug.Log("Requesting " + filePath + ", please make sure it exists and is a valid config");
28+
throw new Exception("UnityWebRequest didn't succeed : Network or HTTP Error");
29+
}
30+
#endif
2431
return request.downloadHandler.text;
2532
}
2633
}

Assets/Plugins/AndroidEditor/Editor/EOSOnPreprocessBuild_android.cs renamed to Assets/Plugins/Android/Editor/EOSOnPreprocessBuild_android.cs

Lines changed: 152 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
using UnityEditor;
2424
using UnityEditor.Build;
2525
using UnityEditor.Build.Reporting;
26+
using UnityEditor.Android;
2627
using UnityEngine;
2728
using System.IO;
2829
using System.Linq;
2930
using PlayEveryWare.EpicOnlineServices;
3031
using System.Collections.Generic;
32+
using System.Text.RegularExpressions;
3133

34+
#if UNITY_ANDROID
3235
public class EOSOnPreprocessBuild_android : IPreprocessBuildWithReport
3336
{
3437
public int callbackOrder { get { return 3; } }
@@ -40,19 +43,13 @@ private static string GetAndroidEOSValuesConfigPath()
4043
return Path.Combine(assetsPathname, "eos_dependencies.androidlib/res/values/eos_values.xml");
4144
}
4245

43-
//-------------------------------------------------------------------------
44-
private static string GetPackageName()
45-
{
46-
return "com.playeveryware.eos";
47-
}
48-
49-
5046
//-------------------------------------------------------------------------
5147
public void OnPreprocessBuild(BuildReport report)
5248
{
5349
if (report.summary.platform == BuildTarget.Android)
5450
{
5551
InstallEOSDependentLibrary();
52+
ConfigureGradleTemplateProperties();
5653
ConfigureEOSDependentLibrary();
5754
}
5855
}
@@ -101,8 +98,8 @@ static private void InstallFiles(string[] filenames, string pathToInstallFrom,
10198
//-------------------------------------------------------------------------
10299
private string GetPlatformSpecificAssetsPath(string subpath)
103100
{
104-
string packagePathname = Path.GetFullPath("Packages/" + GetPackageName() + "/PlatformSpecificAssets~/" + subpath);
105-
string streamingAssetsSamplesPathname = Path.Combine(Application.dataPath, "../PlatformSpecificAssets/" + subpath);
101+
string packagePathname = Path.GetFullPath(Path.Combine("Packages", EOSPackageInfo.GetPackageName(), "PlatformSpecificAssets~", subpath));
102+
string streamingAssetsSamplesPathname = Path.Combine(Application.dataPath, "..", "PlatformSpecificAssets", subpath);
106103
string pathToInstallFrom = "";
107104

108105
if (Directory.Exists(packagePathname))
@@ -114,6 +111,10 @@ private string GetPlatformSpecificAssetsPath(string subpath)
114111
{
115112
pathToInstallFrom = streamingAssetsSamplesPathname;
116113
}
114+
else
115+
{
116+
Debug.LogError("PreprocessBuildError : EOS Plugin Package Missing");
117+
}
117118
return pathToInstallFrom;
118119
}
119120

@@ -131,6 +132,23 @@ bool DoesGradlePropertiesContainSetting(string gradleTemplatePathname, string se
131132
return false;
132133
}
133134

135+
//-------------------------------------------------------------------------
136+
void DisableGradleProperty(string gradleTemplatePathname, string setting)
137+
{
138+
var gradleTemplateToWrite = new List<string>();
139+
140+
foreach (string line in File.ReadAllLines(gradleTemplatePathname))
141+
{
142+
if (line.Contains(setting) && !line.StartsWith("#"))
143+
{
144+
}
145+
else
146+
{
147+
gradleTemplateToWrite.Add(line);
148+
}
149+
}
150+
File.WriteAllLines(gradleTemplatePathname, gradleTemplateToWrite.ToArray());
151+
}
134152
//-------------------------------------------------------------------------
135153
void ReplaceOrSetGradleProperty(string gradleTemplatePathname, string setting, string value)
136154
{
@@ -157,47 +175,152 @@ void ReplaceOrSetGradleProperty(string gradleTemplatePathname, string setting, s
157175
File.WriteAllLines(gradleTemplatePathname, gradleTemplateToWrite.ToArray());
158176
}
159177

178+
//-------------------------------------------------------------------------
179+
int GetTargetAPI()
180+
{
181+
var playerApiTarget = PlayerSettings.Android.targetSdkVersion;
182+
if (playerApiTarget == AndroidSdkVersions.AndroidApiLevelAuto)
183+
{
184+
int maxVersion = 0;
185+
var apiRegex = new Regex(@"android-(\d+)");
186+
//find max installed android api
187+
foreach (var dir in Directory.GetDirectories(Path.Combine(AndroidExternalToolsSettings.sdkRootPath, "platforms")))
188+
{
189+
var dirName = Path.GetFileName(dir);
190+
var match = apiRegex.Match(dirName);
191+
if (match.Success && match.Groups.Count == 2)
192+
{
193+
if (int.TryParse(match.Groups[1].Value, out int matchVal))
194+
{
195+
if (matchVal > maxVersion)
196+
{
197+
maxVersion = matchVal;
198+
}
199+
}
200+
}
201+
}
202+
if (maxVersion == 0)
203+
{
204+
return 29;
205+
}
206+
return maxVersion;
207+
}
208+
else
209+
{
210+
return (int)playerApiTarget;
211+
}
212+
}
213+
214+
//-------------------------------------------------------------------------
215+
string GetBuildTools()
216+
{
217+
var toolsRegex = new Regex(@"(\d+)\.(\d+)\.(\d+)");
218+
int maxMajor = 0, maxMinor = 0, maxPatch = 0;
219+
//find highest usable build tools version
220+
#if UNITY_2022_2_OR_NEWER
221+
const int highestVersion = 32;
222+
#else
223+
const int highestVersion = 30;
224+
#endif
225+
foreach (var dir in Directory.GetDirectories(Path.Combine(AndroidExternalToolsSettings.sdkRootPath, "build-tools")))
226+
{
227+
var dirName = Path.GetFileName(dir);
228+
var match = toolsRegex.Match(dirName);
229+
int majorVersion = 0, minorVersion = 0, patchVersion = 0;
230+
bool success = match.Success && match.Groups.Count == 4 &&
231+
int.TryParse(match.Groups[1].Value, out majorVersion) &&
232+
int.TryParse(match.Groups[2].Value, out minorVersion) &&
233+
int.TryParse(match.Groups[3].Value, out patchVersion);
234+
if (success)
235+
{
236+
if (majorVersion > highestVersion)
237+
{
238+
continue;
239+
}
240+
if (majorVersion > maxMajor ||
241+
(majorVersion == maxMajor && minorVersion > maxMinor) ||
242+
(majorVersion == maxMajor && minorVersion == maxMinor && patchVersion > maxPatch))
243+
{
244+
maxMajor = majorVersion;
245+
maxMinor = minorVersion;
246+
maxPatch = patchVersion;
247+
}
248+
}
249+
}
250+
if (maxMajor == 0)
251+
{
252+
return "30.0.3";
253+
}
254+
else
255+
{
256+
return $"{maxMajor}.{maxMinor}.{maxPatch}";
257+
}
258+
}
259+
//-------------------------------------------------------------------------
260+
void WriteConfigMacros(string filepath)
261+
{
262+
var contents = File.ReadAllText(filepath);
263+
string apiVersion = GetTargetAPI().ToString();
264+
string buildTools = GetBuildTools();
265+
string newContents = contents.Replace("**APIVERSION**", apiVersion).Replace("**TARGETSDKVERSION**", apiVersion).Replace("**BUILDTOOLS**", buildTools);
266+
File.WriteAllText(filepath, newContents);
267+
}
268+
160269
//-------------------------------------------------------------------------
161270
public void InstallEOSDependentLibrary()
162271
{
163272
string packagedPathname = GetPlatformSpecificAssetsPath("EOS/Android/");
164273

165274
if (Directory.Exists(packagedPathname))
166275
{
167-
string assetsPathname = Path.Combine(Application.dataPath, "Plugins/Android/EOS/");
276+
string assetsPathname = Path.Combine(Application.dataPath, "Plugins", "Android", "EOS");
277+
string buildGradlePath = "eos_dependencies.androidlib/build.gradle";
168278
string[] filenames =
169279
{
170280
"eos_dependencies.androidlib/AndroidManifest.xml",
171-
"eos_dependencies.androidlib/build.gradle",
281+
buildGradlePath,
172282
"eos_dependencies.androidlib/project.properties",
173283
"eos_dependencies.androidlib/res/values/eos_values.xml",
174284
"eos_dependencies.androidlib/res/values/styles.xml"
175285

176286
};
177287
InstallFiles(filenames, packagedPathname, assetsPathname);
178288

179-
// Unity has a fixed location for the gradleTemplate.properties file. (as of 2021)
180-
string gradleTemplatePathname = Path.Combine(Application.dataPath, "Plugins/Android/gradleTemplate.properties");
181-
if (File.Exists(gradleTemplatePathname))
182-
{
183-
if (!DoesGradlePropertiesContainSetting(gradleTemplatePathname, "android.useAndroidX=true"))
184-
{
185-
ReplaceOrSetGradleProperty(gradleTemplatePathname, "android.useAndroidX", "true");
186-
}
187-
}
188-
else
289+
WriteConfigMacros(Path.Combine(assetsPathname, buildGradlePath));
290+
}
291+
}
292+
//-------------------------------------------------------------------------
293+
public void ConfigureGradleTemplateProperties()
294+
{
295+
// Unity has a fixed location for the gradleTemplate.properties file. (as of 2021)
296+
string gradleTemplatePathname = Path.Combine(Application.dataPath, "Plugins", "Android", "gradleTemplate.properties");
297+
298+
// If the custom gradle template properties option is disabled, delete gradleTemplate.properties.DISABLED
299+
File.Delete(gradleTemplatePathname + ".DISABLED");
300+
301+
// Then create a copy of gradleTemplate.properties in the target folder
302+
// Once gradleTemplate.properties file exists, the custom gradle template properties option is automatically enabled
303+
if (File.Exists(gradleTemplatePathname))
304+
{
305+
if (!DoesGradlePropertiesContainSetting(gradleTemplatePathname, "android.useAndroidX=true"))
189306
{
190-
// Use one we have bundled
191-
string bundledGradleTemplatePathname = GetPlatformSpecificAssetsPath("EOS/Android/gradleTemplate.properties");
192-
File.Copy(bundledGradleTemplatePathname, gradleTemplatePathname);
307+
ReplaceOrSetGradleProperty(gradleTemplatePathname, "android.useAndroidX", "true");
193308
}
194309
}
310+
else
311+
{
312+
// Use one we have bundled
313+
string bundledGradleTemplatePathname = Path.Combine(GetPlatformSpecificAssetsPath("EOS/Android/"), "gradleTemplate.properties");
314+
File.Copy(bundledGradleTemplatePathname, gradleTemplatePathname);
315+
}
316+
#if UNITY_2022_2_OR_NEWER
317+
DisableGradleProperty(gradleTemplatePathname, "android.enableR8");
318+
#endif
195319
}
196-
197320
//-------------------------------------------------------------------------
198321
public void ConfigureEOSDependentLibrary()
199322
{
200-
string configFilePath = Path.Combine(Application.streamingAssetsPath, "EOS", EOSManager.ConfigFileName);
323+
string configFilePath = Path.Combine(Application.streamingAssetsPath, "EOS", EOSPackageInfo.ConfigFileName);
201324
var eosConfigFile = new EOSConfigFile<EOSConfig>(configFilePath);
202325
eosConfigFile.LoadConfigFromDisk();
203326
string clientIDAsLower = eosConfigFile.currentEOSConfig.clientID.ToLower();
@@ -211,7 +334,7 @@ public void ConfigureEOSDependentLibrary()
211334
if (node != null)
212335
{
213336
string eosProtocolScheme = node.InnerText;
214-
string storedClientID = eosProtocolScheme.Split(".").Last();
337+
string storedClientID = eosProtocolScheme.Split('.').Last();
215338

216339
if (storedClientID != clientIDAsLower)
217340
{
@@ -221,4 +344,5 @@ public void ConfigureEOSDependentLibrary()
221344
}
222345
}
223346

224-
}
347+
}
348+
#endif

Assets/Plugins/AndroidEditor/Editor/EOSOnPreprocessBuild_android.cs.meta renamed to Assets/Plugins/Android/Editor/EOSOnPreprocessBuild_android.cs.meta

File renamed without changes.

Assets/Plugins/AndroidEditor/Editor/PlatformSpecificConfigEditorAndroid.cs renamed to Assets/Plugins/Android/Editor/PlatformSpecificConfigEditorAndroid.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public void OnGUI()
6969
overrideValues = configFile.currentEOSConfig.overrideValues;
7070
}
7171

72-
EpicOnlineServicesConfigEditor.AssigningFlagTextField("Override Platform Flags (Seperated by '|')", 190, ref overrideValues.platformOptionsFlags);
72+
EpicOnlineServicesConfigEditor.AssigningFlagTextField("Override Platform Flags (Seperated by '|')", ref overrideValues.platformOptionsFlags, 250);
7373

74-
EpicOnlineServicesConfigEditor.AssigningFloatToStringField("Override initial button delay for overlay", 250, ref overrideValues.initialButtonDelayForOverlay);
74+
EpicOnlineServicesConfigEditor.AssigningFloatToStringField("Override initial button delay for overlay", ref overrideValues.initialButtonDelayForOverlay, 250);
7575

76-
EpicOnlineServicesConfigEditor.AssigningFloatToStringField("Override repeat button delay for overlay", 250, ref overrideValues.repeatButtonDelayForOverlay);
76+
EpicOnlineServicesConfigEditor.AssigningFloatToStringField("Override repeat button delay for overlay", ref overrideValues.repeatButtonDelayForOverlay, 250);
7777

7878
EpicOnlineServicesConfigEditor.AssigningULongToStringField("Thread Affinity: networkWork", ref overrideValues.ThreadAffinity_networkWork);
7979
EpicOnlineServicesConfigEditor.AssigningULongToStringField("Thread Affinity: storageIO", ref overrideValues.ThreadAffinity_storageIO);

Assets/Plugins/AndroidEditor/Editor/PlatformSpecificConfigEditorAndroid.cs.meta renamed to Assets/Plugins/Android/Editor/PlatformSpecificConfigEditorAndroid.cs.meta

File renamed without changes.

Assets/Plugins/AndroidEditor/Editor/com.playeveryware.eos-Editor.asmref renamed to Assets/Plugins/Android/Editor/com.playeveryware.eos-Editor.asmref

File renamed without changes.

Assets/Plugins/AndroidEditor/Editor/com.playeveryware.eos-Editor.asmref.meta renamed to Assets/Plugins/Android/Editor/com.playeveryware.eos-Editor.asmref.meta

File renamed without changes.

0 commit comments

Comments
 (0)