89 lines
3.5 KiB
C#
89 lines
3.5 KiB
C#
using BigSpace.XRCore.Base;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Net.NetworkInformation;
|
|
using Unity.XR.PICO.TOBSupport;
|
|
using UnityEngine;
|
|
|
|
public class PicoFunc : Singleton<PicoFunc>
|
|
{
|
|
public string GetCode()
|
|
{
|
|
if (Application.platform == RuntimePlatform.Android)
|
|
{
|
|
return PXR_Enterprise.StateGetDeviceInfo(SystemInfoEnum.EQUIPMENT_SN);
|
|
}
|
|
else
|
|
{
|
|
string mac = "";
|
|
NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
|
|
foreach (NetworkInterface adaper in nis)
|
|
{
|
|
if (adaper.Description == "en0")
|
|
{
|
|
mac = adaper.GetPhysicalAddress().ToString();
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
mac = adaper.GetPhysicalAddress().ToString();
|
|
if (mac != "") break;
|
|
}
|
|
}
|
|
return mac;
|
|
}
|
|
}
|
|
|
|
#region 获取电量和音量
|
|
private static AndroidJavaObject audioManager = null;
|
|
private const string currentVolume = "getStreamVolume";//当前音量
|
|
private const string maxVolume = "getStreamMaxVolume";//最大音量
|
|
private const int STREAM_SYSTEM = 1;
|
|
private float maxvo = 0;
|
|
private float nowvo = 0;
|
|
int volum = 0;
|
|
public uint GetSystemVolume()
|
|
{
|
|
if (Application.platform == RuntimePlatform.Android)
|
|
{
|
|
if (audioManager == null)
|
|
{
|
|
AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
|
AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
|
|
audioManager = currentActivity.Call<AndroidJavaObject>("getSystemService", new AndroidJavaObject("java.lang.String", "audio"));
|
|
maxvo = float.Parse(audioManager.Call<int>(maxVolume, STREAM_SYSTEM).ToString());
|
|
}
|
|
nowvo = float.Parse(audioManager.Call<int>(currentVolume, STREAM_SYSTEM).ToString());
|
|
volum = Mathf.CeilToInt((nowvo / maxvo) * 100);
|
|
//Debug.Log("音量:" + volum);
|
|
return (uint)volum;
|
|
|
|
//Debug.Log("STREAM_VOICE_CALL:" + audioManager.Call<int>(currentVolume, STREAM_VOICE_CALL).ToString());
|
|
//Debug.Log("STREAM_RING:" + audioManager.Call<int>(currentVolume, STREAM_RING).ToString());
|
|
//Debug.Log("STREAM_MUSIC:" + audioManager.Call<int>(currentVolume, STREAM_MUSIC).ToString());
|
|
//Debug.Log("STREAM_ALARM:" + audioManager.Call<int>(currentVolume, STREAM_ALARM).ToString());
|
|
//Debug.Log("STREAM_NOTIFICATION:" + audioManager.Call<int>(currentVolume, STREAM_NOTIFICATION).ToString());
|
|
//Debug.Log("STREAM_DTMF:" + audioManager.Call<int>(currentVolume, STREAM_DTMF).ToString());
|
|
}
|
|
return 100;
|
|
}
|
|
public uint GetBatter()
|
|
{
|
|
if (Application.platform == RuntimePlatform.Android)
|
|
{
|
|
// 打印电池信息
|
|
//Debug.Log("电池==============Battery Status: " + SystemInfo.batteryStatus);
|
|
//Debug.Log("电池==============Battery Level: " + SystemInfo.batteryLevel * 100 + "%");
|
|
//return (uint)Mathf.CeilToInt(SystemInfo.batteryLevel * 100);
|
|
//Debug.Log("电量是多少:"+ PXR_Enterprise.StateGetDeviceInfo(SystemInfoEnum.ELECTRIC_QUANTITY));
|
|
|
|
return uint.Parse(PXR_Enterprise.StateGetDeviceInfo(SystemInfoEnum.ELECTRIC_QUANTITY));
|
|
}
|
|
else
|
|
{
|
|
return 100;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|