浏览代码

Merge pull request #79 from unity/add-thermal-sample

Add a thermal state scene sample.
/4.1
GitHub Enterprise 4 年前
当前提交
370af9f4
共有 23 个文件被更改,包括 2071 次插入1 次删除
  1. 230
      Assets/Scenes/ARFoundationMenu/Menu.unity
  2. 5
      Assets/Scripts/UX/ARSceneSelectUI.cs
  3. 13
      Assets/Scripts/UX/CheckAvailableFeatures.cs
  4. 3
      ProjectSettings/EditorBuildSettings.asset
  5. 4
      README.md
  6. 8
      Assets/Scenes/ThermalState.meta
  7. 8
      Assets/Scenes/ThermalState/Prefabs.meta
  8. 98
      Assets/Scenes/ThermalState/Prefabs/SimpleMesh.prefab
  9. 7
      Assets/Scenes/ThermalState/Prefabs/SimpleMesh.prefab.meta
  10. 8
      Assets/Scenes/ThermalState/Scripts.meta
  11. 1001
      Assets/Scenes/ThermalState/ThermalState.unity
  12. 7
      Assets/Scenes/ThermalState/ThermalState.unity.meta
  13. 11
      Assets/Scenes/ThermalState/Scripts/FeaturesReporting.cs.meta
  14. 147
      Assets/Scenes/ThermalState/Scripts/ThermalStateForIOS.cs
  15. 11
      Assets/Scenes/ThermalState/Scripts/ThermalStateForIOS.cs.meta
  16. 47
      Assets/Scenes/ThermalState/Scripts/ThermalStateForIOSProvider.mm
  17. 37
      Assets/Scenes/ThermalState/Scripts/ThermalStateForIOSProvider.mm.meta
  18. 204
      Assets/Scenes/ThermalState/Scripts/ThermalStateHandling.cs
  19. 11
      Assets/Scenes/ThermalState/Scripts/ThermalStateHandling.cs.meta
  20. 212
      Assets/Scenes/ThermalState/Scripts/FeaturesReporting.cs

230
Assets/Scenes/ARFoundationMenu/Menu.unity


m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 123453201}
m_CullTransparentMesh: 0
--- !u!1 &175873739
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 175873740}
- component: {fileID: 175873742}
- component: {fileID: 175873741}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &175873740
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 175873739}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1831158601}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &175873741
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 175873739}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Thermal State
--- !u!222 &175873742
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 175873739}
m_CullTransparentMesh: 0
--- !u!1 &176615697
GameObject:
m_ObjectHideFlags: 0

m_ConfigChooser: {fileID: 2011106401}
m_InputSystem: {fileID: 1868840083}
m_CameraGrain: {fileID: 1726760294}
m_ThermalStateButton: {fileID: 1831158597}
--- !u!1 &786358435
GameObject:
m_ObjectHideFlags: 0

- {fileID: 1868840081}
- {fileID: 2011106399}
- {fileID: 1726760292}
- {fileID: 1831158601}
m_Father: {fileID: 1413559114}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

m_Name:
m_EditorClassIdentifier:
m_Tooltip: {fileID: 2094799242}
--- !u!1 &1831158596
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1831158601}
- component: {fileID: 1831158600}
- component: {fileID: 1831158598}
- component: {fileID: 1831158597}
- component: {fileID: 1831158599}
m_Layer: 5
m_Name: Thermal State
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1831158597
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1831158596}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 0
m_TargetGraphic: {fileID: 1831158598}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 774532498}
m_TargetAssemblyTypeName: UnityEngine.XR.ARFoundation.Samples.ARSceneSelectUI,
Assembly-CSharp
m_MethodName: ThermalStateButtonPressed
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &1831158598
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1831158596}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &1831158599
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1831158596}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 16733cd6749cf4d96be9df0329c6938a, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Tooltip: {fileID: 2094799242}
--- !u!222 &1831158600
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1831158596}
m_CullTransparentMesh: 0
--- !u!224 &1831158601
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1831158596}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 2.8958, y: 2.8958, z: 2.8958}
m_Children:
- {fileID: 175873740}
m_Father: {fileID: 1569808631}
m_RootOrder: 23
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 350, y: -650}
m_SizeDelta: {x: 110, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &1847920808
GameObject:
m_ObjectHideFlags: 0

m_HandleRect: {fileID: 1130901185}
m_Direction: 2
m_Value: 1
m_Size: 0.20706683
m_Size: 0.33929503
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:

5
Assets/Scripts/UX/ARSceneSelectUI.cs


LoadScene("CameraGrain");
}
public void ThermalStateButtonPressed()
{
LoadScene("ThermalState");
}
void ScrollToStartPosition()
{
m_HorizontalScrollBar.value = 0;

13
Assets/Scripts/UX/CheckAvailableFeatures.cs


set => m_CameraGrain = value;
}
[SerializeField]
Button m_ThermalStateButton;
public Button thermalStateButton
{
get => m_ThermalStateButton;
set => m_ThermalStateButton = value;
}
void Start()
{
var planeDescriptors = new List<XRPlaneSubsystemDescriptor>();

{
m_Meshing.interactable = true;
}
#if UNITY_IOS
m_ThermalStateButton.interactable = true;
#endif // UNITY_IOS
}
}
}

