Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        phase                = "Done";
        prePos               = cube.transform.position;
        preRot               = cube.transform.rotation;
        progress             = 0;
        delay                = delayTime;
        grabLeft.text        = "";
        grabRight.text       = "";
        triggerLeft.text     = "";
        triggerRight.text    = "";
        menuLeft.text        = "";
        menuRight.text       = "";
        currentMode.text     = "";
        anatomicalPlane.text = "";
        TwoSideText          = "One side view";
        ShaderNumber         = 1;
        backBar.localScale   = new Vector3(barLength, barWidth, 1);
        defaultColor         = Color.gray;
        Transform lgrip = leftWandRenderer.FindComponent("lgrip");

        if (lgrip != null)
        {
            defaultColor = lgrip.GetComponent <MeshRenderer>().material.color;
        }
    }
        private void OnRenderModelLoaded(SteamVR_RenderModel renderModel, bool success)
        {
            Assert.IsNotNull(renderModel);
            if (renderModel != _sourceModel)
            {
                Restore();
                return;
            }

            if (!success)
            {
                Restore();
                return;
            }

            var tip = _sourceModel.FindComponent("tip");

            if (tip != null)
            {
                Assert.IsTrue(tip.childCount >= 1);

                var attach = tip.GetChild(0);
                Assert.IsNotNull(attach);

                _origin = attach;
                _selfTransform.position = _origin.position + _currentOffset;
                _selfTransform.rotation = _origin.rotation;
            }
            else
            {
                Restore();
            }
        }
    void FlashRenderers(string componentName)
    {
        Transform component = renderModel.FindComponent(componentName);

        if (component != null)
        {
            component.GetComponentsInChildren <MeshRenderer>(temp);
            flashingRenderers.AddRange(temp);
            temp.Clear();
        }
    }
        //-------------------------------------------------
        private void CreateAndAddButtonInfo(EVRButtonId buttonID)
        {
            Transform           buttonTransform = null;
            List <MeshRenderer> buttonRenderers = new List <MeshRenderer>();

            string buttonDebug = "Looking for button: " + buttonID;

            EVRButtonId searchButtonID = buttonID;

            if (buttonID == EVRButtonId.k_EButton_Grip && SteamVR.instance.hmd_TrackingSystemName.ToLowerInvariant().Contains("oculus"))
            {
                searchButtonID = EVRButtonId.k_EButton_Axis2;
            }
            ulong buttonMaskForID = (1ul << (int)searchButtonID);

            foreach (KeyValuePair <string, ulong> componentButtonMask in componentButtonMasks)
            {
                if ((componentButtonMask.Value & buttonMaskForID) == buttonMaskForID)
                {
                    buttonDebug += "\nFound component: " + componentButtonMask.Key + " " + componentButtonMask.Value;
                    Transform componentTransform = renderModel.FindComponent(componentButtonMask.Key);

                    buttonTransform = componentTransform;

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

                    buttonRenderers.AddRange(componentTransform.GetComponentsInChildren <MeshRenderer>());
                }
            }

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

            HintDebugLog(buttonDebug);

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

            ButtonHintInfo hintInfo = new ButtonHintInfo();

            buttonHintInfos.Add(buttonID, hintInfo);

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

            //Get the local transform for the button
            hintInfo.localTransform = buttonTransform.Find(SteamVR_RenderModel.k_localTransformName);

            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);
        }
Beispiel #5
0
    private void highlight(string part)
    {
        switch (part)
        {
        case ("leftGrip"):
        {
            Transform lgrip = leftWandRenderer.FindComponent("lgrip");
            if (lgrip != null)
            {
                lgrip.GetComponent <MeshRenderer>().material.color = Color.Lerp(defaultColor, highlightColor, Mathf.PingPong(Time.time, 1));
            }
            lgrip = rightWandRenderer.FindComponent("lgrip");
            if (lgrip != null)
            {
                lgrip.GetComponent <MeshRenderer>().material.color = Color.Lerp(defaultColor, highlightColor, Mathf.PingPong(Time.time, 1));
            }
            break;
        }

        case ("rightGrip"):
        {
            Transform rgrip = leftWandRenderer.FindComponent("rgrip");
            if (rgrip != null)
            {
                rgrip.GetComponent <MeshRenderer>().material.color = Color.Lerp(defaultColor, highlightColor, Mathf.PingPong(Time.time, 1));
            }
            rgrip = rightWandRenderer.FindComponent("rgrip");
            if (rgrip != null)
            {
                rgrip.GetComponent <MeshRenderer>().material.color = Color.Lerp(defaultColor, highlightColor, Mathf.PingPong(Time.time, 1));
            }
            break;
        }

        case ("leftTrigger"):
        {
            Transform trigger = leftWandRenderer.FindComponent("trigger");
            if (trigger != null)
            {
                trigger.GetComponent <MeshRenderer>().material.color = Color.Lerp(defaultColor, highlightColor, Mathf.PingPong(Time.time, 1));
            }
            break;
        }

        case ("rightTrigger"):
        {
            Transform trigger = rightWandRenderer.FindComponent("trigger");
            if (trigger != null)
            {
                trigger.GetComponent <MeshRenderer>().material.color = Color.Lerp(defaultColor, highlightColor, Mathf.PingPong(Time.time, 1));
            }
            break;
        }

        case ("leftMenu"):
        {
            Transform menu = leftWandRenderer.FindComponent("button");
            if (menu != null)
            {
                menu.GetComponent <MeshRenderer>().material.color = Color.Lerp(defaultColor, highlightColor, Mathf.PingPong(Time.time, 1));
            }
            break;
        }

        case ("rightMenu"):
        {
            Transform menu = rightWandRenderer.FindComponent("button");
            if (menu != null)
            {
                menu.GetComponent <MeshRenderer>().material.color = Color.Lerp(defaultColor, highlightColor, Mathf.PingPong(Time.time, 1));
            }
            break;
        }
        }
    }