diff --git a/Editor/CompileCesiumForUnityNative.cs b/Editor/CompileCesiumForUnityNative.cs index 1b8657ab..99d5d7b2 100644 --- a/Editor/CompileCesiumForUnityNative.cs +++ b/Editor/CompileCesiumForUnityNative.cs @@ -8,6 +8,7 @@ using System.Text; using System; using System.Collections.Generic; +using System.Linq; #if UNITY_ANDROID using UnityEditor.Android; #endif @@ -120,6 +121,8 @@ private static string GetSharedLibraryFilename(string baseName, BuildTarget targ return $"{baseName}.dll"; case BuildTarget.iOS: return $"lib{baseName}.a"; + case BuildTarget.VisionOS: + return $"lib{baseName}.a"; case BuildTarget.StandaloneOSX: return $"lib{baseName}.dylib"; default: @@ -168,6 +171,31 @@ private static void ConfigurePlugin(LibraryToBuild library, PluginImporter impor UnityEngine.Debug.LogAssertion("Unsupported processor: " + library.Cpu); importer.SetPlatformData(library.Platform, "CPU", wsaPlatform); } + else if (library.Platform == BuildTarget.VisionOS) + { + importer.SetPlatformData(library.Platform, "CPU", "ARM64"); + + // TODO: WARN: this will likely cause issues, why native build generates those libs? Where are they needed? + var duplicatedSymbolsExcludeLibs = new string[] { + "libjpeg.a", + "libwebp.a" + }; + + var projectPath = Application.dataPath.Replace("Assets", ""); + foreach (var libFilePath in Directory.EnumerateFiles(library.InstallDirectory, "*.a", SearchOption.AllDirectories)) + { + if(duplicatedSymbolsExcludeLibs.Any(l => libFilePath.EndsWith(l))) + continue; + + var libRelativeFilePath = libFilePath.Replace(projectPath, ""); + var libPluginImporter = AssetImporter.GetAtPath(libRelativeFilePath) as PluginImporter; + + if (libPluginImporter != null) + { + libPluginImporter.SetPlatformData(library.Platform, "CPU", "ARM64"); + } + } + } } private static void OnPostprocessAllAssets( @@ -349,7 +377,7 @@ public static LibraryToBuild GetLibraryToBuild(PlatformToBuild platform, Library library.ExtraConfigureArgs.Add("-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a"); } - if (platform.platformGroup == BuildTargetGroup.iOS) + if (platform.platformGroup == BuildTargetGroup.iOS || platform.platformGroup == BuildTargetGroup.VisionOS) { library.Toolchain = "extern/ios-toolchain.cmake"; library.ExtraConfigureArgs.Add("-GXcode"); @@ -407,6 +435,11 @@ private static bool IsIOS(BuildTargetGroup platformGroup, BuildTarget platform) { return platformGroup == BuildTargetGroup.iOS && platform == BuildTarget.iOS; } + + private static bool IsVisionOS(BuildTargetGroup platformGroup, BuildTarget platform) + { + return platformGroup == BuildTargetGroup.VisionOS && platform == BuildTarget.VisionOS; + } private static string GetDirectoryNameForPlatform(PlatformToBuild platform) { @@ -419,6 +452,8 @@ private static string GetDirectoryNameForPlatform(BuildTargetGroup platformGroup return "Editor"; else if (IsIOS(platformGroup, platform)) return "iOS"; + else if (IsVisionOS(platformGroup, platform)) + return "VisionOS"; // Make sure we use "WSA" and not "Metro" else if (platformGroup == BuildTargetGroup.WSA) return "WSA"; @@ -450,7 +485,7 @@ internal static void BuildNativeLibrary(LibraryToBuild library) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.UseShellExecute = false; - if (library.Platform == BuildTarget.StandaloneOSX || library.Platform == BuildTarget.iOS) + if (library.Platform == BuildTarget.StandaloneOSX || library.Platform == BuildTarget.iOS || library.Platform == BuildTarget.VisionOS) { startInfo.FileName = File.Exists("/Applications/CMake.app/Contents/bin/cmake") ? "/Applications/CMake.app/Contents/bin/cmake" : "cmake"; } @@ -483,7 +518,22 @@ internal static void BuildNativeLibrary(LibraryToBuild library) startInfo.Arguments = string.Join(' ', args); RunAndLog(startInfo, log, logFilename); - + + if (IsVisionOS(library.PlatformGroup, library.Platform)) + { + var xcodeProjectPath = Path.Combine(library.BuildDirectory, "CesiumForUnityNative.xcodeproj/project.pbxproj"); + if (File.Exists(xcodeProjectPath)) + { + var originalXcodeContents = File.ReadAllText(xcodeProjectPath); + var xcodeContentsTargetedToXros = originalXcodeContents.Replace("SDKROOT = iphoneos;", "SDKROOT = xros;"); + File.WriteAllText(xcodeProjectPath, xcodeContentsTargetedToXros); + } + else + { + UnityEngine.Debug.Log("Xcode project does not exist, unable to change target to VisionOs"); + } + } + args = new List() { "--build", @@ -499,7 +549,7 @@ internal static void BuildNativeLibrary(LibraryToBuild library) startInfo.Arguments = string.Join(' ', args); RunAndLog(startInfo, log, logFilename); - if (library.Platform == BuildTarget.iOS) + if (library.Platform == BuildTarget.iOS || library.Platform == BuildTarget.VisionOS) AssetDatabase.Refresh(); } } diff --git a/Editor/ConfigureReinterop.cs b/Editor/ConfigureReinterop.cs index 5f5fc3a0..edc012ac 100644 --- a/Editor/ConfigureReinterop.cs +++ b/Editor/ConfigureReinterop.cs @@ -22,6 +22,8 @@ internal partial class ConfigureReinterop public const string CppOutputPath = "../native~/Editor/generated-Android"; #elif UNITY_IOS public const string CppOutputPath = "../native~/Editor/generated-iOS"; +#elif UNITY_VISIONOS + public const string CppOutputPath = "../native~/Editor/generated-VisionOS"; #elif UNITY_WSA public const string CppOutputPath = "../native~/Runtime/generated-WSA"; #elif UNITY_64 @@ -37,7 +39,7 @@ internal partial class ConfigureReinterop // The name of the DLL or SO containing the C++ code. public const string NativeLibraryName = "CesiumForUnityNative-Editor"; - + // Comma-separated types to treat as non-blittable, even if their fields would // otherwise cause Reinterop to treat them as blittable. public const string NonBlittableTypes = "Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle,Unity.Collections.NativeArray,UnityEngine.MeshData,UnityEngine.MeshDataArray"; diff --git a/Runtime/ConfigureReinterop.cs b/Runtime/ConfigureReinterop.cs index c674fbc0..95657603 100644 --- a/Runtime/ConfigureReinterop.cs +++ b/Runtime/ConfigureReinterop.cs @@ -31,6 +31,8 @@ internal partial class ConfigureReinterop public const string CppOutputPath = "../native~/Runtime/generated-Android"; #elif UNITY_IOS public const string CppOutputPath = "../native~/Runtime/generated-iOS"; +#elif UNITY_VISIONOS + public const string CppOutputPath = "../native~/Runtime/generated-VisionOS"; #elif UNITY_WSA public const string CppOutputPath = "../native~/Runtime/generated-WSA"; #elif UNITY_64 @@ -45,7 +47,7 @@ internal partial class ConfigureReinterop public const string BaseNamespace = "DotNet"; // The name of the DLL or SO containing the C++ code. -#if UNITY_IOS && !UNITY_EDITOR +#if (UNITY_IOS || UNITY_VISIONOS) && !UNITY_EDITOR public const string NativeLibraryName = "__Internal"; #else public const string NativeLibraryName = "CesiumForUnityNative-Runtime"; @@ -336,7 +338,7 @@ public void ExposeToCPP() CesiumWebMapTileServiceRasterOverlay webMapTileServiceRasterOverlay = go.GetComponent(); - webMapTileServiceRasterOverlay.baseUrl = webMapTileServiceRasterOverlay.baseUrl; + webMapTileServiceRasterOverlay.baseUrl = webMapTileServiceRasterOverlay.baseUrl; webMapTileServiceRasterOverlay.layer = webMapTileServiceRasterOverlay.layer; webMapTileServiceRasterOverlay.style = webMapTileServiceRasterOverlay.style; webMapTileServiceRasterOverlay.format = webMapTileServiceRasterOverlay.format;