如何通过Unity将Android设备预热至40度? [英] How to warm up Android device to 40 degrees via Unity?

查看:299
本文介绍了如何通过Unity将Android设备预热至40度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望创建一个可以充当暖手器"的Android应用.我正在使用GPS通话,振动,手电筒,并且还使用多个线程在循环中运行代码.电池消耗很高,但还不够.

I wish to create an Android app that will act as a "hand warmer". I am using GPS calls, vibration, flashlight and I am also using multiple threads to run code in a loop. Battery consumption is high but it is not enough.

当我使用此应用时,大约需要10分钟才能从25度变为33度.我的目标是在尽可能短的时间内达到40度.

When I use this app it takes about 10 minutes in order to go from 25 degrees to 33. My goal is to reach 40 degrees in the shortest time possible.

那么,我如何通过C#代码读取设备温度,以及如何达到40度的高温并保持在该温度?

So, how can I read the device temp via C# code, and how to reach 40 degrees of heat and stay there?

推荐答案

您不需要手电筒或振动器即可进行此操作,因为大多数人会讨厌该应用程序,因为即使不需要时,这两个应用程序也会打开.

You don't need the flashlight or vibrator to do this as the app will be annoying to most people since these two would be switched on even when not needed.

使用不会对用户造成身体影响但能够产生热量的技术.

Use techniques that shouldn't affect the user physically but is capable of generating heat.

如何通过C#代码读取设备温度

how can I read the device temp via C# code

在读取传感器之前,您首先需要检查设备是否具有温度计传感器.至于使用C#从Android读取传感器,则必须使用Java代码编写,然后从C#调用该函数.

You first need to check if the device has a thermometer sensor before you should read the sensor. As for reading sensor from Android with C#, you have to write that with Java code then call that function from C#.

您可以使用已经制作的 Unity-Android-Sensor-Plugin 插件.

You can use the already made Unity-Android-Sensor-Plugin plugin for this.

private AndroidJavaObject plugin;

void Start ()
{
#if UNITY_ANDROID
    plugin = new AndroidJavaClass("jp.kshoji.unity.sensor.UnitySensorPlugin").CallStatic<AndroidJavaObject>("getInstance");

    //Init the ambienttemperature sensor
    if (plugin != null) 
    {
        plugin.Call("startSensorListening", "ambienttemperature");
    }
#endif
}

稍后要在更新"功能中读取环境温度传感器:

To read the ambient temperature sensors later on in the Update function:

float[] sensorValue = plugin.Call<float[]>("getSensorValues", "ambienttemperature");


电池消耗很高,但还不够.

Battery consumption is high but it is not enough.

这些是用来加热您的移动设备的技术.

These are techniques to use to heat up your mobile device.

亮度:

1 .将亮度更改为最高值.现在,禁用自动调光,以使屏幕指示灯始终闪烁.

1.Change the brightness to the highest value. Now, disable auto dim so that the screen led is always shining.

网络:

2 .创建多个(4到5)TCP服务器,每个服务器都在各自的线程中运行,并且设备上的端口也不同.

2.Create multiple(4 to 5) TCP server with with each one running in their own Threads and also with different ports on the device.

现在,创建相同数量的TCP客户端,并使用端口和IPAddress.Loopback作为IP连接到服务器.

Now, create the-same amount of TCP client and connect to the server with the ports and IPAddress.Loopback as the IP.

在while循环中,随机生成大约 13k 个浮点数,将其转换为字节数组,然后将其连续发送到每个客户端和服务器.当您收到它时,将该字节数组转换回浮点数,然后对结果完全不执行任何操作.重复并冲洗.

In a while loop, randomly generate about 13k float numbers, convert it to byte array then send it to each client and server continuously. When you receive it convert that byte array back to float then do absolutely nothing with the result. Repeat and rinse.

音频:

3 .将 5 6 音频文件加载到音频文件,将其设置为循环,然后将音量设置为0.播放所有音频.

3.Load 5 or 6 audio files to audio file, set the it to loop then set the volume to 0. Play all the audio.

视频:

4 .加载 5 6 动画,将其设置为循环然后播放.它可能在屏幕上不可见,但是只要它正在播放,它就可以正常工作.

4.Load 5 or 6 animations, set it to loop then play it. It may not be visible on the screen but as long as it is playing, it do fine.

视频:

5 .使用Unity的新

5.Load 3 videos with Unity's new VidepPlayer, disable audio, connect the video to RawImage. Set the alpha of other RawImage to 0 so that it is not visible. Play video and let decoding do the job.

传感器:

6 .启用加速度计"和陀螺仪传感器会在更新"功能的每一帧对其进行轮询.

6.Enable accelerometer and gyro sensors poll it every frame in the Update function.

7 .在更新功能中启用GPS并读取轮询每一帧.

7.Enable GPS and read poll it every frame in the Update function.

8 .启用蓝牙并每秒连续搜索其他设备.

8.Enable Bluetooth and do a continuous search for other devices every second.

9 .启用前后摄像头,从中拉出Textures,但不执行任何操作.

9.Enable the front and back camera, pull Textures from them but do nothing with it.

如何达到40度的热量并保持在那里?

how to reach 40 degrees of heat and stay there?

放在一起:

将上述所有内容放入函数或自己的类中.

Put everything described above in a function or its own class.

1 .编写一个带有int变量的简单类,该类称为level.此级别变量应用于确定上述哪些操作应在运行.

1.Write a simple class with an int variable called level. This level variable should be used to determine which actions described above should be running.

2 .启动应用后,将级别更改为9,然后启用/启动上述每种技术.如果温度达到 38 左右,则将温度降低到大约 5 .当级别降低时,您将停止在其下运行任何设备,因此,在这种情况下,应停止轮询加速度计,陀螺仪,GPS,蓝牙和摄像头,然后禁用它们.

2.When app is started, change the level to 9 then enable/start each technique described above. If the temperature reaches around 38, decrease the level to about 5. When the level is decreased, you stop running running anything under, so in this case,you should stop polling accelerometer, gyro, GPS ,Bluetooth and cameras then disable them.

3 .如果温度高于 40 ,请降低温度.如果它低于 40 ,请提高水平.这样可以将温度保持在~40度左右.

3.If the temperature is above 40, decrease the level. If it is below 40, increase the level. This is how you keep the temperature around ~40 degrees.

4 .甚至更好,您可能必须制作自己的 PID控制器为此使用了上述技术.正确处理将需要一些时间,但这可能是解决此问题的最佳方法.

4.Even better, you may have to make your own PID controller that uses those techniques above for this. It will take time to get it right but this is possibly the best way to go about this.

提示:

对于您做的每件事,请检查帧频.如果帧速率低于 6 ,请停止.如果您不这样做,Android可能会因为没有响应而终止该应用程序.

For each stuff you do, check the frame rate. If the frame-rate is below 6, stop. If you don't, Android may kill the app for not being responsive.

注意:

写一个简单的函数来检测暖手器"应用程序可能会成为"暖手器和截肢者"应用程序.

Write a simple function that detects some certain devices mentioned in the comment section. Make sure that this app does not run on these app or your "hand warmer" app could become a "hand warmer && amputator" app.

这篇关于如何通过Unity将Android设备预热至40度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