Skip to content

Commit 4f7a007

Browse files
authored
Merge pull request #9494 from CDiaz-MS/leap_4.6.0
Leap Motion Unity Modules Support for version 4.6.0, 4.7.0 and 4.7.1
2 parents d029ca5 + b487729 commit 4f7a007

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

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

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,23 @@ static class LeapMotionConfigurationChecker
3030
private static bool isLeapRecognizedByMRTK = false;
3131

3232
// The current supported Leap Core Assets version numbers.
33-
private static string[] leapCoreAssetsVersionsSupported = new string[] { "4.5.0", "4.5.1" };
33+
private static string[] leapCoreAssetsVersionsSupported = new string[] { "4.5.0", "4.5.1", "4.6.0", "4.7.0", "4.7.1" };
3434

3535
// The current Leap Core Assets version in this project
3636
private static string currentLeapCoreAssetsVersion = "";
3737

3838
// The path difference between the root of assets and the root of the Leap Motion Core Assets.
3939
private static string pathDifference = "";
4040

41+
// The Leap Unity Modules version 4.7.1 already contains a LeapMotion.asmdef file at this path
42+
private static string leapAsmDefPath_471 = "LeapMotion/Core/Scripts/LeapMotion.asmdef";
43+
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_460 = "LeapMotion/Core/Scripts/XR/LeapXRPinchLocomotion.cs";
49+
4150
// Array of paths to Leap Motion testing directories that will be removed from the project.
4251
// Make sure each test directory ends with '/'
4352
// These paths only need to be deleted if the Leap Core Assets version is 4.4.0
@@ -123,6 +132,8 @@ private static void ConfigureLeapMotion(bool isLeapInProject)
123132

124133
if (isLeapCoreAssetsVersionSupported)
125134
{
135+
Debug.Log($"Integrating the Leap Motion Unity Modules Version {currentLeapCoreAssetsVersion} with MRTK");
136+
126137
RemoveTestingFolders();
127138
AddAndUpdateAsmDefs();
128139
AddLeapEditorAsmDefs();
@@ -158,6 +169,32 @@ private static bool LeapCoreAssetsVersionSupport()
158169
if (line.Contains(versionNumberSupported))
159170
{
160171
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 certain 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_460);
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+
161198
return true;
162199
}
163200
}
@@ -214,6 +251,12 @@ private static void AddAndUpdateAsmDefs()
214251
{
215252
string leapCoreAsmDefPath = Path.Combine(Application.dataPath, pathDifference, "LeapMotion", "LeapMotion.asmdef");
216253

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")
256+
{
257+
return;
258+
}
259+
217260
// If the asmdef has already been created then do not create another one
218261
if (!File.Exists(leapCoreAsmDefPath))
219262
{
@@ -229,9 +272,14 @@ private static void AddAndUpdateAsmDefs()
229272

230273
// An assembly definition was added to the Leap Core Assets in version 4.5.1
231274
// The LeapMotion.LeapCSharp assembly definition is added as a reference at the root of the Core Assets
232-
if (currentLeapCoreAssetsVersion == "4.5.1")
275+
if (currentLeapCoreAssetsVersion == "4.5.1" || currentLeapCoreAssetsVersion == "4.6.0" || currentLeapCoreAssetsVersion == "4.7.0")
233276
{
234277
leapAsmDef.AddReference("LeapMotion.LeapCSharp");
278+
279+
// If the unity modules version is 4.6.0 or 4.7.0 then add SpatialTracking as a reference
280+
#if UNITY_2019_3_OR_NEWER
281+
leapAsmDef.AddReference("UnityEngine.SpatialTracking");
282+
#endif
235283
}
236284

237285
leapAsmDef.Save(leapCoreAsmDefPath);
@@ -271,7 +319,7 @@ private static void AddLeapEditorAsmDefs()
271319
};
272320

273321
// Add the LeapMotion.LeapCSharp assembly definition to the leap motion tests assembly definition
274-
if (currentLeapCoreAssetsVersion == "4.5.1" && leapAsmDef.Key == "LeapMotion.Core.Tests.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"))
275323
{
276324
leapEditorAsmDef.AddReference("LeapMotion.LeapCSharp");
277325
}

0 commit comments

Comments
 (0)