public static DebugText Create() { Canvas canvas = FindObjectOfType <Canvas>(); if (canvas == null) { Debug.Log("Creating a Canvas object in the Scene for DebugText."); canvas = ExhibitBase.CreateCanvas(1920, 1080); } GameObject textGO = new GameObject(); RectTransform textTransfrom = textGO.AddComponent <RectTransform>(); textTransfrom.anchorMin = Vector2.zero; textTransfrom.anchorMax = Vector2.one; textTransfrom.pivot = new Vector2(0.5f, 0.5f); textTransfrom.offsetMin = Vector2.zero; textTransfrom.offsetMax = new Vector2(canvas.pixelRect.width, canvas.pixelRect.height); DebugText dt = textGO.AddComponent <DebugText>(); textGO.name = "Debug Text"; textTransfrom.SetParent(canvas.gameObject.transform); dt.textElement = textGO.AddComponent <Text>(); dt.SetFont(dt.fontType); dt.SetColor(dt.fontColor); dt.SetFontSize(dt.fontSize); dt.textElement.raycastTarget = false; return(dt); }
/// <summary> /// adds the corner overlay buttons in order to add Code Sequences /// </summary> public void AddButtons() { Canvas canvas = FindObjectOfType <Canvas>(); if (canvas == null) { Debug.Log("Creating a Canvas object in the Scene for the corner code buttons."); canvas = ExhibitBase.CreateCanvas(1920, 1080); } cornerCodeTestParent = new GameObject(); cornerCodeTestParent.name = "Corner Codes"; RectTransform cornerCodeRectTransform = cornerCodeTestParent.AddComponent <RectTransform>(); cornerCodeRectTransform.position.Set(0, 0, 0); cornerCodeRectTransform.sizeDelta = new Vector2(Screen.width, Screen.height); cornerCodeRectTransform.SetParent(canvas.GetComponent <RectTransform>(), false); GameObject[] buttons = new GameObject[4]; for (int i = 0; i < 4; i++) { GameObject buttonGameObject = new GameObject(); buttonGameObject.name = "Corner Code Button " + i; RectTransform buttonRectTransform = buttonGameObject.AddComponent <RectTransform>(); buttonRectTransform.SetParent(cornerCodeRectTransform); buttonRectTransform.sizeDelta = new Vector2(cornerCodeButtonSize, cornerCodeButtonSize); Image buttonImage = buttonGameObject.AddComponent <Image>(); buttonImage.color = cornerCodeTestColor; buttons[i] = buttonGameObject; cornerCodeTestImages.Add(buttonImage); } CanvasScaler canvasScaler = canvas.GetComponent <CanvasScaler>(); Vector2 resolution = canvasScaler.referenceResolution; // set positions of test images buttons[0].GetComponent <RectTransform>().anchoredPosition = new Vector3(-(resolution.x / 2) + (cornerCodeButtonSize / 2), (resolution.y / 2) - (cornerCodeButtonSize / 2)); buttons[1].GetComponent <RectTransform>().anchoredPosition = new Vector3((resolution.x / 2) - (cornerCodeButtonSize / 2), (resolution.y / 2) - (cornerCodeButtonSize / 2)); buttons[2].GetComponent <RectTransform>().anchoredPosition = new Vector3(-(resolution.x / 2) + (cornerCodeButtonSize / 2), -(resolution.y / 2) + (cornerCodeButtonSize / 2)); buttons[3].GetComponent <RectTransform>().anchoredPosition = new Vector3((resolution.x / 2 - (cornerCodeButtonSize / 2)), -(resolution.y / 2) + (cornerCodeButtonSize / 2)); // create rectangles cornerCodeRects.Add(new Rect(0, resolution.y - cornerCodeButtonSize, cornerCodeButtonSize, cornerCodeButtonSize)); // top-left cornerCodeRects.Add(new Rect(resolution.x - cornerCodeButtonSize, resolution.y - cornerCodeButtonSize, cornerCodeButtonSize, cornerCodeButtonSize)); // top-right cornerCodeRects.Add(new Rect(0, 0, cornerCodeButtonSize, cornerCodeButtonSize)); // bottom-left cornerCodeRects.Add(new Rect(resolution.x - cornerCodeButtonSize, 0, cornerCodeButtonSize, cornerCodeButtonSize)); // bottom-right if (cornerCodeTestColor == Color.clear) { for (int i = 0; i < buttons.Length; i++) { buttons[i].SetActive(false); } } addedCornerCodeButtons = true; StartCoroutine(ExhibitUtilities.DoActionAfterTime(BringToFront, 5f)); }