diff --git a/Source/Engine/Scripting/Runtime/DotNet.cpp b/Source/Engine/Scripting/Runtime/DotNet.cpp index 426fe3c28..0b5993477 100644 --- a/Source/Engine/Scripting/Runtime/DotNet.cpp +++ b/Source/Engine/Scripting/Runtime/DotNet.cpp @@ -281,17 +281,18 @@ bool MCore::LoadEngine() flaxLibraryPath = ::String(StringUtils::GetDirectoryName(Platform::GetExecutableFilePath())) / StringUtils::GetFileName(flaxLibraryPath); } #endif +#if !PLATFORM_SWITCH if (!FileSystem::FileExists(flaxLibraryPath)) { LOG(Error, "Flax Engine native library file is missing ({0})", flaxLibraryPath); } +#endif RegisterNativeLibrary("FlaxEngine", flaxLibraryPath.Get()); MRootDomain = New("Root"); MDomains.Add(MRootDomain); - void* GetRuntimeInformationPtr = GetStaticMethodPointer(TEXT("GetRuntimeInformation")); - char* buildInfo = CallStaticMethod(GetRuntimeInformationPtr); + char* buildInfo = CallStaticMethod(GetStaticMethodPointer(TEXT("GetRuntimeInformation"))); LOG(Info, ".NET runtime version: {0}", ::String(buildInfo)); MCore::GC::FreeMemory(buildInfo); @@ -2047,7 +2048,7 @@ bool InitHostfxr() #endif // Platform-specific setup -#if PLATFORM_IOS +#if PLATFORM_IOS || PLATFORM_SWITCH setenv("MONO_AOT_MODE", "aot", 1); setenv("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", 1); #endif diff --git a/Source/Engine/Scripting/Scripting.cs b/Source/Engine/Scripting/Scripting.cs index 188333ff1..516a85628 100644 --- a/Source/Engine/Scripting/Scripting.cs +++ b/Source/Engine/Scripting/Scripting.cs @@ -180,8 +180,8 @@ namespace FlaxEngine private static void OnLocalizationChanged() { - // iOS uses globalization-invariant mode so ignore it -#if !PLATFORM_IOS + // Invariant-globalization only (see InitHostfxr with Mono) +#if !(PLATFORM_IOS || PLATFORM_SWITCH) var currentThread = Thread.CurrentThread; var language = Localization.CurrentLanguage; if (language != null) @@ -238,6 +238,10 @@ namespace FlaxEngine internal static ManagedHandle CultureInfoToManaged(int lcid) { +#if PLATFORM_IOS || PLATFORM_SWITCH + // Invariant-globalization only (see InitHostfxr with Mono) + lcid = 0; +#endif return ManagedHandle.Alloc(new CultureInfo(lcid)); } diff --git a/Source/ThirdParty/nethost/nethost.Build.cs b/Source/ThirdParty/nethost/nethost.Build.cs index b6dfdb1fa..53d974b44 100644 --- a/Source/ThirdParty/nethost/nethost.Build.cs +++ b/Source/ThirdParty/nethost/nethost.Build.cs @@ -74,12 +74,24 @@ public class nethost : ThirdPartyModule case TargetPlatform.Switch: case TargetPlatform.PS4: case TargetPlatform.PS5: - options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libmonosgen-2.0.a")); - options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libSystem.Native.a")); - options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libSystem.IO.Ports.Native.a")); - options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libSystem.IO.Compression.Native.a")); - options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libSystem.Globalization.Native.a")); + { + var type = Flax.Build.Utilities.GetType($"Flax.Build.Platforms.{options.Platform.Target}.nethost"); + var onLink = type?.GetMethod("OnLink"); + if (onLink != null) + { + // Custom linking logic overriden by platform tools + onLink.Invoke(null, new object[] { options, hostRuntime.Path }); + } + else + { + options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libmonosgen-2.0.a")); + options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libSystem.Native.a")); + options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libSystem.IO.Ports.Native.a")); + options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libSystem.IO.Compression.Native.a")); + options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libSystem.Globalization.Native.a")); + } break; + } case TargetPlatform.Android: options.PublicDefinitions.Add("USE_MONO_DYNAMIC_LIB"); options.DependencyFiles.Add(Path.Combine(hostRuntime.Path, "libmonosgen-2.0.so")); diff --git a/Source/Tools/Flax.Build/Utilities/Utilities.cs b/Source/Tools/Flax.Build/Utilities/Utilities.cs index 02019b30d..0ae68ca93 100644 --- a/Source/Tools/Flax.Build/Utilities/Utilities.cs +++ b/Source/Tools/Flax.Build/Utilities/Utilities.cs @@ -352,6 +352,16 @@ namespace Flax.Build } } + /// + /// Calls within Flax.Build context - can be used by build scripts to properly find a type by name. + /// + /// The full name (namespace with class name). + /// Type or null if not found. + public static Type GetType(string name) + { + return Type.GetType(name); + } + /// /// Runs the external program. ///