Пример #1
0
        public void Enable(IHandController ctl)
        {
            if (point != null)
            {
                GameObject.Destroy(point);
            }
            if (renderer != null)
            {
                GameObject.Destroy(renderer);
            }
            if (raycast != null)
            {
                GameObject.Destroy(raycast);
            }

            point    = ctl.gameObject.AddComponent <VRTK_Pointer>();
            renderer = ctl.gameObject.AddComponent <VRTK_StraightPointerRenderer>();
            raycast  = ctl.gameObject.AddComponent <VRTK_CustomRaycast>();

            point.pointerRenderer  = renderer;
            renderer.customRaycast = raycast;

            point.enableTeleport   = false;
            point.activationButton = VRTK_ControllerEvents.ButtonAlias.TriggerPress;
            raycast.layersToIgnore = ctl.Player.PointerIgnoreLayers;
        }
Пример #2
0
    private bool ControllerRaycast(out Vector3 hitPoint)
    {
        Ray        ray = new Ray(m_controllerEvents.transform.position, transform.forward);
        RaycastHit hit;

        if (VRTK_CustomRaycast.Raycast(m_customRaycast, ray, out hit, m_layersToIgnore, m_maxDistance))
        {
            hitPoint = hit.point;

            if (m_coneDrag)
            {
                Vector3 groundPos = m_playArea.position;

                // find ground below play area
                RaycastHit groundHit;
                Ray        groundRay = new Ray(new Vector3(groundPos.x, m_headset.position.y, groundPos.z), Vector3.down);
                if (VRTK_CustomRaycast.Raycast(m_customRaycast, groundRay, out groundHit, m_layersToIgnore))
                {
                    groundPos = groundHit.point;
                }

                // a "ramp"
                m_plane = new Plane(groundPos, hitPoint, groundPos + Vector3.Cross(Vector3.up, hitPoint - groundPos));
            }
            else
            {
                m_plane = new Plane(Vector3.up, hitPoint);
            }
            return(true);
        }

        hitPoint = Vector3.zero;
        return(false);
    }
Пример #3
0
        public void Enable(IHandController ctl)
        {
            if (point != null)
            {
                GameObject.Destroy(point);
            }
            if (renderer != null)
            {
                GameObject.Destroy(renderer);
            }
            if (raycast != null)
            {
                GameObject.Destroy(raycast);
            }

            point    = ctl.gameObject.AddComponent <VRTK_Pointer>();
            renderer = ctl.gameObject.AddComponent <VRTK_BezierPointerRenderer>();
            raycast  = ctl.gameObject.AddComponent <VRTK_CustomRaycast>();

            point.pointerRenderer  = renderer;
            renderer.customRaycast = raycast;

            point.enableTeleport   = true;
            point.activationButton = VRTK_ControllerEvents.ButtonAlias.TriggerPress;
            point.selectionButton  = VRTK_ControllerEvents.ButtonAlias.TriggerPress;
            point.selectOnPress    = false;
            raycast.layersToIgnore = ctl.Player.PointerIgnoreLayers;

            ctl.Player.Teleport.InitDestinationSetListener(ctl.gameObject, true);
        }
Пример #4
0
    private GameObject GetCollidedObject(out RaycastHit pointerCollidedWith)
    {
        Transform origin         = GetOrigin();
        Ray       pointerRaycast = new Ray(origin.position, origin.forward);
        bool      rayHit         = VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out pointerCollidedWith, defaultIgnoreLayer, maximumLength);

        if (pointerCollidedWith.collider != null)
        {
            return(pointerCollidedWith.collider.gameObject);
        }
        else
        {
            return(null);
        }
    }
Пример #5
0
    // Identical to VRTK_StraightPointerRenderer except we return actual ray length instead of truncated ray
    protected override float CastRayForward()
    {
        Transform  origin         = GetOrigin();
        Ray        pointerRaycast = new Ray(origin.position, origin.forward);
        RaycastHit pointerCollidedWith;

        customRaycast = new VRTK_CustomRaycast();
        customRaycast.layersToIgnore = LayerMask.NameToLayer("Ignore Raycast");
#pragma warning disable 0618
        bool rayHit = VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out pointerCollidedWith, layersToIgnore, maximumLength);
#pragma warning restore 0618

        CheckRayMiss(rayHit, pointerCollidedWith);
        CheckRayHit(rayHit, pointerCollidedWith);

        float actualLength = maximumLength;
        if (rayHit && pointerCollidedWith.distance < maximumLength)
        {
            actualLength = pointerCollidedWith.distance;
        }

        return(actualLength);
    }
Пример #6
0
        public void Enable(IHandController ctl)
        {
            ctl.Events.ButtonTwoPressed += OnMenu;

            if (point != null)
            {
                GameObject.Destroy(point);
            }
            if (renderer != null)
            {
                GameObject.Destroy(renderer);
            }
            if (raycast != null)
            {
                GameObject.Destroy(raycast);
            }
            if (policyList != null)
            {
                GameObject.Destroy(policyList);
            }
            if (menuObj != null)
            {
                GameObject.Destroy(menuObj);
            }
            // No need to destroy menu, as it should have been attached to menuObj
            // (and if it wasn't then we have bigger problems to worry about)

            point      = ctl.gameObject.AddComponent <VRTK_Pointer>();
            renderer   = ctl.gameObject.AddComponent <VRTK_StraightPointerRenderer>();
            raycast    = ctl.gameObject.AddComponent <VRTK_CustomRaycast>();
            policyList = ctl.gameObject.AddComponent <VRTK_PolicyList>();
            menuObj    = new GameObject("ModeMenu");
            menu       = menuObj.AddComponent <ModeMenu>();

            point.pointerRenderer  = renderer;
            point.targetListPolicy = policyList;
            renderer.customRaycast = raycast;

            point.enableTeleport   = false;
            point.activationButton = VRTK_ControllerEvents.ButtonAlias.TriggerPress;
            point.selectionButton  = VRTK_ControllerEvents.ButtonAlias.TriggerPress;
            point.selectOnPress    = false;
            raycast.layersToIgnore = ctl.Player.PointerIgnoreLayers;
            policyList.checkType   = VRTK_PolicyList.CheckTypes.Script;
            policyList.operation   = VRTK_PolicyList.OperationTypes.Include;
            policyList.identifiers = new List <string> {
                nameof(ModeMenuItem)
            };

            point.DestinationMarkerEnter += (sender, e) => Debug.Log(e.target);
            point.DestinationMarkerSet   += (sender, e) => {
                var item = e.target.GetComponent <ModeMenuItem>();

                if (item != null)
                {
                    switch (item.type)
                    {
                    case ModeMenuItem.ModeType.Primary: modeCtl.SelectPrimary(item.index); break;

                    case ModeMenuItem.ModeType.Grip: modeCtl.SelectGrip(item.index); break;
                    }

                    modeCtl.EndMenu();
                }
            };

            menuObj.transform.position = ctl.gameObject.transform.position;
            // The ternary ensures the menu's not flipped if you're pointing the controller backwards
            menuObj.transform.rotation = Quaternion.Euler(
                0.0f,
                ctl.gameObject.transform.eulerAngles.y + (ctl.gameObject.transform.up.y < 0.0f ? 180.0f : 0.0f),
                0.0f);
            menuObj.transform.localScale = ctl.gameObject.transform.lossyScale;

            menu.Init(ctl.Player, modeCtl);
        }