Skip to content

Commit 5554b83

Browse files
committed
Update Unity Modules version inference
1 parent 3b76cce commit 5554b83

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

Assets/MRTK/Providers/LeapMotion/Editor/LeapMotionConfigurationChecker.cs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ static class LeapMotionConfigurationChecker
4141
// The Leap Unity Modules version 4.7.1 already contains a LeapMotion.asmdef file at this path
4242
private static string leapAsmDefPath_471 = "LeapMotion/Core/Scripts/LeapMotion.asmdef";
4343

44+
// This path is used to determine if the Leap Motion Unity Modules is version 4.7.0
45+
private static string leapTestsPath_470 = "LeapMotion/Core/Editor/Tests";
46+
47+
// This path is used to determine if the Leap Motion Unity Modules is version 4.6.0 or 4.5.1
48+
private static string leapXRPath_451 = "LeapMotion/Core/Scripts/XR/LeapXRPinchLocomotion.cs";
49+
4450
// Array of paths to Leap Motion testing directories that will be removed from the project.
4551
// Make sure each test directory ends with '/'
4652
// These paths only need to be deleted if the Leap Core Assets version is 4.4.0
@@ -126,6 +132,8 @@ private static void ConfigureLeapMotion(bool isLeapInProject)
126132

127133
if (isLeapCoreAssetsVersionSupported)
128134
{
135+
Debug.Log($"Integrating the Leap Motion Unity Modules Version {currentLeapCoreAssetsVersion} with MRTK");
136+
129137
RemoveTestingFolders();
130138
AddAndUpdateAsmDefs();
131139
AddLeapEditorAsmDefs();
@@ -161,6 +169,32 @@ private static bool LeapCoreAssetsVersionSupport()
161169
if (line.Contains(versionNumberSupported))
162170
{
163171
currentLeapCoreAssetsVersion = versionNumberSupported;
172+
173+
// The Leap Motion Unity modules Version.txt has remained 4.5.1 across versions 4.6.0, 4.7.0 and 4.7.1, check for the presence
174+
// of certian paths to infer the version number.
175+
176+
// This path is only present in 4.7.1
177+
string leap471Path = Path.Combine(Application.dataPath, pathDifference, leapAsmDefPath_471);
178+
179+
// This path is present in versions 4.7.0 and 4.7.1
180+
string testDirectoryPath = Path.Combine(Application.dataPath, pathDifference, leapTestsPath_470);
181+
182+
// This path is present in 4.6.0 and not 4.5.1
183+
string xrPath = Path.Combine(Application.dataPath, pathDifference, leapXRPath_451);
184+
185+
if (File.Exists(leap471Path))
186+
{
187+
currentLeapCoreAssetsVersion = "4.7.1";
188+
}
189+
else if (!File.Exists(leap471Path) && Directory.Exists(testDirectoryPath))
190+
{
191+
currentLeapCoreAssetsVersion = "4.7.0";
192+
}
193+
else if (!File.Exists(leap471Path) && !Directory.Exists(testDirectoryPath) && File.Exists(xrPath))
194+
{
195+
currentLeapCoreAssetsVersion = "4.6.0";
196+
}
197+
164198
return true;
165199
}
166200
}
@@ -217,14 +251,9 @@ private static void AddAndUpdateAsmDefs()
217251
{
218252
string leapCoreAsmDefPath = Path.Combine(Application.dataPath, pathDifference, "LeapMotion", "LeapMotion.asmdef");
219253

220-
// The Leap Unity Modules version is 4.7.1 already contains a LeapMotion.asmdef
221-
string leap471Path = Path.Combine(Application.dataPath, pathDifference, leapAsmDefPath_471);
222-
223-
// If the LeapMotion.asmdef is present, then the Leap Unity Modules version is 4.7.1 and the other
224-
// LeapMotion.asmdef file does not need to be created.
225-
if (File.Exists(leap471Path))
254+
// If the Leap Unity Modules version is 4.7.1, the LeapMotion.asmdef file does not need to be created
255+
if (currentLeapCoreAssetsVersion == "4.7.1")
226256
{
227-
currentLeapCoreAssetsVersion = "4.7.1";
228257
return;
229258
}
230259

@@ -243,7 +272,7 @@ private static void AddAndUpdateAsmDefs()
243272

244273
// An assembly definition was added to the Leap Core Assets in version 4.5.1
245274
// The LeapMotion.LeapCSharp assembly definition is added as a reference at the root of the Core Assets
246-
if (currentLeapCoreAssetsVersion == "4.5.1")
275+
if (currentLeapCoreAssetsVersion == "4.5.1" || currentLeapCoreAssetsVersion == "4.6.0" || currentLeapCoreAssetsVersion == "4.7.0")
247276
{
248277
leapAsmDef.AddReference("LeapMotion.LeapCSharp");
249278

@@ -290,7 +319,7 @@ private static void AddLeapEditorAsmDefs()
290319
};
291320

292321
// Add the LeapMotion.LeapCSharp assembly definition to the leap motion tests assembly definition
293-
if ((currentLeapCoreAssetsVersion == "4.5.1" || currentLeapCoreAssetsVersion == "4.7.1") && (leapAsmDef.Key == "LeapMotion.Core.Tests.Editor" || leapAsmDef.Key == "LeapMotion.Core.Editor"))
322+
if ((currentLeapCoreAssetsVersion == "4.5.1" || currentLeapCoreAssetsVersion == "4.6.0" || currentLeapCoreAssetsVersion == "4.7.0" || currentLeapCoreAssetsVersion == "4.7.1") && (leapAsmDef.Key == "LeapMotion.Core.Tests.Editor" || leapAsmDef.Key == "LeapMotion.Core.Editor"))
294323
{
295324
leapEditorAsmDef.AddReference("LeapMotion.LeapCSharp");
296325
}

0 commit comments

Comments
 (0)