Skip to content

Commit 777d493

Browse files
author
d00605132
committed
更改文件名
1 parent 3c655dc commit 777d493

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using MonitorLib.GOT;
3+
using UnityEngine;
4+
5+
public class UnityAndroidProxy
6+
{
7+
private AndroidJavaClass jc;
8+
private AndroidJavaObject jo;
9+
private bool isInit = false;
10+
11+
public UnityAndroidProxy()
12+
{
13+
Init();
14+
}
15+
16+
public void Init()
17+
{
18+
#if UNITY_ANDROID
19+
if (isInit)
20+
{
21+
return;
22+
}
23+
try
24+
{
25+
jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
26+
//jc = new AndroidJavaClass("com.sc.testextendlibrary.MainActivity");
27+
jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
28+
isInit = true;
29+
}
30+
catch (Exception e)
31+
{
32+
Debug.LogError(e);
33+
}
34+
#endif
35+
}
36+
37+
#if UNITY_ANDROID
38+
public DevicePowerConsumeInfo GetPowerConsumeInfo(int frameIndex = 0)
39+
{
40+
if (null == jo || null == jc)
41+
{
42+
Init();
43+
}
44+
string result = jo.Call<string>("GetCurPowerConsumeArgs");
45+
if (string.IsNullOrEmpty(result))
46+
{
47+
return default;
48+
}
49+
//Debug.Log($"从安卓获取结果:{result}");
50+
string[] args = result.Split('|');
51+
DevicePowerConsumeInfo devicePowerConsumeInfo = new DevicePowerConsumeInfo();
52+
devicePowerConsumeInfo.FrameIndex = frameIndex;
53+
devicePowerConsumeInfo.Capacity = Convert.ToInt32(args[0]);
54+
devicePowerConsumeInfo.Temperature = Convert.ToInt32(args[1]);
55+
devicePowerConsumeInfo.BatteryV = Convert.ToSingle(args[2]);
56+
devicePowerConsumeInfo.BatteryCapacity = Convert.ToInt32(args[3]);
57+
devicePowerConsumeInfo.BatteryChargeCounter = Convert.ToInt32(args[4]);
58+
devicePowerConsumeInfo.BatteryCurrentNow = Convert.ToInt32(args[5]);
59+
devicePowerConsumeInfo.BatteryPower = Convert.ToSingle(args[6]);
60+
devicePowerConsumeInfo.UseLeftHours = Convert.ToSingle(args[7]);
61+
devicePowerConsumeInfo.CpuTemperate = Convert.ToInt32(args[8]);
62+
return devicePowerConsumeInfo;
63+
}
64+
65+
public MemoryUseData GetPssMemory(int frameIndex = 0)
66+
{
67+
if (null == jo || null == jc)
68+
{
69+
Init();
70+
}
71+
var pss = jo.Call<float>("GetCurAppMemorySize");
72+
var memoryUseData = new MemoryUseData()
73+
{
74+
FrameIndex = frameIndex,
75+
PssMemorySize = pss
76+
};
77+
return memoryUseData;
78+
}
79+
#endif
80+
}

Assets/GOT/Scripts/UnityAndroidProxy.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)