コード例 #1
0
        public override void Interact(HandVR handVR)
        {
            base.Interact(handVR);

            if (handVR.GrabDown())
            {
                initialMappingOffset = linearMapping.value - CalculateLinearMapping(handVR.transform);
                sampleCount          = 0;
                mappingChangeRate    = 0.0f;

                Interacting = true;
            }

            if (handVR.GrabUp())
            {
                CalculateMappingChangeRate();

                Interacting = false;
            }

            if (handVR.Grab())
            {
                if (Interacting)
                {
                    UpdateLinearMapping(handVR.transform);
                }
            }
        }
コード例 #2
0
ファイル: Grabbable.cs プロジェクト: helloMike/SimpleVR
        /// <summary>
        /// Gives velocity to Rigidbody
        /// </summary>
        /// <param name="rb"></param>
        /// <param name="handVR"></param>
        private void AdjustPhysicsWithPhysicsTracker(HandVR handVR)
        {
            Rigidbody.isKinematic            = false;   //Slot Store method set Grabbables as kinematic
            Rigidbody.interpolation          = RigidbodyInterpolation.Interpolate;
            Rigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous;
            Rigidbody.useGravity             = true;

            Vector3 position        = Vector3.zero;
            Vector3 velocity        = Vector3.zero;
            Vector3 angularVelocity = Vector3.zero;


            Rigidbody.velocity        = handVR.Velocity;
            Rigidbody.angularVelocity = handVR.AngularVelocity;

            // Make the object travel at the release velocity for the amount
            // of time it will take until the next fixed update, at which
            // point Unity physics will take over
            float timeUntilFixedUpdate = (Time.fixedDeltaTime + Time.fixedTime) - Time.time;

            transform.position += timeUntilFixedUpdate * velocity;
            float   angle = Mathf.Rad2Deg * angularVelocity.magnitude;
            Vector3 axis  = angularVelocity.normalized;

            transform.rotation *= Quaternion.AngleAxis(angle * timeUntilFixedUpdate, axis);

            StartCoroutine(EndAdjustPhysicsWithPhysicsTracker());
        }
コード例 #3
0
ファイル: Slot.cs プロジェクト: helloMike/SimpleVR
        public override void Interact(HandVR handVR)
        {
            base.Interact(handVR);

            if (handVR.GrabDown() && AttachedGrabbable)
            {
                AttachedGrabbable.Attach(handVR);
            }
        }
コード例 #4
0
        public virtual void Unhover(HandVR handVR, bool affectChildren = true)
        {
            hoverHands.Remove(handVR);

            if (hoverHands.Count == 0)
            {
                Hovered = false;
                OnUnhovered?.Invoke(handVR);
            }
        }
コード例 #5
0
        //don't like it
        //public override void Hover(HandVR handVR, bool affectChildren = true)
        //{
        //	base.Hover(handVR, affectChildren);

        //	if (handVR.Grab())
        //	{
        //		Debug.Log("down");
        //		initialMappingOffset = linearMapping.value - CalculateLinearMapping(handVR.transform);
        //		sampleCount = 0;
        //		mappingChangeRate = 0.0f;

        //		Interacting = true;
        //	}
        //}

        public override void Unhover(HandVR handVR, bool affectChildren = true)
        {
            base.Unhover(handVR, affectChildren);

            if (!Interacting || hoverHands.Count != 0)
            {
                return;
            }

            CalculateMappingChangeRate();

            Interacting = false;
        }
コード例 #6
0
ファイル: Grabbable.cs プロジェクト: helloMike/SimpleVR
        public override void Interact(HandVR handVR)
        {
            base.Interact(handVR);

            if (handVR.GrabDown() && (!Attached || handVR != OwnerHandVR))
            {
                Attach(handVR);
            }
            else if (!handVR.Grab() && Attached && handVR == OwnerHandVR && !Overlapping)               //!handVR.Interact() instead of handVR.InteractUp() because it works if hand did the interactUp inside a wall and then it went out so it wasn't Blocked anymore
            {
                Detach();
            }
        }
コード例 #7
0
ファイル: Grabbable.cs プロジェクト: helloMike/SimpleVR
        private bool TryStore(HandVR handVR)
        {
            if (handVR.HoveredInteractable == null)
            {
                return(false);
            }

            Slot slot = handVR.HoveredInteractable.GetComponent <Slot>();

            if (slot == null || slot.SlotType != attachmentTypeName)
            {
                return(false);
            }

            slot.Store(this, OwnerHandVR.CharacterVR);
            OwnerSlot = slot;

            return(true);
        }
