#if USING_MRTK2 || USING_MRTK3


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

#if USING_MRTK3
    using Microsoft.MixedReality.Toolkit.SpatialManipulation;
#endif

# if USING_MRTK2
    using Microsoft.MixedReality.Toolkit.Utilities.Solvers;
#endif

namespace SimplifyXR
{
    public class MRTK2_3HandMenuEvents : MonoBehaviour
    {
        public void Start()
        {
            var elements = this.GetComponentInChildren<ElementRoot>();

#if USING_MRTK2
            var handConstraintMRTK2 = this.GetComponent<Microsoft.MixedReality.Toolkit.Utilities.Solvers.HandConstraintPalmUp>();

            handConstraintMRTK2?.OnFirstHandDetected.AddListener(() => elements.gameObject.SetActive(true));
            handConstraintMRTK2?.OnLastHandLost.AddListener(() => elements.gameObject.SetActive(false));
#endif

#if USING_MRTK3
            var handConstraint = this.GetComponent<Microsoft.MixedReality.Toolkit.SpatialManipulation.HandConstraintPalmUp>();

            handConstraint?.OnFirstHandDetected.AddListener(() => elements.gameObject.SetActive(true));
            handConstraint?.OnLastHandLost.AddListener(() => elements.gameObject.SetActive(false));
#endif

        }

        public void OnDestroy()
        {
#if USING_MRTK2
            var handConstraintMRTK2 = this.GetComponent<Microsoft.MixedReality.Toolkit.Utilities.Solvers.HandConstraintPalmUp>();
            handConstraintMRTK2?.OnFirstHandDetected.RemoveAllListeners();
#endif

#if USING_MRTK3
            var handConstraint = this.GetComponent<Microsoft.MixedReality.Toolkit.SpatialManipulation.HandConstraintPalmUp>();
            handConstraint?.OnFirstHandDetected.RemoveAllListeners();
#endif
        }

    }
}

#endif
