/// <summary>
    /// When object is created, set up Animations and VRTK Interactions
    /// </summary>
    ///
    private void Awake()
    {
        interactObject = gameObject.AddComponent(typeof(VRTK_InteractableObject)) as VRTK_InteractableObject;
        VRTK_InteractHaptics interactHaptics = gameObject.AddComponent(typeof(VRTK_InteractHaptics)) as VRTK_InteractHaptics;

        VRTK.GrabAttachMechanics.VRTK_ChildOfControllerGrabAttach         grabAttach  = gameObject.AddComponent(typeof(VRTK.GrabAttachMechanics.VRTK_ChildOfControllerGrabAttach)) as VRTK.GrabAttachMechanics.VRTK_ChildOfControllerGrabAttach;
        VRTK.SecondaryControllerGrabActions.VRTK_SwapControllerGrabAction grabAction  = gameObject.AddComponent(typeof(VRTK.SecondaryControllerGrabActions.VRTK_SwapControllerGrabAction)) as VRTK.SecondaryControllerGrabActions.VRTK_SwapControllerGrabAction;
        VRTK.SecondaryControllerGrabActions.VRTK_AxisScaleGrabAction      scaleAction = gameObject.AddComponent(typeof(VRTK.SecondaryControllerGrabActions.VRTK_AxisScaleGrabAction)) as VRTK.SecondaryControllerGrabActions.VRTK_AxisScaleGrabAction;
        //VRTK.VRTK_SlideObjectControlAction slide = gameObject.AddComponent(typeof(VRTK.VRTK_SlideObjectControlAction)) as VRTK.VRTK_SlideObjectControlAction;
        //VRTK.VRTK_TouchpadControl control = gameObject.AddComponent(typeof(VRTK.VRTK_TouchpadControl)) as VRTK.VRTK_TouchpadControl;
        Rigidbody rigidBody = gameObject.AddComponent(typeof(Rigidbody)) as Rigidbody;

        interactObject.isGrabbable               = true;
        interactObject.holdButtonToGrab          = false;
        interactObject.grabAttachMechanicScript  = grabAttach;
        interactObject.secondaryGrabActionScript = scaleAction;

        interactObject.InteractableObjectUngrabbed += InteractObject_InteractableObjectUngrabbed;;

        grabAttach.precisionGrab = true;

        rigidBody.useGravity  = false;
        rigidBody.isKinematic = true;

        scaleAction.lockAxis       = new Vector3State(false, false, true);
        scaleAction.uniformScaling = true;
    }
Example #2
0
        public static void CopyControllerHaptics()
        {
            if (Selection.activeGameObject == null)
            {
                return;
            }
            VRTK_InteractHaptics hapticsToCopy = Selection.activeGameObject.GetComponent <VRTK_InteractHaptics>();

            object[] objs = Object.FindObjectsOfType(typeof(VRTK_InteractHaptics));
            foreach (VRTK_InteractHaptics haptics in objs)
            {
                haptics.clipOnTouch     = hapticsToCopy.clipOnTouch;
                haptics.strengthOnTouch = hapticsToCopy.strengthOnTouch;
                haptics.durationOnTouch = hapticsToCopy.durationOnTouch;
                haptics.intervalOnTouch = hapticsToCopy.intervalOnTouch;

                haptics.clipOnGrab     = hapticsToCopy.clipOnGrab;
                haptics.strengthOnGrab = hapticsToCopy.strengthOnGrab;
                haptics.durationOnGrab = hapticsToCopy.durationOnGrab;
                haptics.intervalOnGrab = hapticsToCopy.intervalOnGrab;

                haptics.clipOnUse     = hapticsToCopy.clipOnUse;
                haptics.strengthOnUse = hapticsToCopy.strengthOnUse;
                haptics.durationOnUse = hapticsToCopy.durationOnUse;
                haptics.intervalOnUse = hapticsToCopy.intervalOnUse;
            }
        }