3
ProjectSettings/EditorBuildSettings.asset


- enabled: 1
path: Assets/Scenes/SimpleAR/SimpleAR.unity
guid: 99c9720ab356a0642a771bea13969a05
- enabled: 1
path: Assets/Scenes/ThermalState/ThermalState.unity
guid: e5b0cb11dfe354e67a344c280bf8b611
m_configObjects:
UnityEditor.XR.ARCore.ARCoreSettings: {fileID: 11400000, guid: f8ce26fe3bc69499b9be4b2378e97a94,
type: 2}

4
README.md


## Input System
This sample demonstrates a version of the SimpleAR scene using Unity's new Input System. See [`ARController.inputactions`](https://github.com/Unity-Technologies/arfoundation-samples/blob/latest-preview/Assets/Scenes/InputSystem/ARController.inputactions) for an example of an action map. For a demonstration on how these action map bindings are used, see the [`InputSystem_PlaceOnPlane.cs`](https://github.com/Unity-Technologies/arfoundation-samples/blob/latest-preview/Assets/Scenes/InputSystem/InputSystem_PlaceOnPlane.cs) script. For more details, see the [`Input System Documentation`](https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/index.html).
## Thermal State
This sample contains the code required to query for an iOS device's thermal state so that the thermal state may be used with C# game code. This sample illustrates how the thermal state may be used to disable AR Foundation features to reduce the thermal state of the device.
# Community and Feedback
The intention of this reposititory is to provide a means for getting started with the features in ARFoundation. The samples are intentionally simplistic with a focus on teaching basic scene setup and APIs. If you you have a question, find a bug, or would like to request a new feature concerning any of the ARFoundation packages or these samples please [submit a GitHub issue](https://github.com/Unity-Technologies/arfoundation-samples/issues). New issues are reviewed regularly.

8
Assets/Scenes/ThermalState.meta


fileFormatVersion: 2
guid: 8326044ec302a44fc81b17b2b68576b8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Scenes/ThermalState/Prefabs.meta


fileFormatVersion: 2
guid: a2bb3ad8a77cf4165a64050458de4c38
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

98
Assets/Scenes/ThermalState/Prefabs/SimpleMesh.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &628810306991918854
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1334555916045423617}
- component: {fileID: 3164683533026836259}
- component: {fileID: 5509717854409629217}
- component: {fileID: 1592233981980384025}
m_Layer: 0
m_Name: SimpleMesh
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1334555916045423617
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 628810306991918854}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &3164683533026836259
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 628810306991918854}
m_Mesh: {fileID: 0}
--- !u!23 &5509717854409629217
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 628810306991918854}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: e01257fbb05e84833a5beb1792546158, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!64 &1592233981980384025
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 628810306991918854}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 4
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 0}

7
Assets/Scenes/ThermalState/Prefabs/SimpleMesh.prefab.meta


fileFormatVersion: 2
guid: 481ab5ad50c684d128841668c492e601
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Scenes/ThermalState/Scripts.meta


fileFormatVersion: 2
guid: fccca18c31f2c4301b7868e8b79dae92
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/Scenes/ThermalState/ThermalState.unity
文件差异内容过多而无法显示
查看文件

7
Assets/Scenes/ThermalState/ThermalState.unity.meta


