void OnChange(SteamVR_Action_In action) //Creates and deploys an Event on any Input action
        {
            STKEventSender sender = GetComponent <STKEventSender>();

            sender.SetEventValue("Name", action.GetShortName());
            if (action.GetType() == typeof(SteamVR_Action_Boolean))
            {
                SteamVR_Action_Boolean v = (SteamVR_Action_Boolean)action;
                sender.SetEventValue("boolValue", v.GetState(SteamVR_Input_Sources.Any));
            }
            else if (action.GetType() == typeof(SteamVR_Action_Single))
            {
                SteamVR_Action_Single v = (SteamVR_Action_Single)action;
                sender.SetEventValue("singleValue", v.GetAxis(SteamVR_Input_Sources.Any));
            }
            else if (action.GetType() == typeof(SteamVR_Action_Vector2))
            {
                SteamVR_Action_Vector2 v = (SteamVR_Action_Vector2)action;
                sender.SetEventValue("vector2Value", v.GetAxis(SteamVR_Input_Sources.Any));
            }
            else if (action.GetType() == typeof(SteamVR_Action_Vector3))
            {
                SteamVR_Action_Vector3 v = (SteamVR_Action_Vector3)action;
                sender.SetEventValue("vector3Value", v.GetAxis(SteamVR_Input_Sources.Any));
            }
            sender.Deploy();
        }
Пример #2
0
        //-------------------------------------------------
        private IEnumerator TestTextHints()
        {
            while (true)
            {
                for (int actionIndex = 0; actionIndex < SteamVR_Input.actionsNonPoseNonSkeletonIn.Length; actionIndex++)
                {
                    SteamVR_Action_In action = (SteamVR_Action_In)SteamVR_Input.actionsNonPoseNonSkeletonIn[actionIndex];
                    if (action.GetActive(inputSource))
                    {
                        ShowText(action, action.GetShortName());
                        yield return(new WaitForSeconds(3.0f));
                    }
                    yield return(null);
                }

                HideAllText();
                yield return(new WaitForSeconds(3.0f));
            }
        }
Пример #3
0
        //-------------------------------------------------
        // Cycles through all the text hints on the controller
        //-------------------------------------------------
        private IEnumerator TestTextHints(Hand hand)
        {
            ControllerButtonHints.HideAllTextHints(hand);

            while (true)
            {
                for (int actionIndex = 0; actionIndex < SteamVR_Input.actionsIn.Length; actionIndex++)
                {
                    SteamVR_Action_In action = (SteamVR_Action_In)SteamVR_Input.actionsIn[actionIndex];
                    if (action.GetActive(hand.handType))
                    {
                        ControllerButtonHints.ShowTextHint(hand, action, action.GetShortName());
                        yield return(new WaitForSeconds(3.0f));

                        ControllerButtonHints.HideTextHint(hand, action);
                        yield return(new WaitForSeconds(0.5f));
                    }
                    yield return(null);
                }

                ControllerButtonHints.HideAllTextHints(hand);
                yield return(new WaitForSeconds(3.0f));
            }
        }
