public void UpdateEventsManager()
        {
            VRTK_InteractableObject newEventsManager = transform.GetComponentInParent<VRTK_InteractableObject>();
            if (newEventsManager == null)
            {
                Debug.LogError("The radial menu must be a child of an interactable object or be set in the inspector!");
                return;
            }
            else if (newEventsManager != eventsManager) // Changed managers
            {
                if (eventsManager != null)
                { // Unsubscribe from the old events
                    OnDisable();
                }

                eventsManager = newEventsManager;

                // Subscribe to new events
                OnEnable();

                Object.Destroy(menuCollider);

                // Reset to initial state
                Initialize();
            }
        }
 protected override void SnapObjectToZone(VRTK.VRTK_InteractableObject objectToSnap)
 {
     base.SnapObjectToZone(objectToSnap);
     if (!hasCrop)
     {
         PlantSeed(objectToSnap);
     }
 }
Beispiel #3
0
    // Use this for initialization
    protected virtual void Start()
    {
        meshFilter        = GetComponent <MeshFilter>();
        renderer          = GetComponent <Renderer>();
        renderer.material = normalMaterial;

        transform.localScale = new Vector3(colliderSize, colliderSize, colliderSize);
        if (followTarget == null)
        {
            return;
        }

        //既存Collider削除
        var colliders = followTarget.gameObject.GetComponents <Collider>();

        foreach (var collider in colliders)
        {
            DestroyImmediate(collider);
        }

        //既存Rigidbody削除
        var rigidBody = followTarget.gameObject.GetComponent <Rigidbody>();

        if (rigidBody)
        {
            DestroyImmediate(rigidBody);
        }

        followTarget.gameObject.layer = LayerMask.NameToLayer("Node");

        targetCollider = followTarget.gameObject.AddComponent <BoxCollider>();
        var fixedJointGrabAttach = followTarget.gameObject.AddComponent <VRTK.GrabAttachMechanics.VRTK_FixedJointGrabAttach>();

        fixedJointGrabAttach.precisionGrab = true;
        targetRigidbody             = followTarget.gameObject.AddComponent <Rigidbody>();
        targetRigidbody.isKinematic = true;

        //targetにScalingNodeが付いてたらノードスケール変更
        var scalingNode = followTarget.GetComponent <ScalingNode>();

        if (scalingNode)
        {
            colliderSize *= scalingNode.scale;
        }

        /*if (type == eNodeType.FK)//FKNodeは移動できない
         * {
         *  rigidBody.constraints = RigidbodyConstraints.FreezePosition;
         * }*/

        interactableObject             = followTarget.gameObject.AddComponent <VRTK.VRTK_InteractableObject>();
        interactableObject.isGrabbable = true;
        interactableObject.InteractableObjectGrabbed   += new VRTK.InteractableObjectEventHandler(DoObjectGrab);
        interactableObject.InteractableObjectUngrabbed += new VRTK.InteractableObjectEventHandler(DoObjectUngrabbed);
    }
 private void InitInteractable()
 {
     io = GetComponent<VRTK_InteractableObject>();
     if (io == null)
     {
         io = gameObject.AddComponent<VRTK_InteractableObject>();
     }
     io.isGrabbable = true;
     io.precisionSnap = true;
     io.grabAttachMechanic = VRTK_InteractableObject.GrabAttachType.Track_Object;
 }
Beispiel #5
0
 private void OnTriggerEnter(Collider other)
 {
     //VRTK.VRTK_InteractableObject obj = other.gameObject.GetComponent<VRTK.VRTK_InteractableObject>();
     //if (obj && !active) obj.isGrabbable = false;
     if (!objectInside)
     {
         objectInside = other.gameObject;
         VRTK.VRTK_InteractableObject obj = other.gameObject.GetComponent <VRTK.VRTK_InteractableObject>();
         if (obj && !active)
         {
             obj.isGrabbable = false;
         }
     }
 }
Beispiel #6
0
    protected virtual void OnEnable()
    {
        lightBulb     = GetComponentInChildren <Light>();
        flashlightLit = true;
        ToggleFlashlight(flashlightLit);

        linkedObject = (linkedObject == null ? GetComponent <VRTK_InteractableObject>() : linkedObject);

        if (linkedObject != null)
        {
            linkedObject.InteractableObjectUsed += InteractableObjectUsed;
            //   linkedObject.InteractableObjectUnused += InteractableObjectUnused;
        }
    }
        private IEnumerator AutoGrab()
        {
            controller = GetComponent<VRTK_InteractGrab>();
            if (!controller)
            {
                Debug.LogError("The VRTK_InteractGrab script is required to be attached to the controller along with this script.");
                yield break;
            }

            if (!objectToGrab)
            {
                Debug.LogError("You have to assign an object that should be grabbed.");
                yield break;
            }

            while (controller.controllerAttachPoint == null)
            {
                yield return true;
            }

            grabbableObject = objectToGrab;
            if (cloneGrabbedObject)
            {
                if (previousClonedObject == null)
                {
                    grabbableObject = Instantiate(objectToGrab);
                    previousClonedObject = grabbableObject;
                }
                else
                {
                    grabbableObject = previousClonedObject;
                }
            }

            if (grabbableObject.isGrabbable && !grabbableObject.IsGrabbed())
            {
                if (grabbableObject.AttachIsKinematicObject())
                {
                    grabbableObject.ToggleKinematic(true);
                }

                grabbableObject.transform.position = transform.position;
                controller.GetComponent<VRTK_InteractTouch>().ForceStopTouching();
                controller.GetComponent<VRTK_InteractTouch>().ForceTouch(grabbableObject.gameObject);
                controller.AttemptGrab();
            }
        }
    //---コンポーネントの追加---//
    private void AddedVrtk_InteractableObjectComponent()
    {
        if (IsCompponentsAttached)
        {
            return;
        }
        if (this.GetComponent <VRTK.VRTK_InteractableObject>() != null)
        {
            IsCompponentsAttached = true;
            return;
        }
        else if (this.GetComponent <VRTK.VRTK_InteractableObject>() == null)
        {
            vrtk_InteractableObject             = this.gameObject.AddComponent <VRTK.VRTK_InteractableObject>();
            vrtk_InteractableObject.isGrabbable = true;

            //任意の色に変更すること
            vrtk_InteractableObject.touchHighlightColor = Color.blue;

            vrtk_InteractableObject.grabOverrideButton = VRTK.VRTK_ControllerEvents.ButtonAlias.Trigger_Press;
        }
    }
        private void InitKnob()
        {
            rb = GetComponent<Rigidbody>();
            if (rb == null)
            {
                rb = gameObject.AddComponent<Rigidbody>();
                rb.angularDrag = 10; // otherwise knob will continue to move too far on its own
            }
            rb.isKinematic = false;
            rb.useGravity = false;

            io = GetComponent<VRTK_InteractableObject>();
            if (io == null)
            {
                io = gameObject.AddComponent<VRTK_InteractableObject>();
            }
            io.isGrabbable = true;
            io.precisionSnap = true;
            io.stayGrabbedOnTeleport = false;
            io.grabAttachMechanic = VRTK_InteractableObject.GrabAttachType.Track_Object;

            cj = GetComponent<ConfigurableJoint>();
            if (cj == null)
            {
                cj = gameObject.AddComponent<ConfigurableJoint>();
                cj.configuredInWorldSpace = false;
                cjCreated = true;
            }

            if (connectedTo)
            {
                Rigidbody rb2 = connectedTo.GetComponent<Rigidbody>();
                if (rb2 == null)
                {
                    rb2 = connectedTo.AddComponent<Rigidbody>();
                    rb2.useGravity = false;
                    rb2.isKinematic = true;
                }
            }
        }
