Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mao-test-h
Last active May 7, 2021 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mao-test-h/f7a6733fc3eea2b73f617717c82d0351 to your computer and use it in GitHub Desktop.
Save mao-test-h/f7a6733fc3eea2b73f617717c82d0351 to your computer and use it in GitHub Desktop.
Unity上からiOS端末の発熱状態を取得する
using System.Runtime.InteropServices;
namespace iOSNative
{
/// <summary>
/// `ProcessInfo`のBridge
/// </summary>
/// <remarks>
/// - https://developer.apple.com/documentation/foundation/processinfo
/// </remarks>
public static class ProcessInfoBridge
{
/// <summary>
/// システムの熱状態を取得
/// </summary>
/// <returns>
/// NOTE:
/// - iOS実機以外は常に`.Nominal`を返す
/// </returns>
public static ThermalState ThermalState
{
get
{
#if !UNITY_EDITOR && UNITY_IOS
return (ThermalState) ThermalStateNative();
#endif
return ThermalState.Nominal;
}
}
#region P/Invoke
[DllImport("__Internal", EntryPoint = "thermalState")]
static extern int ThermalStateNative();
#endregion P/Invoke
}
}
#import <Foundation/Foundation.h>
#ifdef __cplusplus
extern "C" {
#endif
// システムの熱状態を取得
// NOTE: マーシャリングの都合でintで返しているが、結果自体はNSProcessInfoThermalStateに準拠
// ref: https://developer.apple.com/documentation/foundation/nsprocessinfothermalstate?language=objc
int thermalState() {
return (int) [NSProcessInfo.processInfo thermalState];
}
#ifdef __cplusplus
}
#endif
namespace iOSNative
{
/// <summary>
/// システムの熱状態
/// </summary>
/// <remarks>
/// - https://developer.apple.com/documentation/foundation/processinfo/thermalstate
/// </remarks>
public enum ThermalState
{
/// <summary>
/// The thermal state is within normal limits.
/// </summary>
Nominal,
/// <summary>
/// The thermal state is slightly elevated.
/// </summary>
Fair,
/// <summary>
/// The thermal state is high.
/// </summary>
Serious,
/// <summary>
/// The thermal state is significantly impacting the performance of the system and the device needs to cool down.
/// </summary>
Critical,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment