private static void ConfigureOculusIntegration() { bool OculusIntegrationPresent = ReconcileOculusIntegrationDefine(); FileInfo[] oculusXRSDKAsmDefFile = FileUtilities.FindFilesInAssets("Microsoft.MixedReality.Toolkit.Providers.XRSDK.Oculus.asmdef"); FileInfo[] oculusXRSDKHandtrackingUtilsAsmDefFile = FileUtilities.FindFilesInAssets("Microsoft.MixedReality.Toolkit.XRSDK.Oculus.Handtracking.Utilities.asmdef"); FileInfo[] oculusXRSDKHandtrackingEditorAsmDefFile = FileUtilities.FindFilesInAssets("Microsoft.MixedReality.Toolkit.XRSDK.Oculus.Handtracking.Editor.asmdef"); List <FileInfo[]> oculusAsmDefFiles = new List <FileInfo[]>() { oculusXRSDKAsmDefFile, oculusXRSDKHandtrackingUtilsAsmDefFile, oculusXRSDKHandtrackingEditorAsmDefFile }; foreach (FileInfo[] oculusAsmDefFile in oculusAsmDefFiles) { // When MRTK is used through NuGet compiled assemblies, there will not be an asmdef file in the assets directory to configure. if (oculusAsmDefFile.Length == 0) { return; } AssemblyDefinition oculusAsmDef = AssemblyDefinition.Load(oculusAsmDefFile[0].FullName); List <string> references = oculusAsmDef.References.ToList(); if (!OculusIntegrationPresent) { Debug.Log("Oculus Integration package not detected, removing references from asmdefs"); if (references.Contains("Oculus.VR")) { references.Remove("Oculus.VR"); } if (references.Contains("Oculus.VR.Editor")) { references.Remove("Oculus.VR.Editor"); } oculusAsmDef.References = references.ToArray(); } else { if (oculusAsmDefFile == oculusXRSDKAsmDefFile || oculusAsmDefFile == oculusXRSDKHandtrackingUtilsAsmDefFile) { oculusAsmDef.AddReference("Oculus.VR"); } if (oculusAsmDefFile == oculusXRSDKHandtrackingEditorAsmDefFile) { oculusAsmDef.AddReference("Oculus.VR.Editor"); } } oculusAsmDef.Save(oculusAsmDefFile[0].FullName); } }
/// <summary> /// Adds an asmdef at the root of the LeapMotion Core Assets once they are imported into the project and adds the newly created LeapMotion.asmdef /// as a reference for the existing leap data provider asmdef. /// </summary> private static void AddAndUpdateAsmDefs() { string leapCoreAsmDefPath = Path.Combine(Application.dataPath, pathDifference, "LeapMotion", "LeapMotion.asmdef"); // If the asmdef has already been created then do not create another one if (!File.Exists(leapCoreAsmDefPath)) { // Create the asmdef that will be placed in the Leap Core Assets when they are imported // A new asmdef needs to be created in order to reference it in the MRTK/Providers/LeapMotion/Microsoft.MixedReality.Toolkit.Providers.LeapMotion.asmdef file AssemblyDefinition leapAsmDef = new AssemblyDefinition { Name = "LeapMotion", AllowUnsafeCode = true, References = new string[] { }, IncludePlatforms = new string[] { "Editor", "WindowsStandalone32", "WindowsStandalone64" } }; // An assembly definition was added to the Leap Core Assets in version 4.5.1 // The LeapMotion.LeapCSharp assembly definition is added as a reference at the root of the Core Assets if (currentLeapCoreAssetsVersion == "4.5.1") { leapAsmDef.AddReference("LeapMotion.LeapCSharp"); } leapAsmDef.Save(leapCoreAsmDefPath); } }
/// <summary> /// Adds an asmdef at the root of the LeapMotion Core Assets once they are imported into the project and adds the newly created LeapMotion.asmdef /// as a reference for the existing leap data provider asmdef. /// </summary> private static void AddAndUpdateAsmDefs() { // If the Leap Unity Modules version is 4.7.1 or newer, the LeapMotion.asmdef file does not need to be created // NB V5.0 - V5.2 are not supported by MRTK so are not expected here. if (currentLeapCoreAssetsVersion == "4.7.1" || currentLeapCoreAssetsVersion == "4.9.1" || currentLeapCoreAssetsVersion == "5.3.0") { return; } string leapCoreAsmDefPath = Path.Combine(Application.dataPath, pathDifference, "LeapMotion", "LeapMotion.asmdef"); // If the asmdef has already been created then do not create another one if (!File.Exists(leapCoreAsmDefPath)) { // Create the asmdef that will be placed in the Leap Core Assets when they are imported // A new asmdef needs to be created in order to reference it in the MRTK/Providers/LeapMotion/Microsoft.MixedReality.Toolkit.Providers.LeapMotion.asmdef file AssemblyDefinition leapAsmDef = new AssemblyDefinition { Name = "LeapMotion", AllowUnsafeCode = true, References = new string[] { }, IncludePlatforms = new string[] { "Editor", "WindowsStandalone32", "WindowsStandalone64" } }; // An assembly definition was added to the Leap Core Assets in version 4.5.1 // The LeapMotion.LeapCSharp assembly definition is added as a reference at the root of the Core Assets if (currentLeapCoreAssetsVersion == "4.5.1" || currentLeapCoreAssetsVersion == "4.6.0" || currentLeapCoreAssetsVersion == "4.7.0") { leapAsmDef.AddReference("LeapMotion.LeapCSharp"); // If the unity modules version is 4.6.0 or 4.7.0 then add SpatialTracking as a reference #if UNITY_2019_3_OR_NEWER leapAsmDef.AddReference("UnityEngine.SpatialTracking"); #endif } leapAsmDef.Save(leapCoreAsmDefPath); } }
/// <summary> /// Adds assembly definition files for the Unity Modules /// </summary> private static void AddLeapEditorAsmDefsForUnityModules() { if (FileUtilities.FindFilesInAssets("LeapMotion.Core.Editor.asmdef").Length == 0) { foreach (KeyValuePair <string, string[]> leapAsmDef in leapUnityModulesEditorDirectories) { // Convert asmdef name to a path string leapAsmDefPath = leapAsmDef.Key.Replace('.', '/'); string leapAsmDefFilename = string.Concat(leapAsmDef.Key, ".asmdef"); // Path for the asmdef including the filename string fullLeapAsmDefFilePath = Path.Combine(Application.dataPath, pathDifference, leapAsmDefPath, leapAsmDefFilename); // Path for the asmdef NOT including the filename string fullLeapAsmDefDirectoryPath = Path.Combine(Application.dataPath, pathDifference, leapAsmDefPath); // Make sure the directory exists within the leap core assets before we add the asmdef // The leap core assets version 4.5.0 contains the LeapMotion/Core/Tests/Editor directory while 4.4.0 does not. if (!File.Exists(fullLeapAsmDefFilePath) && Directory.Exists(fullLeapAsmDefDirectoryPath)) { // Create and save the new asmdef AssemblyDefinition leapEditorAsmDef = new AssemblyDefinition { Name = leapAsmDef.Key, References = leapAsmDef.Value, IncludePlatforms = new string[] { "Editor" } }; // Add the LeapMotion.LeapCSharp assembly definition to the leap motion tests assembly definition if ((currentLeapCoreAssetsVersion == "4.5.1" || currentLeapCoreAssetsVersion == "4.6.0" || currentLeapCoreAssetsVersion == "4.7.0" || currentLeapCoreAssetsVersion == "4.7.1" || currentLeapCoreAssetsVersion == "4.9.1") && (leapAsmDef.Key == "LeapMotion.Core.Tests.Editor" || leapAsmDef.Key == "LeapMotion.Core.Editor")) { leapEditorAsmDef.AddReference("LeapMotion.LeapCSharp"); } #if !UNITY_2019_3_OR_NEWER // In Unity 2018.4, directories that contain tests need to have a test assembly. // An asmdef is added to a leap directory that contains tests for the leap core assets 4.5.0. if (leapEditorAsmDef.Name.Contains("Tests")) { leapEditorAsmDef.OptionalUnityReferences = new string[] { "TestAssemblies" }; } #endif leapEditorAsmDef.Save(fullLeapAsmDefFilePath); } } } }