void Start() { if (provider == null) { provider = GetComponent <LeapXRServiceProvider>(); if (provider == null) { Debug.LogError("No Valid LeapXRServiceProvider"); } } }
void Awake() { if (cam == null) { cam = this.transform.GetChild(0).gameObject; } if (leap == null) { leap = this.transform.GetChild(0).GetComponent <LeapXRServiceProvider>(); } }
// Update is called once per frame void Update() { controller = new LeapXRServiceProvider(); Frame frame = controller.GetLeapController().Frame(); List <Hand> hands = frame.Hands; Hand leftHand = new Hand(); bool leftHandExist = false; Hand rightHand = new Hand(); bool rightHandExist = false; foreach (Hand hand in hands) { if (hand.IsLeft) { leftHand = hand; setText(hand, leftHandInfo); leftHandExist = true; } else { rightHand = hand; setText(hand, rightHandInfo); rightHandExist = true; } } if (leftHandExist & rightHandExist) { //check gesture models states gestureSplit.Check(leftHand, rightHand, Time.deltaTime); gestureClap.Check(leftHand, rightHand, Time.deltaTime); } if (leftHandExist & !rightHandExist) { gestureLeftSwap.Check(leftHand, null, Time.deltaTime); gestureRightSwap.Check(leftHand, null, Time.deltaTime); gestureUpSwap.Check(leftHand, null, Time.deltaTime); gestureDownSwap.Check(leftHand, null, Time.deltaTime); gestureGrab.Check(leftHand, null, Time.deltaTime); gesturePinch.Check(leftHand, null, Time.deltaTime); } if (!leftHandExist & rightHandExist) { gestureLeftSwap.Check(null, rightHand, Time.deltaTime); gestureRightSwap.Check(null, rightHand, Time.deltaTime); gestureUpSwap.Check(null, rightHand, Time.deltaTime); gestureDownSwap.Check(null, rightHand, Time.deltaTime); gestureGrab.Check(null, rightHand, Time.deltaTime); gesturePinch.Check(null, rightHand, Time.deltaTime); } }
void Awake() { LeapXRServiceProvider provider = FindObjectOfType <LeapXRServiceProvider>(); XRSettings.enabled = enableVR; if (enableVR) { provider.deviceOrigin = GameObject.Find("VRLeapOrigin").transform; } else { provider.deviceOrigin = GameObject.Find("DesktopLeapOrigin").transform; } }
void Start() { _provider = GetComponent <LeapXRServiceProvider>(); Vector4 setting = new Vector4(_provider.deviceOffsetXAxis, _provider.deviceOffsetYAxis, _provider.deviceOffsetZAxis, _provider.deviceTiltXAxis); if (GetSavedOffset(ref setting)) { _lastSetting = _cachedSetting = setting; Debug.Log("retrieved saved offset"); _provider.deviceOffsetXAxis = setting.x; _provider.deviceOffsetYAxis = setting.y; _provider.deviceOffsetZAxis = setting.z; _provider.deviceTiltXAxis = setting.w; } }
/// <inheritdoc /> public override void Enable() { base.Enable(); if (leapControllerOrientation == LeapControllerOrientation.Headset) { // If the leap controller is mounted on a headset then add the LeapXRServiceProvider to the scene // The LeapXRServiceProvider can only be attached to a camera LeapMotionServiceProvider = CameraCache.Main.gameObject.AddComponent <LeapXRServiceProvider>(); LeapXRServiceProvider leapXRServiceProvider = LeapMotionServiceProvider as LeapXRServiceProvider; // Allow modification of VR specific offset modes if the leapControllerOrientation is Headset // These settings mirror the modification of the properties exposed in the inspector within the LeapXRServiceProvider attached // to the main camera if (leapVRDeviceOffsetMode == LeapVRDeviceOffsetMode.ManualHeadOffset) { // Change the offset mode before setting the properties leapXRServiceProvider.deviceOffsetMode = LeapXRServiceProvider.DeviceOffsetMode.ManualHeadOffset; leapXRServiceProvider.deviceOffsetYAxis = SettingsProfile.LeapVRDeviceOffsetY; leapXRServiceProvider.deviceOffsetZAxis = SettingsProfile.LeapVRDeviceOffsetZ; leapXRServiceProvider.deviceTiltXAxis = SettingsProfile.LeapVRDeviceOffsetTiltX; } else if (leapVRDeviceOffsetMode == LeapVRDeviceOffsetMode.Transform) { if (SettingsProfile.LeapVRDeviceOrigin != null) { leapXRServiceProvider.deviceOffsetMode = LeapXRServiceProvider.DeviceOffsetMode.Transform; leapXRServiceProvider.deviceOrigin = SettingsProfile.LeapVRDeviceOrigin; } else { Debug.LogError("The Leap VR Device Origin Transform was not set in the LeapMotionDeviceManagerProfile and is null."); } } } if (leapControllerOrientation == LeapControllerOrientation.Desk) { // Create a separate gameobject if the leap controller is on the desk GameObject leapProvider = new GameObject("LeapProvider"); // The LeapServiceProvider does not need to be attached to a camera, but the location of this gameobject is the anchor for the desk hands LeapMotionServiceProvider = leapProvider.AddComponent <LeapServiceProvider>(); // Follow the transform of the main camera by adding the service provider as a child of the main camera leapProvider.transform.parent = CameraCache.Main.transform; // Apply hand position offset, an offset is required to render the hands in view and in front of the camera LeapMotionServiceProvider.transform.position += leapHandsOffset; } // Add the attachment hands to the scene for the purpose of getting the tracking state of each hand and joint positions GameObject leapAttachmentHandsGameObject = new GameObject("LeapAttachmentHands"); leapAttachmentHands = leapAttachmentHandsGameObject.AddComponent <AttachmentHands>(); // The first hand in attachmentHands.attachmentHands is always left leftAttachmentHand = leapAttachmentHands.attachmentHands[0]; // The second hand in attachmentHands.attachmentHands is always right rightAttachmentHand = leapAttachmentHands.attachmentHands[1]; // Enable all attachment point flags in the leap hand. By default, only the wrist and the palm are enabled. foreach (TrackedHandJoint joint in Enum.GetValues(typeof(TrackedHandJoint))) { leapAttachmentHands.attachmentPoints |= LeapMotionArticulatedHand.ConvertMRTKJointToLeapJoint(joint); } }