Ejemplo n.º 1
0
        //-------------------------------------------------
        private void ShowText(ISteamVR_Action_In_Source action, string text, bool highlightButton = true)
        {
            if (actionHintInfos.ContainsKey(action))
            {
                ActionHintInfo hintInfo = actionHintInfos[action];
                hintInfo.textHintObject.SetActive(true);
                hintInfo.textHintActive = true;

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

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

                UpdateTextHint(hintInfo);

                if (highlightButton)
                {
                    ShowButtonHint(action);
                }

                renderModel.gameObject.SetActive(true);
            }
        }
Ejemplo n.º 2
0
        //-------------------------------------------------
        private void ShowButtonHint(params ISteamVR_Action_In_Source[] actions)
        {
            renderModel.gameObject.SetActive(true);

            renderModel.GetComponentsInChildren <MeshRenderer>(renderers);
            for (int i = 0; i < renderers.Count; i++)
            {
                Texture mainTexture = renderers[i].material.mainTexture;
                renderers[i].sharedMaterial       = controllerMaterial;
                renderers[i].material.mainTexture = mainTexture;

                // This is to poke unity into setting the correct render queue for the model
                renderers[i].material.renderQueue = controllerMaterial.shader.renderQueue;
            }

            for (int i = 0; i < actions.Length; i++)
            {
                if (actionHintInfos.ContainsKey(actions[i]))
                {
                    ActionHintInfo hintInfo = actionHintInfos[actions[i]];
                    foreach (MeshRenderer renderer in hintInfo.renderers)
                    {
                        if (!flashingRenderers.Contains(renderer))
                        {
                            flashingRenderers.Add(renderer);
                        }
                    }
                }
            }

            startTime = Time.realtimeSinceStartup;
            tickCount = 0.0f;
        }
Ejemplo n.º 3
0
        //-------------------------------------------------
        private void UpdateTextHint(ActionHintInfo hintInfo)
        {
            Transform playerTransform = player.hmdTransform;
            Vector3   vDir            = playerTransform.position - hintInfo.canvasOffset.position;

            Quaternion standardLookat   = Quaternion.LookRotation(vDir, Vector3.up);
            Quaternion upsideDownLookat = Quaternion.LookRotation(vDir, playerTransform.up);

            float flInterp;

            if (playerTransform.forward.y > 0.0f)
            {
                flInterp = Util.RemapNumberClamped(playerTransform.forward.y, 0.6f, 0.4f, 1.0f, 0.0f);
            }
            else
            {
                flInterp = Util.RemapNumberClamped(playerTransform.forward.y, -0.8f, -0.6f, 1.0f, 0.0f);
            }

            hintInfo.canvasOffset.rotation = Quaternion.Slerp(standardLookat, upsideDownLookat, flInterp);

            Transform lineTransform = hintInfo.line.transform;

            hintInfo.line.useWorldSpace = false;
            hintInfo.line.SetPosition(0, lineTransform.InverseTransformPoint(hintInfo.textStartAnchor.position));
            hintInfo.line.SetPosition(1, lineTransform.InverseTransformPoint(hintInfo.textEndAnchor.position));
        }
        //-------------------------------------------------
        private void HideButtonHint(params ISteamVR_Action_In_Source[] actions)
        {
            Color baseColor = controllerMaterial.GetColor(colorID);

            for (int i = 0; i < actions.Length; i++)
            {
                if (actionHintInfos.ContainsKey(actions[i]))
                {
                    ActionHintInfo hintInfo = actionHintInfos[actions[i]];
                    foreach (MeshRenderer renderer in hintInfo.renderers)
                    {
                        renderer.material.color = baseColor;
                        if (flashingRenderers.Contains(renderer))
                        {
                            flashingRenderers.Remove(renderer);
                            hand.hintsActive--;
                        }
                    }
                }
            }

            if (hand.hintsActive == 0)
            {
                if (!hand.isControllerActive)
                {
                    hand.ResetTemporarySkeletonRangeOfMotion();
                }
                renderModel.gameObject.SetActive(false);
            }
        }
Ejemplo n.º 5
0
        //-------------------------------------------------
        private void HideText(ISteamVR_Action_In_Source action)
        {
            if (actionHintInfos.ContainsKey(action))
            {
                ActionHintInfo hintInfo = actionHintInfos[action];
                hintInfo.textHintObject.SetActive(false);
                hintInfo.textHintActive = false;

                HideButtonHint(action);
            }
        }
Ejemplo n.º 6
0
 //-------------------------------------------------
 private string GetActiveHintText(ISteamVR_Action_In_Source action)
 {
     if (actionHintInfos.ContainsKey(action))
     {
         ActionHintInfo hintInfo = actionHintInfos[action];
         if (hintInfo.textHintActive)
         {
             return(hintInfo.text.text);
         }
     }
     return(string.Empty);
 }
Ejemplo n.º 7
0
        //-------------------------------------------------
        private bool IsButtonHintActive(ISteamVR_Action_In_Source action)
        {
            if (actionHintInfos.ContainsKey(action))
            {
                ActionHintInfo hintInfo = actionHintInfos[action];
                foreach (MeshRenderer buttonRenderer in hintInfo.renderers)
                {
                    if (flashingRenderers.Contains(buttonRenderer))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 8
0
        //-------------------------------------------------
        private void HideButtonHint(params ISteamVR_Action_In_Source[] actions)
        {
            Color baseColor = usingMaterial.GetColor(colorID);

            for (int i = 0; i < actions.Length; i++)
            {
                if (actionHintInfos.ContainsKey(actions[i]))
                {
                    ActionHintInfo hintInfo = actionHintInfos[actions[i]];
                    foreach (MeshRenderer renderer in hintInfo.renderers)
                    {
                        renderer.material.color = baseColor;
                        flashingRenderers.Remove(renderer);
                    }
                }
            }

            if (flashingRenderers.Count == 0)
            {
                renderModel.gameObject.SetActive(false);
            }
        }
        //-------------------------------------------------
        private void ShowText(ISteamVR_Action_In_Source action, string text, bool rendering, bool highlightButton = true)
        {
            if (actionHintInfos.ContainsKey(action))
            {
                ActionHintInfo hintInfo = actionHintInfos[action];
                hintInfo.textHintObject.SetActive(true);
                hintInfo.textHintActive = true;

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

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

                UpdateTextHint(hintInfo);

                if (highlightButton)
                {
                    ShowButtonHint(action);
                }
                renderModel.gameObject.SetActive(true);
                Color color;
                if (rendering)
                {
                    color = new Color(1, 1, 1, 0.125f);
                }
                else
                {
                    color = new Color(1, 1, 1, 0);
                }
                controllerMaterial.color = color;
            }
        }
Ejemplo n.º 10
0
        //-------------------------------------------------
        private void CreateAndAddButtonInfo(ISteamVR_Action_In action, SteamVR_Input_Sources inputSource)
        {
            Transform           buttonTransform = null;
            List <MeshRenderer> buttonRenderers = new List <MeshRenderer>();

            StringBuilder buttonDebug = new StringBuilder();

            buttonDebug.Append("Looking for action: ");

            buttonDebug.AppendLine(action.GetShortName());

            buttonDebug.Append("Action localized origin: ");
            buttonDebug.AppendLine(action.GetLocalizedOrigin(inputSource));

            string actionComponentName = action.GetRenderModelComponentName(inputSource);

            if (componentTransformMap.ContainsKey(actionComponentName))
            {
                buttonDebug.AppendLine(string.Format("Found component: {0} for {1}", actionComponentName, action.GetShortName()));
                Transform componentTransform = componentTransformMap[actionComponentName];

                buttonTransform = componentTransform;

                buttonDebug.AppendLine(string.Format("Found componentTransform: {0}. buttonTransform: {1}", componentTransform, buttonTransform));

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

            buttonDebug.AppendLine(string.Format("Found {0} renderers for {1}", buttonRenderers.Count, action.GetShortName()));

            foreach (MeshRenderer renderer in buttonRenderers)
            {
                buttonDebug.Append("\t");
                buttonDebug.AppendLine(renderer.name);
            }

            HintDebugLog(buttonDebug.ToString());

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

            ActionHintInfo hintInfo = new ActionHintInfo();

            actionHintInfos.Add(action, hintInfo);

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

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

            OffsetType 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
            Vector3 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);
        }