fileFormatVersion: 2
guid: e5b0cb11dfe354e67a344c280bf8b611
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

11
Assets/Scenes/ThermalState/Scripts/FeaturesReporting.cs.meta


fileFormatVersion: 2
guid: ae0dd90ee676041d5a821647cb367fc7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

147
Assets/Scenes/ThermalState/Scripts/ThermalStateForIOS.cs


using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using UnityEngine;
namespace UnityEngine.XR.ARFoundation.Samples
{
/// <summary>
/// A component that provides functionality to query for thermal state on iOS devices and to subscribe to an event
/// that fires when the thermal state changes.
/// </summary>
public class ThermalStateForIOS : MonoBehaviour
{
#if UNITY_IOS && !UNITY_EDITOR
/// <summary>
/// The thermal state on the previous update, used for determining when to fire the state changed event.
/// </summary>
ThermalState? m_PreviousThermalState;
#endif // UNITY_IOS && !UNITY_EDITOR
/// <summary>
/// Event that fires when the thermal state has changed.
/// </summary>
public Action<ThermalStateChange> stateChanged;
/// <summary>
/// iOS thermal states as documented by
/// https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/RespondToThermalStateChanges.html
/// <summary>
public enum ThermalState
{
/// <summary>
/// Thermal state is unknown.
/// </summary>
[Description("Unknown")]
Unknown = 0,
/// <summary>
/// The thermal state is at an acceptable level.
/// </summary>
[Description("Nominal")]
Nominal = 1,
/// <summary>
/// The thermal state is minimally elevated.
/// </summary>
[Description("Fair")]
Fair = 2,
/// <summary>
/// The thermal state is highly elevated.
/// </summary>
[Description("Serious")]
Serious = 3,
/// <summary>
/// The thermal state is significantly elevated.
/// </summary>
[Description("Critical")]
Critical = 4,
}
/// <summary>
/// Queries the current thermal state of the iOS device.
/// </summary>
public ThermalState currentThermalState => NativeApi.GetCurrentThermalState();
#if UNITY_IOS && !UNITY_EDITOR
/// <summary>
/// On enable, initialize the previous thermal state to null.
/// </summary>
void OnEnable()
{
m_PreviousThermalState = null;
}
/// <summary>
/// On each update, query the current thermal state, and fire the state changed event if the thermal state has
/// changed since the previous update.
/// </summary>
void Update()
{
ThermalState thermalState = currentThermalState;
if (m_PreviousThermalState.HasValue && (thermalState != m_PreviousThermalState.Value))
{
if (stateChanged != null)
{
stateChanged(new ThermalStateChange(m_PreviousThermalState.Value, thermalState));
}
}
m_PreviousThermalState = thermalState;
}
#endif // UNITY_IOS && !UNITY_EDITOR
/// <summary>
/// Struct containing both the previous and current thermal states when a state change occurs.
/// </summary>
public struct ThermalStateChange
{
/// <summary>
/// The previous thermal state for a state change event.
/// </summary>
ThermalState m_PreviousThermalState;
/// <summary>
/// The current thermal state for a state change event.
/// </summary>
ThermalState m_CurrentThermalState;
/// <summary>
/// The previous thermal state for a state change event.
/// </summary>
public ThermalState previousThermalState => m_PreviousThermalState;
/// <summary>
/// The current thermal state for a state change event.
/// </summary>
public ThermalState currentThermalState => m_CurrentThermalState;
/// <summary>
/// Constructs a thermal state change with the previous and current thermal states.
/// </summary>
/// <param name="previousThermalState">The previous thermal state for a state change event.</param>
/// <param name="currentThermalState">The current thermal state for a state change event.</param>
public ThermalStateChange (ThermalState previousThermalState, ThermalState currentThermalState)
{
m_PreviousThermalState = previousThermalState;
m_CurrentThermalState = currentThermalState;
}
}
/// <summary>
/// Native API for querying the thermal state on iOS. For other platforms, this API is stubbed out.
/// /<summary>
static class NativeApi
{
#if UNITY_IOS && !UNITY_EDITOR
[DllImport("__Internal", EntryPoint = "ARFoundationSamples_GetCurrentThermalState")]
public static extern ThermalState GetCurrentThermalState();
#else // UNITY_IOS && !UNITY_EDITOR
public static ThermalState GetCurrentThermalState() => ThermalState.Unknown;
#endif // UNITY_IOS && !UNITY_EDITOR
}
}
}