Beispiel #10
0
        private void SetupObject()
        {
            GameObject go = Selection.activeGameObject;

            if (go)
            {
                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.ChildOfController:
                    grab = go.AddComponent <VRTK_ChildOfControllerGrabAttach>();
                    break;

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

                case PrimaryGrab.Climbable:
                    grab = go.AddComponent <VRTK_ClimbableGrabAttach>();
                    break;

                case PrimaryGrab.CustomJoint:
                    grab = go.AddComponent <VRTK_CustomJointGrabAttach>();
                    break;

                case PrimaryGrab.RotatorTrack:
                    grab = go.AddComponent <VRTK_RotatorTrackGrabAttach>();
                    break;

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

                case PrimaryGrab.TrackObject:
                    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.SwapControllers:
                    grab2 = go.AddComponent <VRTK_SwapControllerGrabAction>();
                    break;

                case SecondaryGrab.ControlDirection:
                    grab2 = go.AddComponent <VRTK_ControlDirectionGrabAction>();
                    break;

                case SecondaryGrab.AxisScale:
                    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>();
                    }
                }
            }
        }
Beispiel #11
0
        private void InitHandle()
        {
            if (handles == null)
            {
                return;
            }

            if (handles.GetComponentInChildren<Collider>() == null)
            {
                Utilities.CreateColliders(handles);
            }

            handleRb = handles.GetComponent<Rigidbody>();
            if (handleRb == null)
            {
                handleRb = handles.AddComponent<Rigidbody>();
            }
            handleRb.isKinematic = false;
            handleRb.useGravity = false;

            handleFj = handles.GetComponent<FixedJoint>();
            if (handleFj == null)
            {
                handleFj = handles.AddComponent<FixedJoint>();
                handleFj.connectedBody = doorRb;
            }

            handleIo = handles.GetComponent<VRTK_InteractableObject>();
            if (handleIo == null)
            {
                handleIo = handles.AddComponent<VRTK_InteractableObject>();
            }
            handleIo.isGrabbable = true;
            handleIo.precisionSnap = true;
            handleIo.stayGrabbedOnTeleport = false;
            handleIo.grabAttachMechanic = VRTK_InteractableObject.GrabAttachType.Track_Object;
        }
 private void Start()
 {
     bowAnimation = GetComponent<BowAnimation>();
     handle = GetComponentInChildren<BowHandle>();
     controllers = FindObjectOfType<SteamVR_ControllerManager>();
     interact = GetComponent<VRTK_InteractableObject>();
     interact.InteractableObjectGrabbed += new InteractableObjectEventHandler(DoObjectGrab);
 }
Beispiel #13
0
        // Token: 0x06001599 RID: 5529 RVA: 0x000769C4 File Offset: 0x00074BC4
        protected virtual bool IsObjectGrabbable(GameObject obj)
        {
            VRTK_InteractableObject component = obj.GetComponent <VRTK_InteractableObject>();

            return(this.interactTouch != null && this.interactTouch.IsObjectInteractable(obj) && component != null && (component.isGrabbable || component.PerformSecondaryAction()));
        }
Beispiel #14
0
 private void Start()
 {
     vrtk_InteractableObject             = this.gameObject.GetComponent <VRTK.VRTK_InteractableObject>();
     vrtk_InteractableObject.isGrabbable = true;
 }
Beispiel #15
0
 private bool PointerActivatesUseAction(VRTK_InteractableObject io)
 {
     return(io && io.pointerActivatesUseAction && io.IsValidInteractableController(gameObject, io.allowedUseControllers));
 }
        protected override void InitRequiredComponents()
        {
            if (GetComponentInChildren<Collider>() == null)
            {
                Utilities.CreateColliders(gameObject);
            }

            rb = GetComponent<Rigidbody>();
            if (rb == null)
            {
                rb = gameObject.AddComponent<Rigidbody>();
                rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
                rb.angularDrag = 30; // otherwise lever will continue to move too far on its own
            }
            rb.isKinematic = false;
            rb.useGravity = false;

            io = GetComponent<VRTK_InteractableObject>();
            if (io == null)
            {
                io = gameObject.AddComponent<VRTK_InteractableObject>();
            }
            io.isGrabbable = true;
            io.precisionSnap = true;
            io.stayGrabbedOnTeleport = false;
            io.grabAttachMechanic = VRTK_InteractableObject.GrabAttachType.Rotator_Track;

            hj = GetComponent<HingeJoint>();
            if (hj == null)
            {
                hj = gameObject.AddComponent<HingeJoint>();
                hjCreated = true;
            }

            if (connectedTo)
            {
                Rigidbody rb2 = connectedTo.GetComponent<Rigidbody>();
                if (rb2 == null)
                {
                    rb2 = connectedTo.AddComponent<Rigidbody>();
                }
                rb2.useGravity = false;
            }
        }