コード例 #8
0
ファイル: Grabbable.cs プロジェクト: helloMike/SimpleVR
        public void AddTrackedPoseDriver(HandVR handVR, Vector3 attachPositionOffset, Quaternion attachRotationOffset)
        {
            transform.parent = null;

            transform.position = Vector3.zero;
            transform.rotation = Quaternion.identity;

            //TrackedPoseDriver tpd = gameObject.AddComponent<TrackedPoseDriver>();
            //Just in case... check if already has a trackedPoseProvider
            TrackedPoseDriver tpd = gameObject.GetComponent <TrackedPoseDriver>();

            if (!tpd)
            {
                tpd = gameObject.AddComponent <TrackedPoseDriver>();
            }
            tpd.UseRelativeTransform = true;

            handVR.PoseProvider.AttachPositionOffset = attachPositionOffset;
            handVR.PoseProvider.AttachRotationOffset = attachRotationOffset;
            tpd.poseProviderComponent = handVR.PoseProvider;
        }
コード例 #9
0
 public static Vector2 Move(this HandVR handVR)
 {
     return(SteamVR_Actions.SimpleVR_Ingame.Move.GetAxis(GetSteamVRInputSource(handVR)));
 }
コード例 #10
0
 public static bool TurnRightUp(this HandVR handVR)
 {
     return(SteamVR_Actions.SimpleVR_Ingame.TurnRight.GetStateUp(GetSteamVRInputSource(handVR)));
 }
コード例 #11
0
 public static bool TurnLeftDown(this HandVR handVR)
 {
     return(SteamVR_Actions.SimpleVR_Ingame.TurnLeft.GetStateDown(GetSteamVRInputSource(handVR)));
 }
コード例 #12
0
 public static bool TurnAround(this HandVR handVR)
 {
     return(SteamVR_Actions.SimpleVR_Ingame.TurnAround.GetState(GetSteamVRInputSource(handVR)));
 }
コード例 #13
0
 private static bool TriggerUp(this HandVR handVR)
 {
     return(handVR.IsLeft ? LeftTriggerButton.Up : RightTriggerButton.Up);
 }
コード例 #14
0
 public virtual void Hover(HandVR handVR, bool affectChildren = true)
 {
     hoverHands.Add(handVR);
     Hovered = true;
     OnHovered?.Invoke(handVR);
 }
コード例 #15
0
 public static bool BackUp(this HandVR handVR)
 {
     return(SteamVR_Actions.SimpleVR_Menu.Back.GetStateUp(GetSteamVRInputSource(handVR)));
 }
コード例 #16
0
ファイル: Grabbable.cs プロジェクト: helloMike/SimpleVR
        public void Attach(HandVR handVR, bool iterateAttachmentPoint = false)
        {
            //Debug.Log("Attach: " + this, gameObject);

            // TO DO: Test if not necessary I did it because maybe detach events are important. But attach should let things as they should be.
            if (Attached)
            {
                //True to avoid possible attach to Slot. Imagine you get from one hand to the other but the from hand is hovering a slot. then the detach will attach grabbable to the slot and then attach to the new hand making a strange effect
                Detach(true);
            }
            else if (Stored)
            {
                TryUnstore(OwnerSlot);
            }

            if (iterateAttachmentPoint)
            {
                currentAttachmentPointIndex++;
            }
            if (currentAttachmentPointIndex == attachmentPoints.Count)
            {
                currentAttachmentPointIndex = 0;
            }

            transform.DOKill();
            transform.parent         = handVR.transform;
            OwnerHandVR              = handVR; //Important to do this and next line before real physic attach (position and rotation) to be able to detach from it if other hand steal it on the fly to the hand
            handVR.AttachedGrabbable = this;
            DisableColliders();                //Disable collider to avoid not desired collisions on attach

            Vector3    attachPositionOffset = Vector3.zero;
            Quaternion attachRotationOffset = Quaternion.identity;

            GetLocalAttachmentPositionAndRotation(handVR.transform, out attachPositionOffset, out attachRotationOffset, handVR.AttachmentPointName.name, iterateAttachmentPoint);

            float attachTime = DataVR.Instance.grabbable.attachTime;

            transform.DOLocalMove(-attachPositionOffset, attachTime).SetEase(Ease.OutSine);
            transform.DOLocalRotate(-attachRotationOffset.eulerAngles, attachTime).SetEase(Ease.OutSine).OnComplete
            (
                () =>
            {
                PhysicsExt.IgnoreCollisions(OwnerHandVR.CharacterVR.CharacterController, Colliders); //Ignore Collisions between this and CharacterVR
                EnableColliders();                                                                   //Enable collider (disabled above, before tween attach) WARNING. it is detected by ontriggerenter of physicsproximityAdjust

                //TrackedPoseDriver approach
                {
                    ////Set final position
                    ////-------------------------------------------------
                    //if (attachmentPoints.Count == 0 || (handVR.AttachmentPointName.name == "" && iterateAttachmentPoint == false))
                    //{
                    //	transform.localPosition = Vector3.zero;
                    //	transform.localRotation = Quaternion.identity;
                    //}
                    //else
                    //{
                    //	transform.localPosition = -attachPositionOffset;
                    //	transform.localRotation = Quaternion.Inverse(attachRotationOffset);
                    //}
                    ////-------------------------------------------------
                }

                //SLOT: as it could be in a slot make it kinematic again
                Rigidbody.interpolation          = RigidbodyInterpolation.None;
                Rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
                //TrackedPoseDriver approach
                {
                    //Original approach
                    //Rigidbody.isKinematic = true;

                    AddTrackedPoseDriver(handVR, attachPositionOffset, attachRotationOffset);
                }
                Rigidbody.useGravity = false;

                state = BelongState.Attached;

                //Events
                OnAttached?.Invoke(handVR);

#if UNITY_EDITOR
                Debug.Log("Attach Grabbable: " + this + " to HandVR: " + handVR, gameObject);
#endif
            }
            );
        }
