Last active
May 7, 2021 20:09
-
-
Save mao-test-h/f7a6733fc3eea2b73f617717c82d0351 to your computer and use it in GitHub Desktop.
Unity上からiOS端末の発熱状態を取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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