Beispiel #17
0
 void Start()
 {
     dataPoint = gameObject.GetComponent <VRTK_InteractableObject>();
     text      = GameObject.Find("RedMenuText").GetComponent <Text>();
 }
Beispiel #18
0
 protected virtual bool IsObjectUsable(GameObject obj)
 {
     VRTK_InteractableObject objScript = (obj != null ? obj.GetComponent<VRTK_InteractableObject>() : null);
     return (obj != null && interactTouch != null && interactTouch.IsObjectInteractable(obj) && objScript != null && objScript.isUsable);
 }
Beispiel #19
0
        protected virtual bool FloorIsGrabbedObject(RaycastHit collidedObj)
        {
            VRTK_InteractableObject obj = collidedObj.transform.GetComponent <VRTK_InteractableObject>();

            return(obj != null && obj.IsGrabbed());
        }
Beispiel #20
0
        // Token: 0x06001829 RID: 6185 RVA: 0x000809C4 File Offset: 0x0007EBC4
        protected virtual bool IsClimbableObject(GameObject obj)
        {
            VRTK_InteractableObject component = obj.GetComponent <VRTK_InteractableObject>();

            return(component && component.grabAttachMechanicScript && component.grabAttachMechanicScript.IsClimbable());
        }
Beispiel #21
0
        protected virtual GameObject GetColliderInteractableObject(Collider collider)
        {
            VRTK_InteractableObject checkIO = collider.GetComponentInParent <VRTK_InteractableObject>();

            return(checkIO != null ? checkIO.gameObject : null);
        }
        private void InitBody()
        {
            rb = GetComponent<Rigidbody>();
            if (rb == null)
            {
                rb = gameObject.AddComponent<Rigidbody>();
                rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
            }
            rb.isKinematic = false;

            io = GetComponent<VRTK_InteractableObject>();
            if (io == null)
            {
                io = gameObject.AddComponent<VRTK_InteractableObject>();
            }
            io.isGrabbable = true;
            io.precisionSnap = true;
            io.stayGrabbedOnTeleport = false;
            io.grabAttachMechanic = VRTK_InteractableObject.GrabAttachType.Spring_Joint;

            if (connectedTo)
            {
                Rigidbody rb2 = connectedTo.GetComponent<Rigidbody>();
                if (rb2 == null)
                {
                    rb2 = connectedTo.AddComponent<Rigidbody>();
                    rb2.useGravity = false;
                    rb2.isKinematic = true;
                }
            }

            cj = GetComponent<ConfigurableJoint>();
            if (cj == null)
            {
                cj = gameObject.AddComponent<ConfigurableJoint>();
                cjCreated = true;
            }

            cf = GetComponent<ConstantForce>();
            if (cf == null)
            {
                cf = gameObject.AddComponent<ConstantForce>();
                cf.enabled = false;
                cfCreated = true;
            }
        }
Beispiel #23
0
 protected virtual bool PointerActivatesUseAction(VRTK_InteractableObject givenInteractableObject)
 {
     return(givenInteractableObject && givenInteractableObject.pointerActivatesUseAction && givenInteractableObject.IsValidInteractableController(controller.gameObject, givenInteractableObject.allowedUseControllers));
 }