コード例 #17
0
 public static bool Menu(this HandVR handVR)
 {
     return(SteamVR_Actions.SimpleVR_Menu.Menu.GetState(GetSteamVRInputSource(handVR)));
 }
コード例 #18
0
 //Controller interactions
 //-----------------------------------------------------------
 private static bool Trigger(this HandVR handVR)
 {
     return(handVR.IsLeft ? LeftTriggerButton.Get : RightTriggerButton.Get);
 }
コード例 #19
0
 public static bool EnterDown(this HandVR handVR)
 {
     return(SteamVR_Actions.SimpleVR_Menu.Enter.GetStateDown(GetSteamVRInputSource(handVR)));
 }
コード例 #20
0
 public virtual void Interact(HandVR handVR)
 {
     OnInteract?.Invoke(handVR);
 }
コード例 #21
0
 /// <summary>
 /// Trigger the haptics at a certain time for a certain length
 /// </summary>
 /// <param name="handVR">The HandVR, which device you would like to execute the haptic action.</param>
 /// <param name="secondsFromNow">How long from the current time to execute the action (in seconds - can be 0)</param>
 /// <param name="durationSeconds">How long the haptic action should last (in seconds)</param>
 /// <param name="frequency">How often the haptic motor should bounce (0 - 320 in hz. The lower end being more useful)</param>
 /// <param name="amplitude">How intense the haptic action should be (0 - 1)</param>
 public static void Haptic(this HandVR handVR, float secondsFromNow, float durationSeconds, float frequency, float amplitude)
 {
     Haptic(secondsFromNow, durationSeconds, frequency, amplitude, Input.GetSteamVRInputSource(handVR));
 }
コード例 #22
0
 private void OnDetached(HandVR handVR)
 {
     onDetached.Invoke();
 }
コード例 #23
0
 private static bool TriggerDown(this HandVR handVR)
 {
     return(handVR.IsLeft ? LeftTriggerButton.Down : RightTriggerButton.Down);
 }
コード例 #24
0
 private void OnUnhovered(HandVR handVR)
 {
     onUnhovered.Invoke();
 }
コード例 #25
0
        //public SteamVR_Input_Sources sources;
        //public SteamVR_Action_Boolean action;

        //private void OnEnable()
        //{
        //	if (action == null)
        //	{
        //		Debug.LogError("No test action assigned");
        //		return;
        //	}

        //	action.AddOnChangeListener(OnTestActionChange, sources);
        //}

        //private void OnDisable()
        //{
        //	if (action != null)
        //		action.RemoveOnChangeListener(OnTestActionChange, sources);
        //}

        //private void OnTestActionChange(SteamVR_Action_In actionIn)
        //{
        //	if (action.GetStateDown(sources))
        //	{
        //		Debug.Log("pressed down");
        //	}
        //}
        #endregion

        public static SteamVR_Input_Sources GetSteamVRInputSource(HandVR handVR)
        {
            return(handVR.IsLeft ? SteamVR_Input_Sources.LeftHand : SteamVR_Input_Sources.RightHand);
        }
コード例 #26
0
 public static bool GrabUp(this HandVR handVR)
 {
     //return handVR.TriggerUp();	//Pure Unity System
     return(SteamVR_Actions.SimpleVR_Ingame.Grab.GetStateUp(GetSteamVRInputSource(handVR)));
 }