using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections.Generic;
 
public class HandMouseController : MonoBehaviour
{
    
    [SerializeField] RectTransform[] cursors;
 
    private void Update()
    {
        bool hasHandCursor = false;
 
        for (int i = 0; i < handInfos.Length; i++)
        {
            {
                
                    continue;
 
                Vector3 screenPosition = GetCursorScreenPosition(i);
                cursors[i].position = screenPosition;
 
                
 
                HandleInteractionUI(screenPosition, clicked);
                hasHandCursor = true;
            }
        }
 
        
        if (!hasHandCursor)
        {
            EventSystem.current.SetSelectedGameObject(null);
        }
    }
 
    
    private Vector3 GetCursorScreenPosition(int handIndex)
    {
        
        Vector3 pos1 = joints[4].transform.position;
        Vector3 pos2 = joints[8].transform.position;
        Vector3 middle = (pos1 + pos2) / 2;
        Vector3 position = Camera.main.WorldToScreenPoint(middle);
        return position;
    }
 
    private bool HandleInteractionUI(Vector3 screenPosition, bool click)
    {
        
        PointerEventData pointerEventData = new PointerEventData(EventSystem.current) { position = screenPosition };
        List<RaycastResult> results = new List<RaycastResult>();
        EventSystem.current.RaycastAll(pointerEventData, results);
 
        
        foreach (RaycastResult result in results)
        {
            if (result.gameObject.TryGetComponent(out Button button))
            {
                EventSystem.current.SetSelectedGameObject(button.gameObject);
                if (click)
                {
                    button.onClick.Invoke();
                }
                return true;
            }
        }
 
        
        EventSystem.current.SetSelectedGameObject(null);
        return false;
    }
}
HandInfo[] HandInfos
Definition ManoMotionManagerBase.cs:81
bool TryGetHandInfo(LeftOrRightHand leftRight, out HandInfo handInfo)
Returns true and gives back the hand info of the left/right hand specified.
Definition ManoMotionManagerBase.cs:306
The ManomotionManager handles the communication with the SDK.
Definition ManoMotionManager.cs:13
static ManoMotionManager Instance
Definition ManoMotionManager.cs:19
Handles the visualization of the skeleton joints.
Definition SkeletonManager.cs:16
List< GameObject > jointsSecond
Definition SkeletonManager.cs:22
static SkeletonManager instance
Definition SkeletonManager.cs:40
Definition CameraChangeListener.cs:5
LeftOrRightHand
Definition GestureInfo.cs:58
ManoGestureContinuous
Similar to Manoclass Continuous Gestures are Gesture Information that is being updated on every frame...
Definition GestureInfo.cs:47
ManoGestureTrigger
Trigger Gestures are a type of Gesture Information retrieved for a given frame when the user perfoms ...
Definition GestureInfo.cs:30
ManoGestureTrigger manoGestureTrigger
Trigger gestures are those that happen in one frame.
Definition GestureInfo.cs:165
Contains information about the hand.
Definition HandInfo.cs:23
GestureInfo gestureInfo
Information about hand gestures.
Definition HandInfo.cs:32