Beispiel #24
0
    public override IEnumerator Cut()
    {
        // Jump to main thread for running UNITY API calls
        yield return(Ninja.JumpToUnity);

        // set the blade relative to victim
        _blade = new Plane(gameObject.transform.InverseTransformDirection(-_normalDirection),
                           gameObject.transform.InverseTransformPoint(_anchorPoint));

        // get the victims mesh
        _victim_mesh = gameObject.GetComponent <MeshFilter>().mesh;

        Vector3[] victim_vertices = _victim_mesh.vertices;
        Vector3[] victim_normals  = _victim_mesh.normals;
        Vector2[] victim_uvs      = _victim_mesh.uv;
        Vector4[] victim_tangents = _victim_mesh.tangents;

        int subMeshCount = _victim_mesh.subMeshCount;

        // Jump back to background thread to do heavy processes.
        yield return(Ninja.JumpBack);

        // reset values
        _new_vertices.Clear();

        _leftSide  = new Mesh_Maker();
        _rightSide = new Mesh_Maker();

        bool[] sides = new bool[3];
        int[]  indices;
        int    p1, p2, p3;


        // go throught the submeshes
        for (int sub = 0; sub < subMeshCount; sub++)
        {
            yield return(Ninja.JumpToUnity);

            indices = _victim_mesh.GetTriangles(sub);
            yield return(Ninja.JumpBack);

            for (int i = 0; i < indices.Length; i += 3)
            {
                p1 = indices[i];
                p2 = indices[i + 1];
                p3 = indices[i + 2];

                sides[0] = _blade.GetSide(victim_vertices[p1]);
                sides[1] = _blade.GetSide(victim_vertices[p2]);
                sides[2] = _blade.GetSide(victim_vertices[p3]);

                // whole triangle
                if (sides[0] == sides[1] && sides[0] == sides[2])
                {
                    if (sides[0])
                    { // left side
                        _leftSide.AddTriangle(
                            new Vector3[] { victim_vertices[p1], victim_vertices[p2], victim_vertices[p3] },
                            new Vector3[] { victim_normals[p1], victim_normals[p2], victim_normals[p3] },
                            new Vector2[] { victim_uvs[p1], victim_uvs[p2], victim_uvs[p3] },
                            new Vector4[] { victim_tangents[p1], victim_tangents[p2], victim_tangents[p3] },
                            sub);
                    }
                    else
                    {
                        _rightSide.AddTriangle(
                            new Vector3[] { victim_vertices[p1], victim_vertices[p2], victim_vertices[p3] },
                            new Vector3[] { victim_normals[p1], victim_normals[p2], victim_normals[p3] },
                            new Vector2[] { victim_uvs[p1], victim_uvs[p2], victim_uvs[p3] },
                            new Vector4[] { victim_tangents[p1], victim_tangents[p2], victim_tangents[p3] },
                            sub);
                    }
                }
                else
                { // cut the triangle
                    Cut_this_Face(
                        new Vector3[] { victim_vertices[p1], victim_vertices[p2], victim_vertices[p3] },
                        new Vector3[] { victim_normals[p1], victim_normals[p2], victim_normals[p3] },
                        new Vector2[] { victim_uvs[p1], victim_uvs[p2], victim_uvs[p3] },
                        new Vector4[] { victim_tangents[p1], victim_tangents[p2], victim_tangents[p3] },
                        sub);
                }
            }
        }

        // Jump to main thread for running UNITY API calls
        yield return(Ninja.JumpToUnity);

        // The capping Material will be at the end
        Material[] mats = gameObject.GetComponent <MeshRenderer>().sharedMaterials;
        if (mats[mats.Length - 1].name != capMaterial.name)
        {
            Material[] newMats = new Material[mats.Length + 1];
            mats.CopyTo(newMats, 0);
            newMats[mats.Length] = capMaterial;
            mats = newMats;
        }
        _capMatSub = mats.Length - 1; // for later use

        // Left Mesh
        Mesh left_HalfMesh = _leftSide.GetMesh();

        left_HalfMesh.name = "Split Mesh Left";

        // Right Mesh
        Mesh right_HalfMesh = _rightSide.GetMesh();

        right_HalfMesh.name = "Split Mesh Right";

        // assign the game objects
        gameObject.name = "left side";
        gameObject.GetComponent <MeshFilter>().mesh = left_HalfMesh;

        GameObject leftSideObj = gameObject;

        GameObject rightSideObj = new GameObject("right side", typeof(MeshFilter), typeof(MeshRenderer));

        rightSideObj.transform.position = gameObject.transform.position;
        rightSideObj.transform.rotation = gameObject.transform.rotation;
        rightSideObj.GetComponent <MeshFilter>().mesh = right_HalfMesh;

        leftSideObj.layer  = 9;
        rightSideObj.layer = 9;

        if (gameObject.transform.parent != null)
        {
            rightSideObj.transform.parent = gameObject.transform.parent;
        }

        rightSideObj.transform.localScale = gameObject.transform.localScale;

        // assign mats
        leftSideObj.GetComponent <MeshRenderer>().materials  = mats;
        rightSideObj.GetComponent <MeshRenderer>().materials = mats;

        // Handle new colliders of left & right pieces
        HandleCollisions(leftSideObj);
        HandleCollisions(rightSideObj);

        // Sound effects preparation
        AudioSource asrc = rightSideObj.AddComponent <AudioSource>();

        asrc.spatialBlend = 1f;
        asrc.volume       = 0.4f;
        asrc.playOnAwake  = false;
        ////
        // Other Stuff
        VRTK.VRTK_InteractableObject vrtk_io = rightSideObj.AddComponent <VRTK_InteractableObject>();
        //vrtk_io.holdButtonToGrab = false;
        VRTK_FixedJointGrabAttach vrtk_fjga = rightSideObj.AddComponent <VRTK_FixedJointGrabAttach>();

        vrtk_io.isGrabbable     = true;
        vrtk_fjga.precisionGrab = true;
        /////

        Renderer right_renderer = rightSideObj.GetComponent <Renderer>();
        Renderer left_renderer  = leftSideObj.GetComponent <Renderer>();
        float    right_bounds   = right_renderer.bounds.size.x * right_renderer.bounds.size.y * right_renderer.bounds.size.z;
        float    left_bounds    = left_renderer.bounds.size.x * left_renderer.bounds.size.y * left_renderer.bounds.size.z;

        GameObject leftController = GameObject.Find("LeftController");

        if (leftController.GetComponent <AutoGrab>() != null)
        {
            Destroy(leftController.GetComponent <AutoGrab>());
        }
        if (right_bounds > left_bounds)
        {
            Debug.Log("right side auto grab");

            objectFlesh.transform.parent   = rightSideObj.transform;
            objectFlesh.transform.position = rightSideObj.transform.position;
            objectFlesh.transform.rotation = rightSideObj.transform.rotation;

            parent = rightSideObj;

            if (right_bounds < smallerAllowedRigVolume)
            {
                AddCanBeChopped();
            }
            else
            {
                leftController.GetComponent <VRTK_InteractGrab>().ForceRelease();

                /*if (rightController.GetComponent<VRTK_InteractGrab>() != null)
                 * {
                 *  GameObject grabbedObject = rightController.GetComponent<VRTK_InteractGrab>().GetGrabbedObject();
                 *  Debug.Log(grabbedObject);
                 *
                 *  if (grabbedObject != null && grabbedObject.GetComponent<VRTK_InteractableObject>() != null)
                 *  {
                 *      grabbedObject.GetComponent<VRTK_InteractableObject>().Ungrabbed();
                 *  }
                 * }*/
                AutoGrab autoGrabRight = leftController.AddComponent <AutoGrab>();
                autoGrabRight.interactTouch = autoGrabRight.GetComponent <VRTK_InteractTouch>();
                autoGrabRight.interactGrab  = autoGrabRight.GetComponent <VRTK_InteractGrab>();
                autoGrabRight.objectToGrab  = vrtk_io;

                // Create required components & set parameters on right piece, copy component values to new one.
                CanBePeeled cbc = rightSideObj.AddComponent <CanBePeeled>();
                cbc.capMaterial             = this.capMaterial;
                cbc.sliceTimeout            = this.sliceTimeout;
                cbc.colliderSkinWidth       = this.colliderSkinWidth;
                cbc.detachChildrenOnSlice   = this.detachChildrenOnSlice;
                cbc.newPieceMassMultiplier  = this.newPieceMassMultiplier;
                cbc.canBeChoppedWhileOnHand = this.canBeChoppedWhileOnHand;
                cbc._rootObject             = this._rootObject;
                cbc.choppingSoundBoard      = this.choppingSoundBoard;
                cbc.objectFlesh             = this.objectFlesh;
                cbc.initialRig = leftSideObj;
                ////
            }
            Destroy(leftSideObj.GetComponent <CanBePeeled>());
        }
        else
        {
            Debug.Log("left side auto grab");
            //objectFlesh.transform.localPosition = new Vector3(0,0,0);
            //objectFlesh.transform.SetParent(leftSideObj.transform);
            if (left_bounds < smallerAllowedRigVolume)
            {
                AddCanBeChopped();
            }
            else
            {
                leftController.GetComponent <VRTK_InteractGrab>().ForceRelease();

                /*if (rightController.GetComponent<VRTK_InteractGrab>() != null)
                 * {
                 *  GameObject grabbedObject = rightController.GetComponent<VRTK_InteractGrab>().GetGrabbedObject();
                 *  Debug.Log(grabbedObject);
                 *  if (grabbedObject != null && grabbedObject.GetComponent<VRTK_InteractableObject>() != null)
                 *  {
                 *      grabbedObject.GetComponent<VRTK_InteractableObject>().Ungrabbed(rightController.GetComponent<VRTK_InteractGrab>());
                 *
                 *  }
                 * }*/
                AutoGrab autoGrabRight = leftController.AddComponent <AutoGrab>();
                autoGrabRight.interactTouch = autoGrabRight.GetComponent <VRTK_InteractTouch>();
                autoGrabRight.interactGrab  = autoGrabRight.GetComponent <VRTK_InteractGrab>();
                autoGrabRight.objectToGrab  = leftSideObj.GetComponent <VRTK_InteractableObject>();

                objectFlesh.transform.parent   = leftSideObj.transform;
                objectFlesh.transform.position = leftSideObj.transform.position;
                objectFlesh.transform.rotation = leftSideObj.transform.rotation;

                parent = leftSideObj;
            }

            Destroy(rightSideObj.GetComponent <CanBePeeled>());
        }

        // End thread
        yield return(Ninja.JumpBack);

        yield break;
    }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            VRTK_InteractableObject targ = (VRTK_InteractableObject)target;

            GUILayout.Space(10);
            GUIStyle  guiStyle      = EditorStyles.foldout;
            FontStyle previousStyle = guiStyle.fontStyle;

            guiStyle.fontStyle = FontStyle.Bold;
            viewTouch          = EditorGUILayout.Foldout(viewTouch, "Touch Options", guiStyle);
            guiStyle.fontStyle = previousStyle;
            GUILayout.Space(2);
            if (viewTouch)
            {
                EditorGUI.indentLevel++;

                targ.highlightOnTouch = EditorGUILayout.Toggle(VRTK_EditorUtilities.BuildGUIContent <VRTK_InteractableObject>("highlightOnTouch"), targ.highlightOnTouch);
                if (targ.highlightOnTouch)
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("touchHighlightColor"));
                }

                GUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(VRTK_EditorUtilities.BuildGUIContent <VRTK_InteractableObject>("rumbleOnTouch"));
                EditorGUI.indentLevel--;
                GUILayout.Label("Strength", GUILayout.MinWidth(49f));
                float y = EditorGUILayout.FloatField(targ.rumbleOnTouch.y, GUILayout.MinWidth(10f));
                GUILayout.Label("Duration", GUILayout.MinWidth(50f));
                float x = EditorGUILayout.FloatField(targ.rumbleOnTouch.x, GUILayout.MinWidth(10f));
                targ.rumbleOnTouch = new Vector2(x, y);
                EditorGUI.indentLevel++;
                GUILayout.EndHorizontal();

                EditorGUILayout.PropertyField(serializedObject.FindProperty("allowedTouchControllers"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("hideControllerOnTouch"));

                EditorGUI.indentLevel--;
            }

            //Grab Layout
            GUILayout.Space(10);
            targ.isGrabbable = EditorGUILayout.Toggle(VRTK_EditorUtilities.BuildGUIContent <VRTK_InteractableObject>("isGrabbable"), targ.isGrabbable);
            if (targ.isGrabbable != isGrabbableLastState && targ.isGrabbable)
            {
                viewGrab = true;
            }
            isGrabbableLastState = targ.isGrabbable;
            if (targ.isGrabbable)
            {
                guiStyle           = EditorStyles.foldout;
                previousStyle      = guiStyle.fontStyle;
                guiStyle.fontStyle = FontStyle.Bold;
                viewGrab           = EditorGUILayout.Foldout(viewGrab, "Grab Options", guiStyle);
                guiStyle.fontStyle = previousStyle;
                GUILayout.Space(2);
                if (viewGrab)
                {
                    EditorGUI.indentLevel++;

                    EditorGUILayout.PropertyField(serializedObject.FindProperty("validDrop"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("isSwappable"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("holdButtonToGrab"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("grabOverrideButton"));

                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(VRTK_EditorUtilities.BuildGUIContent <VRTK_InteractableObject>("rumbleOnGrab"));
                    EditorGUI.indentLevel--;
                    GUILayout.Label("Strength", GUILayout.MinWidth(49f));
                    float y = EditorGUILayout.FloatField(targ.rumbleOnGrab.y, GUILayout.MinWidth(10f));
                    GUILayout.Label("Duration", GUILayout.MinWidth(50f));
                    float x = EditorGUILayout.FloatField(targ.rumbleOnGrab.x, GUILayout.MinWidth(10f));
                    targ.rumbleOnGrab = new Vector2(x, y);
                    EditorGUI.indentLevel++;
                    GUILayout.EndHorizontal();

                    EditorGUILayout.PropertyField(serializedObject.FindProperty("allowedGrabControllers"));
                    targ.precisionSnap = EditorGUILayout.Toggle(VRTK_EditorUtilities.BuildGUIContent <VRTK_InteractableObject>("precisionSnap", "Precision Grab(Snap)"), targ.precisionSnap);
                    if (!targ.precisionSnap)
                    {
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("rightSnapHandle"));
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("leftSnapHandle"));
                    }
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("hideControllerOnGrab"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("stayGrabbedOnTeleport"));

                    targ.grabAttachMechanic = (VRTK_InteractableObject.GrabAttachType)EditorGUILayout.EnumPopup(VRTK_EditorUtilities.BuildGUIContent <VRTK_InteractableObject>("grabAttachMechanic"), targ.grabAttachMechanic);
                    if (Array.IndexOf(hasDetachThreshold, targ.grabAttachMechanic) >= 0)
                    {
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("detachThreshold"));
                        if (targ.grabAttachMechanic == VRTK_InteractableObject.GrabAttachType.Spring_Joint)
                        {
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("springJointStrength"));
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("springJointDamper"));
                        }
                    }
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("throwMultiplier"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("onGrabCollisionDelay"));

                    EditorGUI.indentLevel--;
                }
            }

            GUILayout.Space(10);
            targ.isUsable = EditorGUILayout.Toggle(VRTK_EditorUtilities.BuildGUIContent <VRTK_InteractableObject>("isUsable"), targ.isUsable);
            if (targ.isUsable != isUsableLastState && targ.isUsable)
            {
                viewUse = true;
            }

            isUsableLastState = targ.isUsable;
            if (targ.isUsable)
            {
                guiStyle           = EditorStyles.foldout;
                previousStyle      = guiStyle.fontStyle;
                guiStyle.fontStyle = FontStyle.Bold;
                viewUse            = EditorGUILayout.Foldout(viewUse, "Use Options", guiStyle);
                guiStyle.fontStyle = previousStyle;
                GUILayout.Space(2);
                if (viewUse)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("useOnlyIfGrabbed"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("holdButtonToUse"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("useOverrideButton"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("pointerActivatesUseAction"));

                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(VRTK_EditorUtilities.BuildGUIContent <VRTK_InteractableObject>("rumbleOnUse"));
                    EditorGUI.indentLevel--;
                    GUILayout.Label("Strength", GUILayout.MinWidth(49f));
                    float y = EditorGUILayout.FloatField(targ.rumbleOnUse.y, GUILayout.MinWidth(10f));
                    GUILayout.Label("Duration", GUILayout.MinWidth(50f));
                    float x = EditorGUILayout.FloatField(targ.rumbleOnUse.x, GUILayout.MinWidth(10f));
                    targ.rumbleOnUse = new Vector2(x, y);
                    EditorGUI.indentLevel++;
                    GUILayout.EndHorizontal();

                    EditorGUILayout.PropertyField(serializedObject.FindProperty("allowedUseControllers"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("hideControllerOnUse"));

                    EditorGUI.indentLevel--;
                }
            }

            if (targ.GetComponent <VRTK_InteractableObject>().GetType().IsSubclassOf(typeof(VRTK_InteractableObject)))
            {
                GUILayout.Space(10);
                guiStyle           = EditorStyles.foldout;
                previousStyle      = guiStyle.fontStyle;
                guiStyle.fontStyle = FontStyle.Bold;
                viewCustom         = EditorGUILayout.Foldout(viewCustom, "Custom Options", guiStyle);
                guiStyle.fontStyle = previousStyle;
                GUILayout.Space(2);
                if (viewCustom)
                {
                    List <string> excludedProperties = new List <string>();
                    foreach (var ioProperty in typeof(VRTK_InteractableObject).GetFields())
                    {
                        excludedProperties.Add(ioProperty.Name);
                    }

                    DrawPropertiesExcluding(serializedObject, excludedProperties.ToArray());
                }
            }
            serializedObject.ApplyModifiedProperties();
        }
Beispiel #26
0
 // Use this for initialization
 void Start()
 {
     mLid                       = GameObject.Find("Lid");
     interactScript             = mLid.GetComponent <VRTK.VRTK_InteractableObject> ();
     interactScript.isGrabbable = false;
 }
 private bool PointerActivatesUseAction(VRTK_InteractableObject io)
 {
     return (io && io.pointerActivatesUseAction && io.IsValidInteractableController(controller.gameObject, io.allowedUseControllers));
 }
        private void InitHandle()
        {
            handleRb = handle.GetComponent<Rigidbody>();
            if (handleRb == null)
            {
                handleRb = handle.AddComponent<Rigidbody>();
            }
            handleRb.isKinematic = false;
            handleRb.useGravity = false;

            handleFj = handle.GetComponent<FixedJoint>();
            if (handleFj == null)
            {
                handleFj = handle.AddComponent<FixedJoint>();
                handleFj.connectedBody = lidRb;
            }

            handleIo = handle.GetComponent<VRTK_InteractableObject>();
            if (handleIo == null)
            {
                handleIo = handle.AddComponent<VRTK_InteractableObject>();
            }
            handleIo.isGrabbable = true;
            handleIo.precisionSnap = true;
            handleIo.grabAttachMechanic = VRTK_InteractableObject.GrabAttachType.Track_Object;
        }
Beispiel #29
0
        }                                                                                                                                                                              // 0x00000001814811D0-0x00000001814813A0

        protected virtual Vector3 u0924u091Bu0920u0927u091Au0924u091Cu091Bu0924u0929u091F(VRTK_InteractableObject u0928u0926u091Eu091Du0921u0922u0923u0923u091Fu091Au0923) => default; // 0x0000000181485880-0x00000001814859E0
 private void Start()
 {
     arrow = this.transform.FindChild("Arrow").gameObject;
     obj = this.GetComponent<VRTK_InteractableObject>();
 }