11
Assets/Scenes/ThermalState/Scripts/ThermalStateForIOS.cs.meta


fileFormatVersion: 2
guid: 6799e8e2720634b88b4605c0315c05b1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

47
Assets/Scenes/ThermalState/Scripts/ThermalStateForIOSProvider.mm


#import <Foundation/NSProcessInfo.h>
#define EXPORT(_returnType_) extern "C" _returnType_ __attribute__ ((visibility ("default")))
namespace
{
// Values must match UnityEngine.XR.ARFoundation.Samples.ThermalStateForIOS.ThermalState
enum ThermalState
{
kThermalStateUnknown = 0,
kThermalStateNominal = 1,
kThermalStateFair = 2,
kThermalStateSerious = 3,
kThermalStateCritical = 4,
};
inline ThermalState ConvertThermalState(NSProcessInfoThermalState thermalState)
{
ThermalState returnValue;
switch (thermalState)
{
case NSProcessInfoThermalStateNominal:
returnValue = kThermalStateNominal;
break;
case NSProcessInfoThermalStateFair:
returnValue = kThermalStateFair;
break;
case NSProcessInfoThermalStateSerious:
returnValue = kThermalStateSerious;
break;
case NSProcessInfoThermalStateCritical:
returnValue = kThermalStateCritical;
break;
default:
returnValue = kThermalStateUnknown;
break;
}
return returnValue;
}
}
EXPORT(ThermalState) ARFoundationSamples_GetCurrentThermalState()
{
return ::ConvertThermalState([[NSProcessInfo processInfo] thermalState]);
}

37
Assets/Scenes/ThermalState/Scripts/ThermalStateForIOSProvider.mm.meta


fileFormatVersion: 2
guid: 2fa0ad5f54cd343c781cbd116aaf8ef7
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings: {}
- first:
tvOS: tvOS
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:

204
Assets/Scenes/ThermalState/Scripts/ThermalStateHandling.cs


