Exemplo n.º 1
0
    /// <summary>
    /// Instantiate a menu button in the selection canvas for each assigned VRTool prefab,
    /// set each button's text and onClick event to call ChangeActiveTool([associated vr tool]),
    /// and sets the navitagion mode on each element to vertical.
    /// </summary>
    public void PopulateToolBoxMenu()
    {
        foreach (VRTool tool in toolPrefabs)
        {
            VRTool newTool = Instantiate(tool).GetComponent <VRTool>();
            newTool.transform.SetParent(inputTracker != null ? inputTracker.transform : transform.parent);
            newTool.gameObject.SetActive(false);

            Button toolButton = Instantiate(selectionButtonPrefab).GetComponent <Button>();
            toolButton.transform.SetParent(selectionContent);
            toolButton.transform.localScale    = Vector3.one;
            toolButton.transform.localPosition = Vector3.zero;
            toolButton.transform.localRotation = Quaternion.identity;
            Text buttonText = toolButton.transform.GetChild(0).GetComponent <Text>();
            if (buttonText != null)
            {
                buttonText.text = tool.name;
            }
            else
            {
                Debug.Log("Button prefab did not have a UI Text as its first child!");
            }
            toolButton.onClick = new Button.ButtonClickedEvent();
            toolButton.onClick.AddListener(() => ChangeActiveTool(newTool));
            Navigation navigation = new Navigation();
            navigation.mode       = Navigation.Mode.Vertical;
            toolButton.navigation = navigation;
        }
    }
Exemplo n.º 2
0
 /// <summary>
 /// Sets the active tool to newTool, and closes the selection menu
 /// </summary>
 /// <param name="newTool"></param>
 public void ChangeActiveTool(VRTool newTool)
 {
     activeTool = newTool;
     CloseToolboxMenu();
 }