Пример #4
0
        //-------------------------------------------------
        private void CreateAndAddButtonInfo(SteamVR_Action_In action, SteamVR_Input_Sources inputSource)
        {
            Transform buttonTransform = null;
            var       buttonRenderers = new List <MeshRenderer>();

            var buttonDebug = "Looking for action: " + action.GetShortName();

            var actionComponentName = action.GetDeviceComponentName(inputSource);

            if (componentTransformMap.ContainsKey(actionComponentName))
            {
                buttonDebug += "\nFound component: " + actionComponentName + " for " + action.GetShortName();
                var componentTransform = componentTransformMap[actionComponentName];

                buttonTransform = componentTransform;

                buttonDebug += "\nFound componentTransform: " + componentTransform + " buttonTransform: " + buttonTransform;

                buttonRenderers.AddRange(componentTransform.GetComponentsInChildren <MeshRenderer>());
            }
            else
            {
                buttonDebug += string.Format("\nCan't find component transform for action: {0}. Component name: \"{1}\"", action.GetShortName(), actionComponentName);
            }

            buttonDebug += "\nFound " + buttonRenderers.Count + " renderers for " + action.GetShortName();
            foreach (var renderer in buttonRenderers)
            {
                buttonDebug += "\n\t" + renderer.name;
            }

            HintDebugLog(buttonDebug);

            if (buttonTransform == null)
            {
                HintDebugLog("Couldn't find buttonTransform for " + action.GetShortName());
                return;
            }

            var hintInfo = new ActionHintInfo();

            actionHintInfos.Add(action, hintInfo);

            hintInfo.componentName = buttonTransform.name;
            hintInfo.renderers     = buttonRenderers;

            //Get the local transform for the button
            for (var childIndex = 0; childIndex < buttonTransform.childCount; childIndex++)
            {
                var child = buttonTransform.GetChild(childIndex);
                if (child.name == SteamVR_RenderModel.k_localTransformName)
                {
                    hintInfo.localTransform = child;
                }
            }

            var offsetType = OffsetType.Right;

            /*
             * switch ( buttonID )
             *          {
             *                  case EVRButtonId.k_EButton_SteamVR_Trigger:
             *                          {
             *                                  offsetType = OffsetType.Right;
             *                          }
             *                          break;
             *                  case EVRButtonId.k_EButton_ApplicationMenu:
             *                          {
             *                                  offsetType = OffsetType.Right;
             *                          }
             *                          break;
             *                  case EVRButtonId.k_EButton_System:
             *                          {
             *                                  offsetType = OffsetType.Right;
             *                          }
             *                          break;
             *                  case Valve.VR.EVRButtonId.k_EButton_Grip:
             *                          {
             *                                  offsetType = OffsetType.Forward;
             *                          }
             *                          break;
             *                  case Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad:
             *                          {
             *                                  offsetType = OffsetType.Up;
             *                          }
             *                          break;
             *          }
             */

            //Offset for the text end transform
            switch (offsetType)
            {
            case OffsetType.Forward:
                hintInfo.textEndOffsetDir = hintInfo.localTransform.forward;
                break;

            case OffsetType.Back:
                hintInfo.textEndOffsetDir = -hintInfo.localTransform.forward;
                break;

            case OffsetType.Right:
                hintInfo.textEndOffsetDir = hintInfo.localTransform.right;
                break;

            case OffsetType.Up:
                hintInfo.textEndOffsetDir = hintInfo.localTransform.up;
                break;
            }

            //Create the text hint object
            var hintStartPos = hintInfo.localTransform.position + (hintInfo.localTransform.forward * 0.01f);

            hintInfo.textHintObject      = GameObject.Instantiate(textHintPrefab, hintStartPos, Quaternion.identity) as GameObject;
            hintInfo.textHintObject.name = "Hint_" + hintInfo.componentName + "_Start";
            hintInfo.textHintObject.transform.SetParent(textHintParent);
            hintInfo.textHintObject.layer = gameObject.layer;
            hintInfo.textHintObject.tag   = gameObject.tag;

            //Get all the relevant child objects
            hintInfo.textStartAnchor = hintInfo.textHintObject.transform.Find("Start");
            hintInfo.textEndAnchor   = hintInfo.textHintObject.transform.Find("End");
            hintInfo.canvasOffset    = hintInfo.textHintObject.transform.Find("CanvasOffset");
            hintInfo.line            = hintInfo.textHintObject.transform.Find("Line").GetComponent <LineRenderer>();
            hintInfo.textCanvas      = hintInfo.textHintObject.GetComponentInChildren <Canvas>();
            hintInfo.text            = hintInfo.textCanvas.GetComponentInChildren <Text>();
            hintInfo.textMesh        = hintInfo.textCanvas.GetComponentInChildren <TextMesh>();

            hintInfo.textHintObject.SetActive(false);

            hintInfo.textStartAnchor.position = hintStartPos;

            if (hintInfo.text != null)
            {
                hintInfo.text.text = hintInfo.componentName;
            }

            if (hintInfo.textMesh != null)
            {
                hintInfo.textMesh.text = hintInfo.componentName;
            }

            centerPosition += hintInfo.textStartAnchor.position;

            // Scale hint components to match player size
            hintInfo.textCanvas.transform.localScale      = Vector3.Scale(hintInfo.textCanvas.transform.localScale, player.transform.localScale);
            hintInfo.textStartAnchor.transform.localScale = Vector3.Scale(hintInfo.textStartAnchor.transform.localScale, player.transform.localScale);
            hintInfo.textEndAnchor.transform.localScale   = Vector3.Scale(hintInfo.textEndAnchor.transform.localScale, player.transform.localScale);
            hintInfo.line.transform.localScale            = Vector3.Scale(hintInfo.line.transform.localScale, player.transform.localScale);
        }