/// <summary>
        /// called when the object is dropped, this is just called a frame mainly it is a excuse to call RaiseOnGrabStateChangeEvent
        /// </summary>
        protected virtual void DropUpdate()
        {
            ResetActiveControllerState();
            ResetRigidBodyState();

            isUsingTwoHandGrabbable = false;

            if (grabMode == GrabMode.Physics)
            {
                ResetPhysicsState();
            }

            //some componets stop the default behaivour of this component like the VR_TwoHandGrabbable.cs
            if (!preventDefault)
            {
                ApplyControllerVelocity();
                EnableHandCollision();
                ChangeCollidersEnable(true);
                transform.SetParent(null);
            }

            lastInteractController = activeController;
            activeController       = null;

            //can be grabbed aigan
            CanInteract = true;
            TransitionToUnGrabState();
        }
        void Awake()
        {
            Controller = gameObject.GetComponent <CharacterController>();

            if (Controller == null)
            {
                Debug.LogWarning("VR_CharacterController: No CharacterController attached.");
            }

#if SDK_OCULUS
            // We use OVRCameraRig to set rotations to cameras,
            // and to be influenced by rotation
            OVRCameraRig[] CameraRigs = gameObject.GetComponentsInChildren <OVRCameraRig>();

            if (CameraRigs.Length == 0)
            {
                Debug.LogWarning("OVRPlayerController: No OVRCameraRig attached.");
            }
            else if (CameraRigs.Length > 1)
            {
                Debug.LogWarning("OVRPlayerController: More then 1 OVRCameraRig attached.");
            }
            else
            {
                CameraRig = CameraRigs[0];
            }
#endif

            InitialYRotation = transform.rotation.eulerAngles.y;

            rightController = VR_Manager.instance.RightController;
            leftController  = VR_Manager.instance.LeftController;
        }
Exemplo n.º 3
0
        public void SetHaptics(float frequency, float amplitud, VR_Controller controller)
        {
            frequency *= multiplier;
            amplitud  *= multiplier;

            if (amplitud < MIN_HAPTICS_VALUE)
            {
                amplitud = MIN_HAPTICS_VALUE;
            }

            if (Time.time - lastHapticsFeedback < rate)
            {
                return;
            }

            if (!givingFeedback)
            {
                givingFeedback = true;
            }

            lastHapticsFeedback = Time.time;
#if SDK_OCULUS
            OVRInput.SetControllerVibration(frequency, amplitud, controller.OVR_ControllerType);
#endif
#if SDK_STEAM_VR
            hapticAction.Execute(0.0f, rate, Mathf.Min(frequency * 320.0f, 320.0f), amplitud, controller.SteamControllerType);
#endif
            activeController = controller;
        }
Exemplo n.º 4
0
        public VR_Input(VR_Controller controller)
        {
            this.controller = controller;

            #if SDK_STEAM_VR
            InitializeSteamVR_Actions();
            #endif
        }
        public override void OnGrabSuccess(VR_Controller controller)
        {
            activeController = controller;
            currentGrabState = GrabState.Grab;
            RaiseOnGrabStateChangeEvent(GrabState.Grab);

            GrabController.SetVisibility(!GetCurrentHandInteractSettings().hideHandOnGrab);
        }
        public void RemoveActiveDistanceGrabController(VR_Controller controller)
        {
            if (!useDistanceGrab)
            {
                return;
            }

            activeDistanceGrabControllerList.Remove(controller);
        }
        public void AddActiveDistanceGrabController(VR_Controller controller)
        {
            if (!useDistanceGrab)
            {
                return;
            }

            activeDistanceGrabControllerList.Add(controller);
        }
        /// <summary>
        /// Get the distance to the controller
        /// </summary>
        private float GetDistanceToController(VR_Controller controller)
        {
            float     d             = float.MaxValue;
            Transform interactPoint = controller.ControllerType == VR_ControllerType.Right ? HighlightPointRightHand : HighlightPointLeftHand;

            if (controller.IsConnected && controller.CurrentGrab == null)
            {
                d = (interactPoint.position - controller.Position).magnitude;
            }

            return(d);
        }
        public VR_HandInteractSettings GetHandInteractionSettings(VR_Controller controller)
        {
            if (controller.ControllerType == VR_ControllerType.Right)
            {
                return(rightHandSettings);
            }
            if (controller.ControllerType == VR_ControllerType.Left)
            {
                return(leftHandSettings);
            }

            return(null);
        }
        public bool CanInteractUsingController(VR_Controller controller)
        {
            if (controller.ControllerType == VR_ControllerType.Right)
            {
                return(rightHandSettings.canInteract);
            }
            if (controller.ControllerType == VR_ControllerType.Left)
            {
                return(leftHandSettings.canInteract);
            }

            return(false);
        }
Exemplo n.º 11
0
        private void OnGrabStateChange(GrabState newState)
        {
            if (newState == GrabState.Grab)
            {
                grabController = grabbable.GrabController;
            }

            if (newState == GrabState.Drop)
            {
                Debug.Log("drop");
                GetComponent <Rigidbody>().isKinematic = false;
                GetComponent <Rigidbody>().AddForceAtPosition(grabController.Velocity * throwForce, grabController.transform.position);
            }
        }
        private void ResetControllerState(VR_Controller controller)
        {
            //recenter controller
            controller.Recenter();

            controller.OnJointBreakListener.RemoveAllListeners();
            FixedJoint joint = controller.GrabPoint.gameObject.GetComponent <FixedJoint>();

            if (joint != null)
            {
                Destroy(joint);
            }

            controller.CleanCurrentGrab();
        }
        //this is a feature what i am working you can ignore this function :)
        public void SetEditorGrabPositionAndRotation(VR_Controller controller)
        {
            activeController = controller;

            if (!usePerHandSettings)
            {
                leftHandSettings  = handSettings;
                rightHandSettings = handSettings;
            }

            transform.position = CalculateGrabPosition();
            transform.rotation = activeController.GrabPoint.transform.rotation * Quaternion.Euler(GetCurrentHandInteractSettings().rotationOffset);

            //SetupFixedJoint();
            transform.parent = activeController.transform;
        }
        private IEnumerator ApplyControllerVelocityRoutine(VR_Controller controller)
        {
            rb.velocity        = Vector3.zero;
            rb.angularVelocity = Vector3.zero;

            yield return(new WaitForFixedUpdate());

            controller.ApplyThrowVelocity(this);

            while (rb.velocity.magnitude < 0.25f)
            {
                yield return(new WaitForFixedUpdate());
            }

            objectWasThrow = true;
        }
Exemplo n.º 15
0
    // Start is called before the first frame update
    void Start()
    {
        animator = AurduinoControllerObj.GetComponent <Animator>();
        canShock = true;

        rightController = VRShooterKit.VR_Manager.instance.RightController;
        leftController  = VRShooterKit.VR_Manager.instance.LeftController;

        // ! Super important input from controller
        // if (rightController.Input.GetButtonDown( VRShooterKit.VR_InputButton.Button_Secondary )){
        //     // Do the thing
        // }



        //ArduinoController = AurduinoControllerObj.GetComponent<Kreation.Firmata.OnOffController>();
    }
        private void OnSecondaryGrabbableGrabStateChange(GrabState state)
        {
            if (state == GrabState.Grab)
            {
                dominantGrabbable.GrabController.UsePositionOffset = false;


                secondaryController = secondaryGrabbable.GrabController;
                Transform interactPoint = secondaryGrabbable.GetCurrentHandInteractSettings().interactPoint;

                secondaryController.SetVisibility(!secondaryGrabbable.GetCurrentHandInteractSettings().hideHandOnGrab);

                secondaryController.SetPositionControlMode(MotionControlMode.Free);
                secondaryController.SetRotationControlMode(MotionControlMode.Free);

                secondaryController.transform.parent        = interactPoint;
                secondaryController.transform.localPosition = Vector3.zero;
                secondaryController.transform.rotation      = interactPoint.rotation * Quaternion.Euler(secondaryGrabbable.GetCurrentHandInteractSettings().rotationOffset);

                if (OnTwoHandGrabStart != null)
                {
                    OnTwoHandGrabStart.Invoke();
                }
            }

            else if (state == GrabState.Drop && dominantGrabbable.CurrentGrabState == GrabState.Grab)
            {
                dominantGrabbable.GrabController.UsePositionOffset = true;

                secondaryController.SetPositionControlMode(MotionControlMode.Engine);
                secondaryController.SetRotationControlMode(MotionControlMode.Engine);

                secondaryController.SetVisibility(true);

                if (OnTwoHandGrabEnd != null)
                {
                    OnTwoHandGrabEnd.Invoke();
                }
            }
        }
Exemplo n.º 17
0
        private IEnumerator GrabRoutine(VR_Controller controller)
        {
            VR_Grabbable clone = Instantiate(grabbable, transform.position, Quaternion.identity);

            controller.ForceGrab(clone);

            MeshRenderer[] renderArray = clone.transform.GetComponentsInChildren <MeshRenderer>();

            for (int n = 0; n < renderArray.Length; n++)
            {
                renderArray[n].enabled = false;
            }

            yield return(new WaitForEndOfFrame());

            for (int n = 0; n < renderArray.Length; n++)
            {
                renderArray[n].enabled = true;
            }

            clone.gameObject.SetActive(true);
        }
 public virtual void Highlight(VR_Controller controller)
 {
     IsHighlight = true;
 }