Beispiel #31
0
        }                                                                                                                                                                              // 0x00000001814874F0-0x0000000181487590

        protected virtual Vector3 u091Fu0926u0921u0922u091Eu091Fu091Du091Fu091Au091Fu091B(VRTK_InteractableObject u0928u0926u091Eu091Du0921u0922u0923u0923u091Fu091Au0923) => default; // 0x0000000181483A40-0x0000000181483BA0
Beispiel #32
0
 // Use this for initialization
 void Start()
 {
     interactableObject = GetComponent <VRTK.VRTK_InteractableObject>();
     interactableObject.InteractableObjectGrabbed += new VRTK.InteractableObjectEventHandler(InteractableObjectGrabbed);
 }
        private void CheckButtonOverrides(VRTK_InteractableObject touchedObjectScript)
        {
            if (touchedObjectScript.grabOverrideButton != VRTK_ControllerEvents.ButtonAlias.Undefined)
            {
                originalGrabAlias = controllerEvents.grabToggleButton;
                controllerEvents.grabToggleButton = touchedObjectScript.grabOverrideButton;
            }

            if (touchedObjectScript.useOverrideButton != VRTK_ControllerEvents.ButtonAlias.Undefined)
            {
                originalUseAlias = controllerEvents.useToggleButton;
                controllerEvents.useToggleButton = touchedObjectScript.useOverrideButton;
            }
        }
        private Transform GetSnapHandle(VRTK_InteractableObject objectScript)
        {
            if (objectScript.rightSnapHandle == null && objectScript.leftSnapHandle != null)
            {
                objectScript.rightSnapHandle = objectScript.leftSnapHandle;
            }

            if (objectScript.leftSnapHandle == null && objectScript.rightSnapHandle != null)
            {
                objectScript.leftSnapHandle = objectScript.rightSnapHandle;
            }

            if (DeviceFinder.IsControllerOfHand(this.gameObject, DeviceFinder.ControllerHand.Right))
            {
                return objectScript.rightSnapHandle;
            }

            if (DeviceFinder.IsControllerOfHand(this.gameObject, DeviceFinder.ControllerHand.Left))
            {
                return objectScript.leftSnapHandle;
            }

            return null;
        }
 private void CheckRumbleController(VRTK_InteractableObject touchedObjectScript)
 {
     var rumbleAmount = touchedObjectScript.rumbleOnTouch;
     if (!rumbleAmount.Equals(Vector2.zero) && !triggerRumble)
     {
         triggerRumble = true;
         controllerActions.TriggerHapticPulse((ushort)rumbleAmount.y, rumbleAmount.x, 0.05f);
         Invoke("ResetTriggerRumble", rumbleAmount.x);
     }
 }
 protected virtual bool PointerActivatesUseAction(VRTK_InteractableObject givenInteractableObject)
 {
     return(givenInteractableObject != null && givenInteractableObject.pointerActivatesUseAction && (!ControllerRequired() || givenInteractableObject.IsValidInteractableController(controllerEvents.gameObject, givenInteractableObject.allowedUseControllers)));
 }
