summaryrefslogtreecommitdiff
path: root/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/MarkLateLatchNode.cs
blob: e5cad59c873a7b79fc2747f8c8c89f665e65153a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.OpenXR.Input;
using UnityEngine.InputSystem;

/// <summary>
/// Example code for Vulkan Late latching support. For use cases example, please check out Controller Sample - Head object, LeftHand/Aim object and RightHand/Grip object.
/// See: https://docs.unity3d.com/ScriptReference/XR.XRDisplaySubsystem.MarkTransformLateLatched.html
/// </summary>
namespace UnityEngine.XR.OpenXR.Samples.ControllerSample
{
    public class MarkLateLatchNode : MonoBehaviour
    {
        private XRDisplaySubsystem m_DisplaySubsystem = null;
        public UnityEngine.XR.XRDisplaySubsystem.LateLatchNode lateLatchNode;
        //Set one pose type InputAction for each hand to be late latched - e.g.: Aim or Grip. For head node, leave it unset.
        [SerializeField] private InputActionReference _ActionReference = null;

        // Start is called before the first frame update
        void Start()
        {
            List<XRDisplaySubsystem> subsys = new List<XRDisplaySubsystem>();
            SubsystemManager.GetSubsystems<XRDisplaySubsystem>(subsys);

            if (subsys.Count >= 1)
                m_DisplaySubsystem = subsys[0];
            if (_ActionReference != null)
            {
                bool result = OpenXRInput.TrySetControllerLateLatchAction(_ActionReference.action);
                Debug.LogFormat("TrySetControllerLateLatchAction returns {0} for action {1}.", result, _ActionReference);
            }
        }

        // Update is called once per frame
        void Update()
        {
            if (m_DisplaySubsystem != null)
            {
                transform.position += new Vector3(0.00001f, 0, 0);
                Quaternion rot = transform.rotation;
                rot.x += 0.00001f;
                transform.rotation = rot;
                m_DisplaySubsystem.MarkTransformLateLatched(transform, lateLatchNode);
            }
        }
    }
}