简体   繁体   English

如何在Unity C#中获取语言环境信息?

[英]How can i get locale info in Unity C#?

I am developing a project with Unity 2019.2b, it is expected to work at all platforms (android, ios, windows, macos) , i am trying to get device locale info(eg en-us, en-au, en-bz) but all i can find is Application.systemLanguage definition. 我正在使用Unity 2019.2b开发一个项目,它有望在所有平台(android,ios,windows,macos)上工作,我正在尝试获取设备区域设置信息(例如en-us,en-au,en-bz)但我能找到的只是Application.systemLanguage定义。 Even i decide to use this information i will still need region info. 即使我决定使用这些信息,我仍然需要区域信息。 Are there any sample or way to get locale info in Unity or to get device region info? 是否有任何样本或方法可以在Unity中获取区域设置信息或获取设备区域信息? (If the solution for only region info; I dont want to use device location or dont want to use user ip address, i want to get it from settings) (如果只有区域信息的解决方案;我不想使用设备位置或不想使用用户IP地址,我想从设置中获取它)

I tried to get locale or at least device region info with RegionInfo,CultureInfo,System.Threading.Thread.CurrentThread.CurrentUICulture and System.Threading.Thread.CurrentThread.CurrentCulture definitions, but it didn't work. 我尝试使用RegionInfo,CultureInfo,System.Threading.Thread.CurrentThread.CurrentUICulture和System.Threading.Thread.CurrentThread.CurrentCulture定义获取区域设置或至少设备区域信息,但它不起作用。

string regionName = System.Globalization.RegionInfo.CurrentRegion.Name;
string cultureName = System.Globalization.CultureInfo.CurrentCulture.Name;
string cname = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
string uiname = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;

Depending on the platform (ios, android, windows,macos) sometimes the result comes as InvariantCulture, sometimes always en-US even device locale is not en-US. 根据平台(ios,android,windows,macos),有时结果是InvariantCulture,有时总是en-US甚至设备区域设置不是en-US。

The issue is coming from Mono, used by Unity. 问题来自Unity使用的Mono。

I found a few solutions in this forum thread . 我在这个论坛帖子中找到了一些解决方案。

If you are working with Windows a workaround might be using PInvoke: 如果您正在使用Windows,则解决方法可能是使用PInvoke:

 [System.Runtime.InteropServices.DllImport("KERNEL32.DLL")]
 private static extern int GetSystemDefaultLCID();

And then check the global culture like so: 然后像这样检查全球文化:

var currentCulture = new CultureInfo(GetSystemDefaultLCID());

This might be used to set the culture: 这可能用于设置文化:

 Thread.CurrentThread.CurrentCulture = new CultureInfo(GetSystemDefaultLCID());
 Thread.CurrentThread.CurrentUICulture = new CultureInfo(GetSystemDefaultLCID());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Unity 中获得 OnTriggerEnter 角度? C# - How can i get OnTriggerEnter angle in Unity ? c# 如何在使用C#开发的android中获取我的音乐播放器的MP3文件信息 - How can I get a MP3 file info for my musicplayer in android developed with C# 我如何像在终端上一样在c#客户端(stackexchange)上获取群集信息? - How can i get cluster info just like on the terminal, but on my c# client (stackexchange)? 在Unity / C#中基于ColorSpacePoint获取Kinect深度信息 - Get Kinect Depth Info Based On ColorSpacePoint in Unity/C# 我们如何在C#中获取磁盘性能信息 - How can we get Disk Performance info in C# 如何从C#中的IMDB获取信息 - how can get info from IMDB in C# 如何使用 C# 在 Ubuntu 上获取 GPU 信息? - How do I get GPU info on Ubuntu using C#? UNITY C# - 如何获取标有自定义属性(字段)的 class 实例的所有字段? - UNITY C# - How can I get all the fields of the an instance of a class marked with my custom atribute(the fields)? UNITY,我如何从另一个 C# class 获取所有属性并将它们放入枚举 - UNITY, How can I get all properties from another C# class and put them into an enum 如何从Unity的文本字段中获取文本信息并将其分配给C#中的变量? - How do I take text info from a text field from Unity and assign it to a variable in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM