public void OnToggleChange(bool newState)
    {
        // Hide/Show the nodes!
        foreach (Transform t in GameObject.Find("/DestinationPoints").transform)
        {
            t.gameObject.SetActive(newState);
        }

        // Edit the VRTK target policy!  It's on the right hand, but the Remote uses it too.
        VRTK_PolicyList policy = VRTK.VRTK_DeviceFinder.GetControllerRightHand().GetComponent <VRTK_PolicyList> ();

        if (newState)
        {
            policy.identifiers = new List <string> {
                "MazeWalls", "Default"
            };
        }
        else
        {
            policy.identifiers = new List <string> {
                "MazeWalls", "DestinationPoints"
            };
        }
        restrictToNodes = newState;
    }
Example #2
0
 private void OnEnable()
 {
     if (m_PolicyList == null)
     {
         m_PolicyList = GameObject.FindGameObjectWithTag("CabelPolicy").GetComponent <VRTK_PolicyList>();
     }
     m_Indicator          = transform.Find("Indicator").GetComponent <MeshRenderer>().material;
     m_InteractableObject = (m_InteractableObject == null ? GetComponent <VRTK_InteractableObject>() : m_InteractableObject);
     if (m_InteractableObject != null)
     {
         m_InteractableObject.InteractableObjectUsed += M_InteractableObject_InteractableObjectUsed;
     }
 }
        protected virtual VRTK_InteractableObject ValidInteractableObject(GameObject checkObject)
        {
            var currentInteractableObject = checkObject.GetComponentInParent <VRTK_InteractableObject>();

            return(currentInteractableObject != null && !VRTK_PolicyList.Check(currentInteractableObject.gameObject, validObjectListPolicy) ? currentInteractableObject : null);
        }
Example #4
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);
        }