Example #3
0
        public void AddHaptics(IHapticsAware haptics)
        {
            HapticsConfig onUse   = haptics.HapticsOnUse();
            HapticsConfig onTouch = haptics.HapticsOnTouch();
            HapticsConfig onGrab  = haptics.HapticsOnGrab();

            VRTK_InteractHaptics interactHaptic = _gameObject.GetComponent <VRTK_InteractHaptics>();

            if (interactHaptic == null)
            {
                interactHaptic = _gameObject.AddComponent <VRTK_InteractHaptics>();
            }

            if (onUse != null)
            {
                interactHaptic.strengthOnUse = onUse.Strength;
                interactHaptic.intervalOnUse = onUse.Interval;
                interactHaptic.durationOnUse = onUse.Duration;
                //TODO:проверить, нужен ли этот метод в принципе
                //Убрано при обновлении VRTK
                //interactHaptic.cancelOnUnuse = onUse.CancelOnUnaction;
            }
            else
            {
                interactHaptic.strengthOnUse = 0;
                interactHaptic.durationOnUse = 0;
            }

            if (onTouch != null)
            {
                interactHaptic.strengthOnTouch = onTouch.Strength;
                interactHaptic.intervalOnTouch = onTouch.Interval;
                interactHaptic.durationOnTouch = onTouch.Duration;
                //TODO:проверить, нужен ли этот метод в принципе
                //Убрано при обновлении VRTK
                //interactHaptic.cancelOnUntouch = onTouch.CancelOnUnaction;
            }
            else
            {
                interactHaptic.strengthOnTouch = 0;
                interactHaptic.durationOnTouch = 0;
            }

            if (onGrab != null)
            {
                interactHaptic.strengthOnGrab = onGrab.Strength;
                interactHaptic.intervalOnGrab = onGrab.Interval;
                interactHaptic.durationOnGrab = onGrab.Duration;
                //TODO:проверить, нужен ли этот метод в принципе
                //Убрано при обновлении VRTK
                //interactHaptic.cancelOnUngrab = onGrab.CancelOnUnaction;
            }
            else
            {
                interactHaptic.strengthOnGrab = 0;
                interactHaptic.durationOnGrab = 0;
            }
        }
Example #4
0
 /// <summary>
 /// Observable InteractHapticsUsed event
 /// </summary>
 /// <param name="events"></param>
 /// <returns></returns>
 public static IObservable <InteractHapticsEventArgs> InteractHapticsUsedAsObservable(this VRTK_InteractHaptics events)
 {
     return(Observable.FromEvent <InteractHapticsEventHandler, InteractHapticsEventArgs>(
                h => (s, e) => h(e),
                h => events.InteractHapticsUsed += h,
                h => events.InteractHapticsUsed -= h));
 }
Example #5
0
    public void SetupObject()
    {
        Transform[] transforms = Selection.transforms;
        foreach (Transform transform in transforms)
        {
            GameObject go = transform.gameObject;
            VRTK_InteractableObject intObj = go.GetComponent <VRTK_InteractableObject>();
            if (intObj == null)
            {
                intObj = go.AddComponent <VRTK_InteractableObject>();
            }
            intObj.touchHighlightColor = touchColor;
            intObj.isGrabbable         = useGrab;
            intObj.holdButtonToGrab    = holdGrab;
            intObj.isUsable            = useUse;
            intObj.disableWhenIdle     = disableIdle;
            intObj.grabOverrideButton  = VRTK_ControllerEvents.ButtonAlias.Undefined;
            intObj.useOverrideButton   = VRTK_ControllerEvents.ButtonAlias.Undefined;
            VRTK_BaseGrabAttach grab = go.GetComponent <VRTK_BaseGrabAttach>();
            if (grab != null)
            {
                DestroyImmediate(grab);
            }
            switch (primGrab)
            {
            case PrimaryGrab.父子物体式:
                grab = go.AddComponent <VRTK_ChildOfControllerGrabAttach>();
                break;

            case PrimaryGrab.FixedJoint连接式:
                grab = go.AddComponent <VRTK_FixedJointGrabAttach>();
                break;

            case PrimaryGrab.攀爬式:
                grab = go.AddComponent <VRTK_ClimbableGrabAttach>();
                break;

            case PrimaryGrab.关节式:
                grab = go.AddComponent <VRTK_CustomJointGrabAttach>();
                break;

            case PrimaryGrab.添加力:
                grab = go.AddComponent <VRTK_RotatorTrackGrabAttach>();
                break;

            case PrimaryGrab.SpringJoint连接式:
                grab = go.AddComponent <VRTK_SpringJointGrabAttach>();
                break;

            case PrimaryGrab.模拟碰撞式:
                grab = go.AddComponent <VRTK_TrackObjectGrabAttach>();
                break;

            default:
                grab = go.AddComponent <VRTK_ChildOfControllerGrabAttach>();
                break;
            }
            intObj.grabAttachMechanicScript = grab;
            VRTK_BaseGrabAction grab2 = go.GetComponent <VRTK_BaseGrabAction>();
            if (grab2 != null)
            {
                DestroyImmediate(grab2);
            }
            switch (secGrab)
            {
            case SecondaryGrab.换手:
                grab2 = go.AddComponent <VRTK_SwapControllerGrabAction>();
                break;

            case SecondaryGrab.控制方向:
                grab2 = go.AddComponent <VRTK_ControlDirectionGrabAction>();
                break;

            case SecondaryGrab.缩放:
                grab2 = go.AddComponent <VRTK_AxisScaleGrabAction>();
                break;

            default:
                grab2 = go.AddComponent <VRTK_SwapControllerGrabAction>();
                break;
            }
            intObj.secondaryGrabActionScript = grab2;
            if (addrb)
            {
                Rigidbody rb = go.GetComponent <Rigidbody>();
                if (rb == null)
                {
                    go.AddComponent <Rigidbody>();
                }
            }
            if (addHaptics)
            {
                VRTK_InteractHaptics haptics = go.GetComponent <VRTK_InteractHaptics>();
                if (haptics == null)
                {
                    go.AddComponent <VRTK_InteractHaptics>();
                }
            }
        }
    }