Beispiel #37
0
 protected virtual void InitSecondaryGrab(VRTK_InteractableObject currentGrabbedObject)
 {
     influencingGrabbedObject = true;
     currentGrabbedObject.Grabbed(this);
 }
        private void StartUseAction(Transform target)
        {
            interactableObject = target.GetComponent<VRTK_InteractableObject>();
            bool cannotUseBecauseNotGrabbed = (interactableObject && interactableObject.useOnlyIfGrabbed && !interactableObject.IsGrabbed());

            if (PointerActivatesUseAction(interactableObject) && interactableObject.holdButtonToUse && !cannotUseBecauseNotGrabbed)
            {
                interactableObject.StartUsing(gameObject);
            }
        }
Beispiel #39
0
 /// <summary>
 /// The ClearPreviousClone method resets the previous cloned object to null to ensure when the script is re-enabled that a new cloned object is created, rather than the original clone being grabbed again.
 /// </summary>
 public virtual void ClearPreviousClone()
 {
     previousClonedObject = null;
 }
Beispiel #40
0
    // Use this for initialization
    protected virtual void Start()
    {
        //一度だけキャッシュする
        if (typeAnimationUtility == null)
        {
            typeAnimationUtility = System.Reflection.Assembly.Load("UnityEditor.dll").GetType("UnityEditor.AnimationUtility");
        }

        meshFilter        = GetComponent <MeshFilter>();
        renderer          = GetComponent <Renderer>();
        renderer.material = normalMaterial;

        transform.localScale = new Vector3(colliderSize, colliderSize, colliderSize);
        if (followTarget == null)
        {
            return;
        }

        //既存Collider削除
        var colliders = followTarget.gameObject.GetComponents <Collider>();

        foreach (var collider in colliders)
        {
            DestroyImmediate(collider);
        }

        //既存Rigidbody削除
        var rigidBody = followTarget.gameObject.GetComponent <Rigidbody>();

        if (rigidBody)
        {
            DestroyImmediate(rigidBody);
        }

        //その他既存の余計な物削除
        var fixedJointGrabAttach = followTarget.GetComponent <VRTK.GrabAttachMechanics.VRTK_FixedJointGrabAttach>();

        if (fixedJointGrabAttach)
        {
            DestroyImmediate(fixedJointGrabAttach);
        }

        interactableObject = followTarget.GetComponent <VRTK.VRTK_InteractableObject>();
        if (interactableObject)
        {
            DestroyImmediate(interactableObject);
        }

        followTarget.gameObject.layer = LayerMask.NameToLayer("Node");

        targetCollider        = followTarget.gameObject.AddComponent <BoxCollider>();
        targetCollider.center = Vector3.zero;
        fixedJointGrabAttach  = followTarget.gameObject.AddComponent <VRTK.GrabAttachMechanics.VRTK_FixedJointGrabAttach>();
        fixedJointGrabAttach.precisionGrab = true;
        targetRigidbody             = followTarget.gameObject.AddComponent <Rigidbody>();
        targetRigidbody.isKinematic = true;

        //targetにScalingNodeが付いてたらノードスケール変更
        var scalingNode = followTarget.GetComponent <ScalingNode>();

        if (scalingNode)
        {
            colliderSize *= scalingNode.scale;
        }

        /*if (type == eNodeType.FK)//FKNodeは移動できない
         * {
         *  rigidBody.constraints = RigidbodyConstraints.FreezePosition;
         * }*/

        interactableObject             = followTarget.gameObject.AddComponent <VRTK.VRTK_InteractableObject>();
        interactableObject.isGrabbable = true;
        interactableObject.InteractableObjectGrabbed   += new VRTK.InteractableObjectEventHandler(DoObjectGrab);
        interactableObject.InteractableObjectUngrabbed += new VRTK.InteractableObjectEventHandler(DoObjectUngrabbed);

        //親のNodeかどうか
        var parentTarget = followTarget.parent;

        if (parentTarget == null)
        {
            isParent = true;
        }
        else
        {
            if (generateNodes.transformToNodeDic.ContainsKey(parentTarget)) //親がNodeなら子
            {
                isParent   = false;
                parentNode = generateNodes.transformToNodeDic[parentTarget];
            }
            else
            {
                isParent   = true;
                parentNode = null;
            }
        }

        List <Node> childNodeList = new List <Node>();

        //子のNodeをすべて取得
        for (int i = 0; i < followTarget.childCount; i++)
        {
            var child = followTarget.GetChild(i);
            if (generateNodes.transformToNodeDic.ContainsKey(child))
            {
                childNodeList.Add(generateNodes.transformToNodeDic[child]);
            }
        }
        childNodes = childNodeList.ToArray();
    }
