コード例 #1
0
        private void GetDeviceInfo()
        {
            if (PlayerPrefs.GetInt(IS_GET_DEVICE_INFO, 0) == 0)
            {
                try
                {
#if UNITY_EDITOR
                    PlayerPrefs.SetString(UNIQUE_ID, SystemInfo.deviceUniqueIdentifier);
                    PlayerPrefs.SetString(SCREEN_SIZE, string.Format("{0}x{1}", Screen.width, Screen.height));
                    PlayerPrefs.SetString(MODEL, SystemInfo.deviceModel);
                    PlayerPrefs.SetString(OPERATING_SYSTEM, SystemInfo.operatingSystem);
                    PlayerPrefs.SetString(MEMORY, SystemInfo.systemMemorySize.ToString());
#elif UNITY_ANDROID
                    using (AndroidJavaClass secure = new AndroidJavaClass("android.provider.Settings$Secure"))
                    {
                        PlayerPrefs.SetString(UNIQUE_ID, secure.CallStatic <string>("getString",
                                                                                    UnityContext.Call <AndroidJavaObject>("getContentResolver"),
                                                                                    secure.GetStatic <string>("ANDROID_ID")));
                    }

                    using (AndroidJavaClass locale = new AndroidJavaClass("java.util.Locale"))
                    {
                        using (AndroidJavaObject defaultLocale = locale.CallStatic <AndroidJavaObject>("getDefault"))
                        {
                            PlayerPrefs.SetString(COUNTRY, defaultLocale.Call <string>("getCountry"));
                            PlayerPrefs.SetString(LANGUAGE, defaultLocale.Call <string>("getLanguage"));
                        }
                    }
#endif
                    PlayerPrefs.SetInt(IS_GET_DEVICE_INFO, 1);
                }
                catch (System.Exception exception)
                {
                    PlayerPrefs.SetInt(IS_GET_DEVICE_INFO, 0);
                    Debug.LogError(string.Format("Msg:\n{0}\nStack Trace:\n{1}", exception.Message,
                                                 exception.StackTrace));
                }
            }
        }