示例#1
0
    public void updateToolRingIcons()
    {
        if (toolRing != null)
        {
            // Make the tool ring become less transparent as it eases in:
            float alpha = Mathf.Pow(toolRing.transform.localPosition.y / toolRingY, 2f);

            float   scale    = 0.75f + 0.25f * alpha;
            Vector3 scaleVec = 0.045f * (new Vector3(scale, scale, scale));
            //toolRing.transform.localScale = new Vector3 (scale, scale, scale);

            float smallestAngleDiff = float.MaxValue;
            selectedToolEntry = null;

            foreach (Transform tf in toolRing.transform)
            {
                if (alpha > 0)
                {
                    tf.gameObject.SetActive(true);

                    float angleDiff = Mathf.Abs(-toolRing.transform.localEulerAngles.y - tf.localEulerAngles.y);
                    angleDiff = angleDiff % 360f;                               // Just to make sure...
                    if (angleDiff > 180f)
                    {
                        angleDiff = 360f - angleDiff;
                    }
                    Color col = (1f - angleDiff / 360f) * (iconColor);
                    // Make the tool ring become less transparent as
                    col.a        *= alpha;
                    tf.localScale = scaleVec;

                    if (tf.GetComponent <SpriteRenderer> () != null)
                    {
                        tf.GetComponent <SpriteRenderer> ().color = col;
                    }

                    if (angleDiff < smallestAngleDiff)
                    {
                        smallestAngleDiff = angleDiff;
                        selectedToolEntry = tf.GetComponent <ToolRingEntry> ();
                    }
                }
                else
                {
                    tf.gameObject.SetActive(false);
                }
            }
            if (selectedToolEntry != null)
            {
                Color col = Color.white;
                col.a *= alpha;
                selectedToolEntry.GetComponent <SpriteRenderer>().color = col;
                ActiveToolName.text = selectedToolEntry.name;
            }
            Color textCol = ActiveToolName.color;
            textCol.a            = alpha * alpha;
            ActiveToolName.color = textCol;
            ActiveToolName.transform.localScale = scaleVec * 0.1f;
        }
    }
示例#2
0
    /*! Create a new Tool Ring and add an entry for each available Tool.*/
    public void generateToolRing()
    {
        Controller lc = InputDeviceManager.instance.leftController;

        if (lc != null)
        {
            // If there's already a tool ring element, delete it:
            Transform oldToolRing = lc.transform.Find("ToolRingAnchor");
            if (oldToolRing != null)
            {
                Destroy(oldToolRing.gameObject);
            }

            // Create new Tool Ring:
            GameObject anchor = new GameObject("ToolRingAnchor");               // Anchor object for rotation/positon only.
            anchor.transform.SetParent(lc.transform, false);
            anchor.transform.localPosition = new Vector3(0f, -0.025f, 0f);
            anchor.transform.localRotation = Quaternion.AngleAxis(85f, Vector3.right);
            toolRing = new GameObject("ToolRing");                      // Actual tool ring. Will only be rotated around its local Y axis.
            toolRing.transform.SetParent(anchor.transform, false);

            // Add a choice for each tool to the ring:
            int   i        = 0;
            int   numTools = availableTools.Count;
            float radius   = 0.07f;
            foreach (ToolWidget tool in availableTools)
            {
                if (tool != null)
                {
                    float currentAngle = (float)i * (2f * Mathf.PI) / (float)numTools;

                    GameObject go = new GameObject(i.ToString());
                    go.transform.SetParent(toolRing.transform);
                    go.transform.localPosition = radius * (new Vector3(-Mathf.Sin(currentAngle), 0f, -Mathf.Cos(currentAngle)));
                    go.transform.localRotation = Quaternion.AngleAxis(currentAngle * 180f / Mathf.PI, Vector3.up);
                    go.transform.localScale    = new Vector3(0.045f, 0.045f, 0.045f);
                    SpriteRenderer sr = go.AddComponent <SpriteRenderer> ();
                    sr.sprite         = tool.ToolIcon;
                    sr.sortingLayerID = SortingLayer.NameToID("Sprites");

                    ToolRingEntry entry = go.AddComponent <ToolRingEntry> ();
                    entry.Tool = tool;
                    entry.name = tool.name;
                }
                i++;
            }

            GameObject text = new GameObject("ToolNameText");
            text.transform.SetParent(anchor.transform);
            text.transform.localPosition = new Vector3(0f, -0.06f, -radius);
            text.transform.localRotation = Quaternion.AngleAxis(0f * 180f / Mathf.PI, Vector3.up);
            text.transform.localScale    = new Vector3(0.02f, 0.02f, 0.02f);
            ActiveToolName           = text.AddComponent <TextMesh> ();
            ActiveToolName.text      = "";
            ActiveToolName.fontSize  = 40;
            ActiveToolName.alignment = TextAlignment.Center;
            ActiveToolName.anchor    = TextAnchor.MiddleCenter;

            Renderer r = text.GetComponent <Renderer> ();
            r.sortingLayerID = SortingLayer.NameToID("Sprites");
        }
        else
        {
            // If no controller is active, let the RiftToolRing handle the display of available tools:
            if (RiftToolRing.instance != null)
            {
                RiftToolRing.instance.setAvailableTools(availableTools);
            }
        }
    }