Beispiel #41
0
        public virtual IEnumerator AutoGrab()
        {
            yield return new WaitForEndOfFrame();

            interactTouch = (interactTouch != null ? interactTouch : GetComponentInParent<VRTK_InteractTouch>());
            interactGrab = (interactGrab != null ? interactGrab : GetComponentInParent<VRTK_InteractGrab>());

            if (interactTouch == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_NOT_INJECTED, "VRTK_ObjectAutoGrab", "VRTK_InteractTouch", "interactTouch", "the same or parent"));
            }

            if (interactGrab == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_NOT_INJECTED, "VRTK_ObjectAutoGrab", "VRTK_InteractGrab", "interactGrab", "the same or parent"));
            }

            if (objectToGrab == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.NOT_DEFINED, "objectToGrab"));
                yield break;
            }

            while (interactGrab.controllerAttachPoint == null)
            {
                yield return true;
            }

            bool grabbableObjectDisableState = objectToGrab.disableWhenIdle;

            if (objectIsPrefab)
            {
                objectToGrab.disableWhenIdle = false;
            }

            VRTK_InteractableObject grabbableObject = objectToGrab;
            if (alwaysCloneOnEnable)
            {
                ClearPreviousClone();
            }

            if (!interactGrab.GetGrabbedObject())
            {
                if (cloneGrabbedObject)
                {
                    if (previousClonedObject == null)
                    {
                        grabbableObject = Instantiate(objectToGrab);
                        previousClonedObject = grabbableObject;
                    }
                    else
                    {
                        grabbableObject = previousClonedObject;
                    }
                }

                if (grabbableObject.isGrabbable && !grabbableObject.IsGrabbed())
                {
                    grabbableObject.transform.position = transform.position;
                    interactTouch.ForceStopTouching();
                    interactTouch.ForceTouch(grabbableObject.gameObject);
                    interactGrab.AttemptGrab();
                    OnObjectAutoGrabCompleted();
                }
            }
            objectToGrab.disableWhenIdle = grabbableObjectDisableState;
            grabbableObject.disableWhenIdle = grabbableObjectDisableState;
        }