using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARFoundation.Samples
{
public class ThermalStateHandling : MonoBehaviour
{
/// <summary>
/// The environment probe manager.
/// </summary>
AREnvironmentProbeManager m_EnvironmentProbeManager;
/// <summary>
/// The face manager.
/// </summary>
ARFaceManager m_FaceManager;
/// <summary>
/// The mesh manager.
/// </summary>
ARMeshManager m_MeshManager;
/// <summary>
/// The occlusion manager.
/// </summary>
AROcclusionManager m_OcclusionManager;
/// <summary>
/// The AR session.
/// </summary>
ARSession m_Session;
/// <summary>
/// The component from which to query the thermal state.
/// </summary>
public ThermalStateForIOS thermalStateForIOS
{
get => m_ThermalStateForIOS;
set => m_ThermalStateForIOS = value;
}
[SerializeField]
ThermalStateForIOS m_ThermalStateForIOS;
/// <summary>
/// The text UI to update with the current thermal state.
/// </summary>
public Text thermalStateText
{
get => m_ThermalStateText;
set => m_ThermalStateText = value;
}
[SerializeField]
public Text m_ThermalStateText;
/// <summary>
/// On awake, find all of the AR components.
/// </summary>
void Awake()
{
m_EnvironmentProbeManager = FindObjectOfType<AREnvironmentProbeManager>();
m_FaceManager = FindObjectOfType<ARFaceManager>();
m_MeshManager = FindObjectOfType<ARMeshManager>();
m_OcclusionManager = FindObjectOfType<AROcclusionManager>();
m_Session = FindObjectOfType<ARSession>();
}
/// <summary>
/// On enable, update the current thermal state text, set the AR features, and subscribe to the thermal state
/// change event.
/// </summary>
void OnEnable()
{
Debug.Assert(m_ThermalStateForIOS != null, "ThermalStateForIOS cannot be null");
Debug.Assert(m_ThermalStateText != null, "ThermalStateText cannot be null");
ThermalStateForIOS.ThermalState thermalState = m_ThermalStateForIOS.currentThermalState;
m_ThermalStateText.text = $"Thermal State: {thermalState}";
SetARFeaturesBasedOnThermalState(thermalState);
m_ThermalStateForIOS.stateChanged += OnThermalStateChanged;
}
/// <summary>
/// On disable, update the current thermal state text, and unsubscribe to the thermal state change event.
/// </summary>
void OnDisable()
{
Debug.Assert(m_ThermalStateForIOS != null, "ThermalStateForIOS cannot be null");
Debug.Assert(m_ThermalStateText != null, "ThermalStateText cannot be null");
m_ThermalStateText.text = $"Thermal State: {ThermalStateForIOS.ThermalState.Unknown}";
m_ThermalStateForIOS.stateChanged -= OnThermalStateChanged;
}
/// <summary>
/// When the thermal state changes, update the thermal state text UI, and set the AR features based on the
/// current thermal state.
/// </summary>
void OnThermalStateChanged(ThermalStateForIOS.ThermalStateChange thermalStateChangeArgs)
{
m_ThermalStateText.text = $"Thermal State: {thermalStateChangeArgs.currentThermalState}";
SetARFeaturesBasedOnThermalState(thermalStateChangeArgs.currentThermalState);
}
/// <summary>
/// Enable/disable AR features based on the thermal state in an effort to reduce power in elevated thermal
/// states.
/// </summary>
/// <remarks>
/// Note that these particular features for each thermal state are just for demo purposes only. Developers
/// should decide which features are most critical for their own apps.
/// </summary>
void SetARFeaturesBasedOnThermalState(ThermalStateForIOS.ThermalState thermalState)
{
switch (thermalState)
{
case ThermalStateForIOS.ThermalState.Nominal:
ToggleEnvironmentProbeFeature(true);
ToggleFaceTrackingFeature(true);
ToggleMeshingFeature(true);
ToggleHumanSegmentationFeatures(true);
ToggleEnvironmentDepthFeature(true);
ToggleARSession(true);
break;
case ThermalStateForIOS.ThermalState.Fair:
ToggleEnvironmentProbeFeature(false);
ToggleFaceTrackingFeature(false);
ToggleMeshingFeature(false);
ToggleHumanSegmentationFeatures(false);
ToggleEnvironmentDepthFeature(true);
ToggleARSession(true);
break;
case ThermalStateForIOS.ThermalState.Serious:
ToggleEnvironmentProbeFeature(false);
ToggleFaceTrackingFeature(false);
ToggleMeshingFeature(false);
ToggleHumanSegmentationFeatures(false);
ToggleEnvironmentDepthFeature(false);
ToggleARSession(true);
break;
case ThermalStateForIOS.ThermalState.Critical:
ToggleEnvironmentProbeFeature(false);
ToggleFaceTrackingFeature(false);
ToggleMeshingFeature(false);
ToggleHumanSegmentationFeatures(false);
ToggleEnvironmentDepthFeature(false);
ToggleARSession(false);
break;
case ThermalStateForIOS.ThermalState.Unknown:
default:
ToggleEnvironmentProbeFeature(true);
ToggleFaceTrackingFeature(true);
ToggleMeshingFeature(true);
ToggleHumanSegmentationFeatures(true);
ToggleEnvironmentDepthFeature(true);
ToggleARSession(true);
break;
}
}
void ToggleEnvironmentProbeFeature(bool active)
{
Debug.Assert(m_EnvironmentProbeManager != null, "environment probe manager not found");
m_EnvironmentProbeManager.enabled = active;
}
void ToggleFaceTrackingFeature(bool active)
{
Debug.Assert(m_FaceManager != null, "face manager not found");
m_FaceManager.enabled = active;
}
void ToggleMeshingFeature(bool active)
{
Debug.Assert(m_MeshManager != null, "mesh manager not found");
m_MeshManager.enabled = active;
}
void ToggleHumanSegmentationFeatures(bool active)
{
Debug.Assert(m_OcclusionManager != null, "occlusion manager not found");
m_OcclusionManager.requestedHumanDepthMode = active ? HumanSegmentationDepthMode.Best : HumanSegmentationDepthMode.Disabled;
m_OcclusionManager.requestedHumanStencilMode = active ? HumanSegmentationStencilMode.Best : HumanSegmentationStencilMode.Disabled;
}
void ToggleEnvironmentDepthFeature(bool active)
{
Debug.Assert(m_OcclusionManager != null, "occlusion manager not found");
m_OcclusionManager.requestedEnvironmentDepthMode = active ? EnvironmentDepthMode.Best : EnvironmentDepthMode.Disabled;
}
void ToggleARSession(bool active)
{
Debug.Assert(m_MeshManager != null, "AR session not found");
m_Session.enabled = active;
}
}
}

