/// <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)); }
private void CornerCodeClicked(string buttonIndex) { cornerCode += buttonIndex; if (ExhibitBase.instance.verbose) { Debug.Log("cornerCode: " + cornerCode); } if (cornerCodeTimeoutCoroutine != null) { StopCoroutine(cornerCodeTimeoutCoroutine); cornerCodeTimeoutCoroutine = null; } if (cornerCodeListeners.ContainsKey(cornerCode)) { cornerCodeListeners[cornerCode](); ResetCornerCode(); } else { //cornerCodeTimeoutCoroutine = StartCoroutine(CornerCodeTimeout()); cornerCodeTimeoutCoroutine = StartCoroutine(ExhibitUtilities.DoActionAfterTime(ResetCornerCode, cornerCodeTimeoutSeconds)); } }
public void LogAndFade(string message, float messageFadeTime) { Log(message); if (fadeCoroutine != null) { StopCoroutine(fadeCoroutine); fadeCoroutine = null; } StartCoroutine(ExhibitUtilities.DoActionAfterTime(HideTextElement, messageFadeTime)); }
public void Show(string guess, bool correct, JoPlayer player, string actualAnswer, System.Action onComplete) { image.rectTransform.localScale = Vector2.zero; image.color = player.color.mainColor; ParticleSystem.MainModule particleMain = particles.main; particleMain.startColor = correct ? correctColor : incorrectColor; guessText.text = guess; playerNameText.text = $"{player.name} guessed"; actualWordText.text = $"The word was {actualAnswer}"; image.rectTransform.DOScale(1f, 0.8f).SetEase(Ease.OutElastic); particles.Play(); StartCoroutine(ExhibitUtilities.DoActionAfterTime(() => { onComplete.Invoke(); }, showTime)); }