1
1
using System . IO ;
2
+ using System . Linq ;
2
3
using UnityEditor ;
3
4
using UnityEditor . Compilation ;
4
5
using UnityEngine ;
5
6
6
7
/// <summary>
7
8
/// Checks for EDM4U assemblies and installs the package from its github releases
8
9
/// </summary>
9
- public sealed class InstallEdm4uStep : OneSignalSetupStep
10
+ public sealed class InstallEdm4uStep : OneSignalSetupStep
10
11
{
11
12
public override string Summary
12
13
=> $ "Install EDM4U { _edm4UVersion } ";
13
14
14
15
public override string Details
15
16
=> $ "Downloads and imports version { _edm4UVersion } from Google's repo. This library resolves dependencies " +
16
- $ "among included libraries on Android.";
17
+ #if UNITY_2021_1_OR_NEWER
18
+ "among included libraries on Android.\n \n <b>NOTE</b>: In Unity 2021+ the " +
19
+ $ "Google.IOSResolver_v{ _edm4UVersion } .dll will be renamed to Google.IOSResolver.dll in order to resolve a bug.";
20
+ #else
21
+ "among included libraries on Android." ;
22
+ #endif
17
23
18
- public override bool IsRequired
24
+ public override bool IsRequired
19
25
=> true;
20
26
21
27
protected override bool _getIsStepCompleted ( )
22
- {
23
- var precompiledAssemblies = CompilationPipeline . GetPrecompiledAssemblyNames ( ) ;
24
- foreach ( var assemblyName in precompiledAssemblies )
25
- {
26
- if ( assemblyName . StartsWith ( "Google.VersionHandler" ) )
27
- return true ;
28
- }
29
-
30
- return false ;
31
- }
28
+ => CompilationPipeline . GetPrecompiledAssemblyNames ( )
29
+ . Any ( assemblyName => assemblyName . StartsWith ( "Google.VersionHandler" ) ) ;
32
30
33
- protected override void _runStep ( )
31
+ protected override void _runStep ( )
34
32
{
35
33
var request = EditorWebRequest . Get ( _edm4UPackageDownloadUrl ) ;
36
34
request . AddEditorProgressDialog ( "Downloading Google External Dependency Manager" ) ;
37
- request . Send ( unityRequest =>
35
+ request . Send ( unityRequest =>
38
36
{
39
- if ( unityRequest . error != null )
37
+ if ( unityRequest . error != null )
40
38
{
41
39
EditorUtility . DisplayDialog ( "Package Download failed." , unityRequest . error , "Ok" ) ;
42
40
return ;
@@ -47,13 +45,35 @@ protected override void _runStep()
47
45
var tmpPackageFile = projectPath + FileUtil . GetUniqueTempPathInProject ( ) + ".unityPackage" ;
48
46
49
47
File . WriteAllBytes ( tmpPackageFile , unityRequest . downloadHandler . data ) ;
50
-
51
48
AssetDatabase . ImportPackage ( tmpPackageFile , false ) ;
49
+
50
+ #if UNITY_2021_1_OR_NEWER
51
+ SessionState . SetBool ( _shouldFix2021Bug , true ) ;
52
+ #endif
53
+
52
54
_shouldCheckForCompletion = true ;
53
55
} ) ;
54
56
}
57
+
58
+ [ InitializeOnLoadMethod ]
59
+ public static void _fixUnity2021Bug ( )
60
+ {
61
+ if ( ! SessionState . GetBool ( _shouldFix2021Bug , false ) )
62
+ return ;
63
+
64
+ SessionState . EraseBool ( _shouldFix2021Bug ) ;
65
+
66
+ EditorApplication . delayCall += ( ) => {
67
+ File . Move ( _iosDLLSourcePath , _iosDLLDestPath ) ;
68
+ File . Move ( _iosDLLSourcePath + ".meta" , _iosDLLDestPath + ".meta" ) ;
69
+ } ;
70
+ }
55
71
56
72
private const string _edm4UVersion = "1.2.165" ;
73
+ private const string _shouldFix2021Bug = "onesignal.installedm4u.shouldfix2021bug" ;
74
+ private const string _iosDLLDestPath = "Assets/ExternalDependencyManager/Editor/Google.IOSResolver.dll" ;
75
+ private static readonly string _iosDLLSourcePath = $ "Assets/ExternalDependencyManager/Editor/Google.IOSResolver_v{ _edm4UVersion } .dll";
57
76
58
- static readonly string _edm4UPackageDownloadUrl = $ "https://github.com/googlesamples/unity-jar-resolver/blob/v{ _edm4UVersion } /external-dependency-manager-{ _edm4UVersion } .unitypackage?raw=true";
77
+ static readonly string _edm4UPackageDownloadUrl
78
+ = $ "https://github.com/googlesamples/unity-jar-resolver/blob/v{ _edm4UVersion } /external-dependency-manager-{ _edm4UVersion } .unitypackage?raw=true";
59
79
}
0 commit comments