123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #if UNITY_IOS
- using System.Runtime.InteropServices;
- #endif
- #if UNITY_ANDROID
- using UnityEngine;
- #endif
- namespace Google.Maps.Scripts {
-
-
-
- public class DeviceCountryProvider : CountryProvider {
-
- private string CountryCode;
-
-
-
-
-
- public void Awake() {
- #if UNITY_EDITOR
-
-
- CountryCode = null;
- #elif UNITY_ANDROID
- try {
- using (var localeClass = new AndroidJavaClass("java.util.Locale")) {
- using (var defaultLocale = localeClass.CallStatic<AndroidJavaObject>("getDefault")) {
- CountryCode = defaultLocale.Call<string>("getCountry");
- }
- }
- } catch (System.Exception e) {
- Debug.LogWarningFormat("<color=red><b>[Maps SDK]</b></color> DeviceCountryError: " +
- "Couldn't get device country: {0}\nSee https://developers.google.com/maps/" +
- "documentation/gaming/support/error_codes#device-country-error for more information.",
- e);
- }
- #elif UNITY_IOS
- CountryCode = MuskGetLocaleRegion();
- #else
- CountryCode = null;
- #endif
- }
-
- public override string GetCountry() {
- return CountryCode;
- }
- #if UNITY_IOS
-
-
-
- [DllImport("__Internal")]
- private static extern string MuskGetLocaleRegion();
- #endif
- }
- }
|