bool manusIsConnected(IEntity entity) { var vrGloveHand = entity.GetComponent <IF_VR_Glove_Hand>(); HandDataManager.EnsureLoaded(); var deviceType = vrGloveHand.Type == IF_VR_HandType.Left ? device_type_t.GLOVE_LEFT : device_type_t.GLOVE_RIGHT; vrGloveHand.Connected = Manus.ManusIsConnected(HandDataManager.ManusSession, deviceType); return(vrGloveHand.Connected); }
public bool GetGrabStateUp(IF_VR_HandType handType) { var handData = HandDataManager.GetHandData(handType == IF_VR_HandType.Left ? ManusVR.SDK.Apollo.device_type_t.GLOVE_LEFT : ManusVR.SDK.Apollo.device_type_t.GLOVE_RIGHT); if (handData == null) { return(false); } return(handData.GetGrabStateUp()); }
public void Setup(IEntity entity) { var subscriptions = new List <IDisposable>(); subscriptionsPerEntity.Add(entity, subscriptions); eventSystem.Receive <IF_VR_Event_OnAttachedToHand>().Subscribe(evt => { var hand = evt.HandEntity.GetComponent <IF_VR_Hand>(); var steamVRHand = convertSteamVRHand(hand); var gloveHand = entity.GetComponent <IF_VR_Glove_Hand>(); if (hand.Type == gloveHand.Type) { steamVRHand.Show(); if (gloveHand.RenderModel) { gloveHand.RenderModel.SetActive(false); } } }).AddTo(subscriptions); eventSystem.Receive <IF_VR_Event_OnDetachedToHand>().Subscribe(evt => { var hand = evt.HandEntity.GetComponent <IF_VR_Hand>(); var steamVRHand = convertSteamVRHand(hand); var gloveHand = entity.GetComponent <IF_VR_Glove_Hand>(); if (hand.Type == gloveHand.Type) { steamVRHand.Hide(); if (gloveHand.RenderModel) { gloveHand.RenderModel.SetActive(true); } } }).AddTo(subscriptions); Observable.EveryUpdate() .Where(x => manusIsConnected(entity) && HandDataManager.IsInitialised) .First() .Subscribe(x => { var vrGloveHand = entity.GetComponent <IF_VR_Glove_Hand>(); var gloveHandType = vrGloveHand.Type; var vrGloveView = entity.GetGameObject(); // create wrist and setup var pool = entityDatabase.GetCollection(); var wristEntity = pool.CreateEntity(); vrGloveHand.Wrist.gameObject.LinkEntity(wristEntity, pool); var wristView = wristEntity.GetGameObject(); var wrist = wristEntity.AddComponent <IF_VR_Glove_Wrist>(); wrist.Type = gloveHandType; vrGloveHand.WristEntity = wristEntity; // instaniate render model prefab var prefab = gloveHandType == IF_VR_HandType.Left ? IF_VR_Steam_Player.instance.leftHand.renderModelPrefab : IF_VR_Steam_Player.instance.rightHand.renderModelPrefab; var parent = wristView.transform; var instance = gameObjectTool.InstantiateWithInit(prefab, parent); var skeleton = instance.GetComponentInChildren <SteamVR_Behaviour_Skeleton>(); var manusRigger = vrGloveView.AddComponent <ManusRigger>(); var handRig = gloveHandType == IF_VR_HandType.Left ? manusRigger.LeftHand = new HandRig() : manusRigger.RightHand = new HandRig(); handRig.WristTransform = vrGloveHand.Wrist; handRig.Thumb.Proximal = skeleton.thumbProximal; handRig.Thumb.Intermedial = skeleton.thumbMiddle; handRig.Thumb.Distal = skeleton.thumbDistal; handRig.Index.Proximal = skeleton.indexProximal; handRig.Index.Intermedial = skeleton.indexMiddle; handRig.Index.Distal = skeleton.indexDistal; handRig.Middle.Proximal = skeleton.middleProximal; handRig.Middle.Intermedial = skeleton.middleMiddle; handRig.Middle.Distal = skeleton.middleDistal; handRig.Ring.Proximal = skeleton.ringProximal; handRig.Ring.Intermedial = skeleton.ringMiddle; handRig.Ring.Distal = skeleton.ringDistal; handRig.Pinky.Proximal = skeleton.pinkyProximal; handRig.Pinky.Intermedial = skeleton.pinkyMiddle; handRig.Pinky.Distal = skeleton.pinkyDistal; var skeletonRoot = skeleton.root; if (skeleton.mirroring == SteamVR_Behaviour_Skeleton.MirrorType.RightToLeft) { skeletonRoot.localRotation = Quaternion.Euler(0, 90, -90); } else { skeletonRoot.localRotation = Quaternion.Euler(0, 90, 90); } var hand = wristView.AddComponent <ManusVR.Hands.Hand>(); hand.DeviceType = gloveHandType == IF_VR_HandType.Left ? device_type_t.GLOVE_LEFT : device_type_t.GLOVE_RIGHT; hand.Initialize(manusRigger); GameObject.Destroy(skeleton); GameObject.Destroy(instance.GetComponentInChildren <Animator>()); // follow tracker var vrHandTrackerEntity = vrInterface.GetHandTrackerEntity(gloveHandType); pool.CreateEntity(new IF_FollowEntityBlueprint(IF_UpdateMomentType.Update, vrHandTrackerEntity, entity, true, true, new Vector3(0.0f, 0.07f, -0.04f), Vector3.zero)); var vrHandEntity = vrInterface.GetHandEntity(gloveHandType); var vrHand = vrHandEntity.GetComponent <IF_VR_Hand>(); var followEntityEntities = entityDatabase.GetEntitiesFor(new Group(typeof(IF_FollowEntity)), 0); foreach (var followEntityEntity in followEntityEntities) { var followEntity = followEntityEntity.GetComponent <IF_FollowEntity>(); if (followEntity.FollowSourceEntity.HasComponent <IF_VR_Hand>()) { var vrHandSource = followEntity.FollowSourceEntity.GetComponent <IF_VR_Hand>(); if (vrHandSource.Type == vrGloveHand.Type) { followEntity.FollowTargetEntity = wristEntity; if (vrHand.Type == IF_VR_HandType.Left) { followEntity.OffsetPosition = new Vector3(-0.14f, 0.03f, -0.08f); followEntity.OffsetRotation = new Vector3(0.0f, -135.0f, 90.0f); } else { followEntity.OffsetPosition = new Vector3(0.14f, -0.03f, 0.08f); followEntity.OffsetRotation = new Vector3(0.0f, 45.0f, 90.0f); } break; } } } if (gloveHandType == IF_VR_HandType.Left) { IF_VR_Steam_Player.instance.leftHand.Hide(); } else if (gloveHandType == IF_VR_HandType.Right) { IF_VR_Steam_Player.instance.rightHand.Hide(); } vrGloveHand.RenderModel = instance; vrGloveHand.Active.Value = true; }).AddTo(subscriptions); Observable.EveryUpdate() .Where(x => vrGloveIsActivated(entity) && HandDataManager.IsPlayerNumberValid(vrGloveInterface.PlayerNumber)) .Subscribe(x => { var vrGloveHand = entity.GetComponent <IF_VR_Glove_Hand>(); var vrGloveHandView = entity.GetGameObject(); var wristEntity = vrGloveHand.WristEntity; var wristView = wristEntity.GetGameObject(); var hand = wristView.GetComponent <Hand>(); if (HandDataManager.CanGetHandData(vrGloveInterface.PlayerNumber, hand.DeviceType)) { var yaw = IF_VR_Steam_Player.instance.trackingOriginTransform.localEulerAngles.y; if (hand.DeviceType == device_type_t.GLOVE_LEFT) { hand.WristYaw = 180 - yaw; } else { hand.WristYaw = 180 + yaw; } ApolloHandData handData = HandDataManager.GetHandData(vrGloveInterface.PlayerNumber, hand.DeviceType); hand.AnimateHand(handData); hand.UpdateHand(handData); } if (vrGloveHandView.activeSelf) { bool state = manusIsConnected(entity); if (!state && vrGloveHand.GoingToDisconnect == false) { vrGloveHand.GoingToDisconnect = true; vrGloveHand.DisconnectStateTimer = 0.0f; } } else { bool state = manusIsConnected(entity); if (state) { vrGloveHandView.SetActive(true); } } if (vrGloveHand.GoingToDisconnect) { vrGloveHand.DisconnectStateTimer += Time.deltaTime; bool state = manusIsConnected(entity); if (state) { vrGloveHand.GoingToDisconnect = false; } else if (vrGloveHand.DisconnectStateTimer >= IF_VR_Glove_Hand.MaxDisconnectStateTimeSeconds) { vrGloveHandView.SetActive(false); vrGloveHand.GoingToDisconnect = false; } } }).AddTo(subscriptions); }