namespace VRTK.Examples { using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using System.Collections; public class UI_Interactions : MonoBehaviour { private const int EXISTING_CANVAS_COUNT = 4; public void Button_Red() { VRTK_Logger.Info("Red Button Clicked"); } public void Button_Pink() { VRTK_Logger.Info("Pink Button Clicked"); } public void Toggle(bool state) { VRTK_Logger.Info("The toggle state is " + (state ? "on" : "off")); } public void Dropdown(int value) { VRTK_Logger.Info("Dropdown option selected was ID " + value); } public void SetDropText(BaseEventData data) { var pointerData = data as PointerEventData; var textObject = GameObject.Find("ActionText"); if (textObject) { var text = textObject.GetComponent(); text.text = pointerData.pointerDrag.name + " Dropped On " + pointerData.pointerEnter.name; } } public void CreateCanvas() { StartCoroutine(CreateCanvasOnNextFrame()); } private IEnumerator CreateCanvasOnNextFrame() { yield return null; var canvasCount = FindObjectsOfType().Length - EXISTING_CANVAS_COUNT; var newCanvasGO = new GameObject("TempCanvas"); newCanvasGO.layer = 5; var canvas = newCanvasGO.AddComponent(); var canvasRT = canvas.GetComponent(); canvasRT.position = new Vector3(-4f, 2f, 3f + canvasCount); canvasRT.sizeDelta = new Vector2(300f, 400f); canvasRT.localScale = new Vector3(0.005f, 0.005f, 0.005f); canvasRT.eulerAngles = new Vector3(0f, 270f, 0f); var newButtonGO = new GameObject("TempButton", typeof(RectTransform)); newButtonGO.transform.SetParent(newCanvasGO.transform); newButtonGO.layer = 5; var buttonRT = newButtonGO.GetComponent(); buttonRT.position = new Vector3(0f, 0f, 0f); buttonRT.anchoredPosition = new Vector3(0f, 0f, 0f); buttonRT.localPosition = new Vector3(0f, 0f, 0f); buttonRT.sizeDelta = new Vector2(180f, 60f); buttonRT.localScale = new Vector3(1f, 1f, 1f); buttonRT.localEulerAngles = new Vector3(0f, 0f, 0f); newButtonGO.AddComponent(); var canvasButton = newButtonGO.AddComponent