Example #6
0
    private void generate_spheres()
    {
        for (int i = sphere_offset; i < sphere_offset + 450; i++)
        {
            if (i >= 2448)
            {
                m_dropdownList.Sort();
                DropDownList.AddOptions(m_dropdownList);
                return;
            }
            //generate spheres according to coord in csv file
            GameObject sp = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            sp.transform.parent   = transform;
            sp.transform.position = new Vector3(float.Parse(CSVManager.GetRowList()[i].X), float.Parse(CSVManager.GetRowList()[i].Y),
                                                float.Parse(CSVManager.GetRowList()[i].Z));
            sp.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
            sp.name = CSVManager.GetRowList()[i].Description;
            sp.tag  = "Sphere";
            spheres.Add(sp);

            //disable shadow
            MeshRenderer mr = sp.GetComponent(typeof(MeshRenderer)) as MeshRenderer;
            mr.shadowCastingMode = ShadowCastingMode.Off;

            //enable sphere collider isTrigger
            SphereCollider sc = sp.GetComponent(typeof(SphereCollider)) as SphereCollider;
            sc.isTrigger = false;

            //add Rigidbody component
            Rigidbody rb = sp.AddComponent(typeof(Rigidbody)) as Rigidbody;
            rb.useGravity  = false;
            rb.isKinematic = true;

            //add VRTK component
            VRTK_InteractableObject       io   = sp.AddComponent(typeof(VRTK_InteractableObject)) as VRTK_InteractableObject;
            VRTK_TrackObjectGrabAttach    toga = sp.AddComponent(typeof(VRTK_TrackObjectGrabAttach)) as VRTK_TrackObjectGrabAttach;
            VRTK_SwapControllerGrabAction scga = sp.AddComponent(typeof(VRTK_SwapControllerGrabAction)) as VRTK_SwapControllerGrabAction;
            VRTK_InteractHaptics          ih   = sp.AddComponent(typeof(VRTK_InteractHaptics)) as VRTK_InteractHaptics;
            io.holdButtonToGrab         = false;
            io.isGrabbable              = true;
            io.touchHighlightColor      = Color.yellow;
            io.grabAttachMechanicScript = toga;

            //set detach distance
            toga.detachDistance = 5.0f;

            //use precision grab
            toga.precisionGrab = true;

            io.secondaryGrabActionScript = scga;

            //show the label in HUD when touched
            TouchedInput ti = sp.AddComponent(typeof(TouchedInput)) as TouchedInput;
            ti.input          = labelInput;
            ti.label          = CSVManager.GetRowList()[i].Description;
            ti.sp             = sp;
            ti.labelList      = labelList;
            ti.input_dropdown = DropDownList;
            ti.m_dropdownList = m_dropdownList;

            //add connectSphere component
            ConnectSpheres cs = sp.AddComponent(typeof(ConnectSpheres)) as ConnectSpheres;
            cs.spheres = spheres;

            //Add the label to the dropdown list
            m_dropdownList.Add(CSVManager.GetRowList()[i].Description);
        }
        m_dropdownList.Sort();
        DropDownList.AddOptions(m_dropdownList);
    }