Exemplo n.º 19
0
 private float CalculateDistanceToInteractable(VR_Controller controller, VR_Interactable interactable)
 {
     return(Vector3.Distance(controller.OriginalParent.position, interactable.transform.position));
 }
        public override void UnHighlight(VR_Controller controller)
        {
            base.UnHighlight(controller);

            outline.outlineActive = 0.0f;
        }
 public override void UnHighlight(VR_Controller controller)
 {
     ScaleTween( 1.0f );
 }
Exemplo n.º 22
0
 public override void Interact(VR_Controller controller)
 {
     StartCoroutine(GrabRoutine(controller));
 }
Exemplo n.º 23
0
 private void Awake()
 {
     controller = GetComponent <VR_Controller>();
 }
 public virtual void Interact(VR_Controller controller)
 {
     onInteractEvent.Invoke(controller);
 }
Exemplo n.º 25
0
        public void SetHaptics(float value, VR_Controller controller)
        {
            value *= multiplier;

            SetHaptics(Random.Range(value / 2.0f, value), value, controller);
        }
 public override void Interact(VR_Controller controller)
 {
     OnGrabSuccess(controller);
 }
 public bool CanHighlightUsingController(VR_Controller controller)
 {
     return(interact == null || interact.CanInteractUsingController(controller));
 }
 public VR_ControllerInfo(VR_Controller controller)
 {
     this.controller             = controller;
     interactionButtonWasPressed = false;
 }
        /// <summary>
        /// Called by VR_Input, to let know what we are grabbing this object
        /// </summary>
        /// <param name="controller"></param>
        public virtual void OnGrabSuccess(VR_Controller controller)
        {
            if (preventDefault)
            {
                activeController = controller;
                CurrentGrabState = GrabState.Grab;
                RaiseOnGrabStateChangeEvent(CurrentGrabState);
                return;
            }

            previusKinematicValue = rb.isKinematic;

            //stop this object to be interactable
            CanInteract = false;

            //set the active controller
            activeController = controller;


            if (rb != null && grabMode == GrabMode.Joint)
            {
                rb.isKinematic          = true;
                originalInterpolateMode = rb.interpolation;
                rb.interpolation        = RigidbodyInterpolation.None;
            }

            if (grabMode == GrabMode.Physics)
            {
                physicsUpdateState      = PhysicsUpdateState.NoCollision;
                previusUseGravityState  = rb.useGravity;
                previusGravityState     = rb.useGravity;
                rb.useGravity           = false;
                rb.isKinematic          = false;
                rb.useGravity           = false;
                rb.interpolation        = RigidbodyInterpolation.Interpolate;
                originalInterpolateMode = rb.interpolation;
                OverridePhysicsMaterial(zeroFrictionOrBouncinessMaterial);

                activeController.UseRotationOffset = false;
                activeController.UsePositionOffset = false;
            }



            //disable collision with the grabbable and the hand
            if (activeController.Collider != null)
            {
                IgnoreCollision(activeController.Collider);
            }


            //if this object shoudl fly to hand disable colliders while flying otherwise set desire collider state
            if (shouldFly)
            {
                //disable colliders while flying
                ChangeCollidersEnable(false);
            }
            else
            {
                ChangeCollidersEnable(enableColliderOnGrab);
            }

            //if we are using a perfect grab
            if (perfectGrab)
            {
                //parent the objects so they exist on the same space
                transform.parent = activeController.transform;
                GrabController.SetVisibility(!GetCurrentHandInteractSettings().hideHandOnGrab);
                SetupFixedJoint();

                //set the current grab state
                CurrentGrabState = GrabState.Grab;
                //raise grab state change event
                RaiseOnGrabStateChangeEvent(CurrentGrabState);
                return;
            }
            else
            {
                //set fly values
                if (shouldFly)
                {
                    grabStartTime     = Time.time;
                    grabStartPosition = transform.position;
                    grabStartRotation = transform.rotation;
                }

                else
                {
                    SetFinalGrabState();
                }

                CurrentGrabState = shouldFly ? GrabState.Flying : GrabState.Grab;
            }


            //raise the event
            RaiseOnGrabStateChangeEvent((shouldFly ? GrabState.Flying : GrabState.Grab));
        }
 public virtual void UnHighlight(VR_Controller controller)
 {
     IsHighlight = false;
 }