11
Assets/Scenes/ThermalState/Scripts/ThermalStateHandling.cs.meta


fileFormatVersion: 2
guid: b9a75ddfff96e4c9a945b81c1c78f9c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

212
Assets/Scenes/ThermalState/Scripts/FeaturesReporting.cs


using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
#if UNITY_IOS && !UNITY_EDITOR
using UnityEngine.XR.ARKit;
#endif // UNITY_IOS && !UNITY_EDITOR
namespace UnityEngine.XR.ARFoundation.Samples
{
public class FeaturesReporting : MonoBehaviour
{
public Text autoFocusText
{
get => m_AutoFocusText;
set => m_AutoFocusText = value;
}
[SerializeField]
Text m_AutoFocusText;
public Text environmentDepthText
{
get => m_EnvironmentDepthText;
set => m_EnvironmentDepthText = value;
}
[SerializeField]
Text m_EnvironmentDepthText;
public Text environmentProbesText
{
get => m_EnvironmentProbesText;
set => m_EnvironmentProbesText = value;
}
[SerializeField]
Text m_EnvironmentProbesText;
public Text faceTrackingText
{
get => m_FaceTrackingText;
set => m_FaceTrackingText = value;
}
[SerializeField]
Text m_FaceTrackingText;
public Text humanDepthText
{
get => m_HumanDepthText;
set => m_HumanDepthText = value;
}
[SerializeField]
Text m_HumanDepthText;
public Text humanStencilText
{
get => m_HumanStencilText;
set => m_HumanStencilText = value;
}
[SerializeField]
Text m_HumanStencilText;
public Text lightEstimationColorText
{
get => m_LightEstimationColorText;
set => m_LightEstimationColorText = value;
}
[SerializeField]
Text m_LightEstimationColorText;
public Text lightEstimationIntensityText
{
get => m_LightEstimationIntensityText;
set => m_LightEstimationIntensityText = value;
}
[SerializeField]
Text m_LightEstimationIntensityText;
public Text meshingText
{
get => m_MeshingText;
set => m_MeshingText = value;
}
[SerializeField]
Text m_MeshingText;
public Text meshingClassificationText
{
get => m_MeshingClassificationText;
set => m_MeshingClassificationText = value;
}
[SerializeField]
Text m_MeshingClassificationText;
public Text planeTrackingText
{
get => m_PlaneTrackingText;
set => m_PlaneTrackingText = value;
}
[SerializeField]
Text m_PlaneTrackingText;
public Text raycastingText
{
get => m_RaycastingText;
set => m_RaycastingText = value;
}
[SerializeField]
Text m_RaycastingText;
public Text rotationAndOrientationText
{
get => m_RotationAndOrientationText;
set => m_RotationAndOrientationText = value;
}
[SerializeField]
Text m_RotationAndOrientationText;
public Text worldFacingCameraText
{
get => m_WorldFacingCameraText;
set => m_WorldFacingCameraText = value;
}
[SerializeField]
Text m_WorldFacingCameraText;
public Text sessionFpsText
{
get => m_SessionFpsText;
set => m_SessionFpsText = value;
}
[SerializeField]
Text m_SessionFpsText;
ARCameraManager m_CameraManager;
AREnvironmentProbeManager m_EnvironmentProbeManager;
ARFaceManager m_FaceManager;
ARMeshManager m_MeshManager;
AROcclusionManager m_OcclusionManager;
ARPlaneManager m_PlaneManager;
ARRaycastManager m_RaycastManager;
ARSession m_Session;
void Awake()
{
m_CameraManager = FindObjectOfType<ARCameraManager>();
m_EnvironmentProbeManager = FindObjectOfType<AREnvironmentProbeManager>();
m_FaceManager = FindObjectOfType<ARFaceManager>();
m_MeshManager = FindObjectOfType<ARMeshManager>();
m_OcclusionManager = FindObjectOfType<AROcclusionManager>();
m_PlaneManager = FindObjectOfType<ARPlaneManager>();
m_RaycastManager = FindObjectOfType<ARRaycastManager>();
m_Session = FindObjectOfType<ARSession>();
}
void Update()
{
bool isARSessionEnabled = m_Session && (m_Session.subsystem?.running ?? false);
bool isCameraManagerEnabled = isARSessionEnabled && m_CameraManager && (m_CameraManager.subsystem?.running ?? false);
bool isEnvironmentProbeManagerEnabled = isARSessionEnabled && m_EnvironmentProbeManager && (m_EnvironmentProbeManager.subsystem?.running ?? false);
bool isFaceManagerEnabled = isARSessionEnabled && m_FaceManager && (m_FaceManager.subsystem?.running ?? false);
bool isMeshManagerEnabled = isARSessionEnabled && m_MeshManager && (m_MeshManager.subsystem?.running ?? false);
bool isOcclusionManagerEnabled = isARSessionEnabled && m_OcclusionManager && (m_OcclusionManager.subsystem?.running ?? false);
bool isPlaneManagerEnabled = isARSessionEnabled && m_PlaneManager && (m_PlaneManager.subsystem?.running ?? false);
bool isRaycastManagerEnabled = isARSessionEnabled && m_RaycastManager && (m_RaycastManager.subsystem?.running ?? false);
SetFeatureDisplayState(m_AutoFocusText, isCameraManagerEnabled && m_CameraManager.autoFocusEnabled);
SetFeatureDisplayState(m_EnvironmentDepthText, isOcclusionManagerEnabled && m_OcclusionManager.currentEnvironmentDepthMode.Enabled());
SetFeatureDisplayState(m_EnvironmentProbesText, isEnvironmentProbeManagerEnabled);
SetFeatureDisplayState(m_FaceTrackingText, isFaceManagerEnabled && (m_FaceManager.supportedFaceCount > 0));
SetFeatureDisplayState(m_HumanDepthText, isOcclusionManagerEnabled && m_OcclusionManager.currentHumanDepthMode.Enabled());
SetFeatureDisplayState(m_HumanStencilText, isOcclusionManagerEnabled && m_OcclusionManager.currentHumanStencilMode.Enabled());
SetFeatureDisplayState(m_LightEstimationColorText, isCameraManagerEnabled && ((m_CameraManager.currentLightEstimation & LightEstimation.AmbientColor) == LightEstimation.AmbientColor));
SetFeatureDisplayState(m_LightEstimationIntensityText, isCameraManagerEnabled && ((m_CameraManager.currentLightEstimation & LightEstimation.AmbientIntensity) == LightEstimation.AmbientIntensity));
SetFeatureDisplayState(m_MeshingText, isMeshManagerEnabled);
#if UNITY_IOS && !UNITY_EDITOR
{
XRMeshSubsystem meshSubsystem = m_MeshManager?.subsystem as XRMeshSubsystem;
SetFeatureDisplayState(m_MeshingClassificationText, isMeshManagerEnabled && meshSubsystem.GetClassificationEnabled());
}
#else // UNITY_IOS && !UNITY_EDITOR
SetFeatureDisplayState(m_MeshingClassificationText, false);
#endif // UNITY_IOS && !UNITY_EDITOR
SetFeatureDisplayState(m_PlaneTrackingText, isPlaneManagerEnabled && (m_PlaneManager.currentDetectionMode != PlaneDetectionMode.None));
SetFeatureDisplayState(m_RaycastingText, isRaycastManagerEnabled);
SetFeatureDisplayState(m_RotationAndOrientationText, isARSessionEnabled && (m_Session.currentTrackingMode == TrackingMode.PositionAndRotation));
SetFeatureDisplayState(m_WorldFacingCameraText, isCameraManagerEnabled && (m_CameraManager.currentFacingDirection == CameraFacingDirection.World));
SetFeatureDisplayState(m_SessionFpsText, isARSessionEnabled);
int arFrameRate = isARSessionEnabled ? (m_Session.frameRate ?? 0) : 0;
m_SessionFpsText.text = $"AR Session FPS: {arFrameRate}";
}
void SetFeatureDisplayState(Text textUI, bool isActive)
{
textUI.color = isActive ? Color.green : Color.red;
}
}
}
正在加载...
取消
保存