/// <summary> /// 获取设备名称 /// </summary> /// <returns></returns> public static string GetDeviceName() { if (_deviceNameInitialized) { return _deviceName; } #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR _deviceName = SystemInfo.deviceName; #elif UNITY_ANDROID using (AndroidJavaClass deviceUtils = new AndroidJavaClass(CLASS_DEVICES_UTILS)) { _deviceName = deviceUtils.CallStatic<string>("GetDeviceName"); deviceUtils.Dispose(); } #elif UNITY_IPHONE //_deviceName = _IOS_GetDeviceName(); #endif _deviceNameInitialized = true; return _deviceName; }
public void Dispose() { if (native != null) { native.Dispose(); native = null; } }
int _Init() { AndroidJavaClass _androidJC = new AndroidJavaClass ("com.unity3d.player.UnityPlayer"); if(_androidJC != null){ _AndroidPluginObj = _androidJC.GetStatic<AndroidJavaObject> ("currentActivity"); _androidJC.Dispose (); if(_AndroidPluginObj == null){ return -1; } return 0; } return -1; }
private void OnLaunchApp(JObject msg) { Debug.Log("onLaunchApp"); string gameId = (string)msg ["game_id"]; string gameVersion = (string)msg ["game_version"]; if (gameId != Application.bundleIdentifier || gameVersion != AirConsole.instance.androidTvGameVersion) { AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity"); AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager"); AndroidJavaObject launchIntent = null; try { launchIntent = packageManager.Call<AndroidJavaObject>("getLeanbackLaunchIntentForPackage", gameId); } catch (Exception) { Debug.Log("getLeanbackLaunchIntentForPackage for " + gameId + " failed"); } if (launchIntent == null) { try { launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", gameId); } catch (Exception) { Debug.Log("getLaunchIntentForPackage for " + gameId + " failed"); } } if (launchIntent != null && gameId != Application.bundleIdentifier) { ca.Call("startActivity", launchIntent); } else { Application.OpenURL("market://details?id=" + gameId); } up.Dispose(); ca.Dispose(); packageManager.Dispose(); launchIntent.Dispose(); System.Diagnostics.Process.GetCurrentProcess().Kill(); } }
void Awake() { if (sdk == null) { sdk = this; } else { Debug.LogWarning("Cardboard SDK object should be a singleton."); enabled = false; } config.initialize(); #if ANDROID_DEVICE try { AndroidJavaClass player = new AndroidJavaClass(cardboardClass); cardboardActivity = player.CallStatic<AndroidJavaObject>("getActivity"); player.Dispose(); cardboardActivity.Call("initFromUnity", gameObject.name); config.canAccessActivity = true; } catch (AndroidJavaException e) { Debug.LogError("Cannot access UnityCardboardActivity. " + "Verify that the jar is in Assets/Plugins/Android. " + e); } // Force side-effectful initialization using serialized values. EnableAlignmentMarker = enableAlignmentMarker; EnableSettingsButton = enableSettingsButton; TapIsTrigger = tapIsTrigger; #endif if (config.canApplyDistortionCorrection()) { Debug.Log("Creating new cardboard screen texture"); StereoScreen = new RenderTexture(Screen.width, Screen.height, 16, RenderTextureFormat.RGB565); StereoScreen.Create(); InitFromUnity(StereoScreen.GetNativeTextureID()); } else { if (!Application.isEditor) { Debug.LogWarning("Lens distortion-correction disabled. Causes: [" + config.getDistortionCorrectionDiagnostic() + "]"); } } InCardboard = newInCardboard = false; #if UNITY_EDITOR if (VRModeEnabled && Application.isPlaying) { SetInCardboard(true); } #endif StartCoroutine("EndOfFrame"); }
/// <summary> /// 获取Mac地址 /// </summary> /// <returns></returns> public static string GetMac() { if (_macInitialized) { return _mac; } #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR #elif UNITY_ANDROID using (AndroidJavaClass unityClass = new AndroidJavaClass(CLASS_UNITYPLAYER_ACTIVITY)) { using (AndroidJavaObject activity = unityClass.GetStatic<AndroidJavaObject>("currentActivity")) { using (AndroidJavaClass deviceUtils = new AndroidJavaClass(CLASS_DEVICES_UTILS)) { _mac = deviceUtils.CallStatic<string>("GetMac", activity); deviceUtils.Dispose(); } activity.Dispose(); } unityClass.Dispose(); } #elif UNITY_IPHONE //_mac = _IOS_GetMac(); #endif _macInitialized = true; return _mac; }
/// <summary> /// 获取外置储存路径 /// </summary> /// <returns>返回外置储存目录路径,没有则返回null</returns> public static string GetExternalStorageDirectory() { if (_externalStorageDirectoryInitialized) { return _externalStorageDirectory; } #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR _externalStorageDirectory = Application.dataPath; #elif UNITY_ANDROID using (AndroidJavaClass deviceUtils = new AndroidJavaClass(CLASS_DEVICES_UTILS)) { _externalStorageDirectory = deviceUtils.CallStatic<string>("GetExternalStorageDirectory"); deviceUtils.Dispose(); } #elif UNITY_IPHONE //_externalStorageDirectory = _IOS_GetExternalStorageDirectory(); #endif _externalStorageDirectoryInitialized = true; return _externalStorageDirectory; }
/// <summary> /// 获取系统版本 /// </summary> /// <returns></returns> public static string GetOSVersion() { if (_osVersionInitialized) { return _osVersion; } #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR #elif UNITY_ANDROID using (AndroidJavaClass deviceUtils = new AndroidJavaClass(CLASS_DEVICES_UTILS)) { _osVersion = deviceUtils.CallStatic<string>("GetAPIVersion"); deviceUtils.Dispose(); } #elif UNITY_IPHONE //_osVersion = _IOS_GetOSVersion(); #endif _osVersionInitialized = true; return _osVersion; }