Beispiel #42
0
    void SetClip(GameObject clipObj, Collider other, bool fast = false)
    {
        if (isEmpty)
        {
            isEmpty = false;
            if (!fast)
            {
                doHack = true;
            }
            Collider collider = other;
            VRTK.VRTK_InteractableObject interaction = clipObj.GetComponent <VRTK.VRTK_InteractableObject>();
            Rigidbody body = clipObj.GetComponent <Rigidbody>();
            interaction.ForceStopInteracting();
            interaction.isGrabbable = false;
            // interaction.enabled = false;
            collider.enabled = false;
            originalPosition = clipObj.transform.localPosition;
            originalRotation = clipObj.transform.localRotation;
            if (!fast)
            {
                clipObj.transform.SetParent(newClipParent);
            }
            else
            {
                clipObj.transform.SetParent(currentClipParent);
            }
            clipObj.transform.localPosition = Vector3.zero;
            clipObj.transform.localRotation = Quaternion.identity;

            if (!fast)
            {
                clipChangeAnimator.SetTrigger("PutIn");
            }
            body.isKinematic = true;
            oldClip          = currentClip;
            currentClip      = clipObj;
            //  AkSoundEngine.PostEvent(removeClipEvent, soundEmitter);

            if (!fast)
            {
                StartCoroutine(OnClipChangeComplete());
            }
        }
        else
        {
            isEmpty = false;
            doHack  = true;
            Collider collider = other;
            VRTK.VRTK_InteractableObject interaction = clipObj.GetComponent <VRTK.VRTK_InteractableObject>();
            Rigidbody body = clipObj.GetComponent <Rigidbody>();
            interaction.ForceStopInteracting();
            interaction.isGrabbable = false;
            // interaction.enabled = false;
            collider.enabled = false;
            originalPosition = clipObj.transform.localPosition;
            originalRotation = clipObj.transform.localRotation;
            clipObj.transform.SetParent(newClipParent);
            clipObj.transform.localPosition = Vector3.zero;
            clipObj.transform.localRotation = Quaternion.identity;

            clipChangeAnimator.SetTrigger("Change");
            body.isKinematic = true;
            oldClip          = currentClip;
            currentClip      = clipObj;
            //  AkSoundEngine.PostEvent(removeClipEvent, soundEmitter);

            StartCoroutine(OnClipChangeComplete());
        }
    }
        protected virtual bool IsObjectGrabbable(GameObject obj)
        {
            VRTK_InteractableObject objScript = obj.GetComponent <VRTK_InteractableObject>();

            return(interactTouch != null && interactTouch.IsObjectInteractable(obj) && objScript != null && (objScript.isGrabbable || objScript.PerformSecondaryAction()));
        }
 private void CheckHideController(VRTK_InteractableObject touchedObjectScript)
 {
     updatedHideControllerOnTouch = touchedObjectScript.CheckHideMode(hideControllerOnTouch, touchedObjectScript.hideControllerOnTouch);
     if (controllerActions.IsControllerVisible() && updatedHideControllerOnTouch)
     {
         Invoke("HideController", hideControllerDelay);
     }
 }
 protected virtual bool ScriptValidGrab(VRTK_InteractableObject objectToGrabScript)
 {
     return(objectToGrabScript != null && objectToGrabScript.grabAttachMechanicScript != null && objectToGrabScript.grabAttachMechanicScript.ValidGrab(controllerAttachPoint));
 }
Beispiel #46
0
 // Use this for initialization
 void Start()
 {
     objectHandler = GetComponent<VRTK.VRTK_InteractableObject>();
 }
        private void InitBody()
        {
            rb = GetComponent<Rigidbody>();
            if (rb == null)
            {
                rb = gameObject.AddComponent<Rigidbody>();
            }
            rb.isKinematic = false;

            io = GetComponent<VRTK_InteractableObject>();
            if (io == null)
            {
                io = gameObject.AddComponent<VRTK_InteractableObject>();
            }
            io.isGrabbable = true;
            io.precisionSnap = true;
            io.grabAttachMechanic = VRTK_InteractableObject.GrabAttachType.Spring_Joint;

            cj = GetComponent<ConfigurableJoint>();
            if (cj == null)
            {
                cj = gameObject.AddComponent<ConfigurableJoint>();
                cj.angularXMotion = ConfigurableJointMotion.Locked;
                cj.angularYMotion = ConfigurableJointMotion.Locked;
                cj.angularZMotion = ConfigurableJointMotion.Locked;
                cj.configuredInWorldSpace = false;
                cjCreated = true;
            }
        }