using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; public class PlayModeTestsUI : MonoBehaviour { static PlayModeTestsUI _instance; public static PlayModeTestsUI instance { get { if (_instance == null ) { _instance = FindObjectOfType(); } return _instance; } } public static bool Exists { get { if (_instance == null) { _instance = FindObjectOfType(); return false; } return _instance != null; } } [SerializeField] int frameWait = 100; [SerializeField] GameObject resultsPanel, waitingPanel, scenePanel; [SerializeField] Text overallAvgText; [SerializeField] RectTransform overallAvgFill; [SerializeField] Text overallMaxText; [SerializeField] RectTransform overallMaxFill; [SerializeField] RectTransform testResultPrefab; [SerializeField] ScrollRect scrollView; [SerializeField] RawImage resultImage; Material resultComparerMaterial; [SerializeField] Gradient fillGradient = new Gradient() { colorKeys = new GradientColorKey[] { new GradientColorKey( Color.red, 0.5f), new GradientColorKey( Color.yellow, 0.75f), new GradientColorKey( Color.green, 0.97f), } }; int numOfResults = 1; List testResults; int[] avgResults; int[] maxResults; Text[] resultsLabels; Text[] resultsAvgValue; RectTransform[] resultsAvgFill; Text[] resultsMaxValue; RectTransform[] resultsMaxFill; EventSystem eventSystem; GameObject lastSelected; Texture2D currentTemplate; RenderTexture currentRT; RenderTexture resultRT; Text scenePanelText; Image waitingImage; // Use this for initialization void Start () { // kill itself if already in scene. if (Exists) { Debug.Log("Kill UIObject because it already exists."); Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); //Debug.Log("Need to create " + (UnityEngine.SceneManagement.SceneManager.sceneCountInBuildSettings - 1) + " test result object."); // Set scroll view content to fit all results scrollView.content.anchorMin = new Vector2(0f, 0f); scrollView.content.anchorMax = new Vector2(1f, 0f); scrollView.content.offsetMin = new Vector2(0f, - (UnityEngine.SceneManagement.SceneManager.sceneCountInBuildSettings - 1f) * 200f); scrollView.content.offsetMax = new Vector2(0f, 0f); // Init results arrays numOfResults = UnityEngine.SceneManagement.SceneManager.sceneCountInBuildSettings - 1; avgResults = new int[numOfResults]; maxResults = new int[numOfResults]; resultsLabels = new Text[numOfResults]; resultsAvgValue = new Text[numOfResults]; resultsAvgFill = new RectTransform[numOfResults]; resultsMaxValue = new Text[numOfResults]; resultsMaxFill = new RectTransform[numOfResults]; testResults = new List(numOfResults); // Create results UI for (int i = 0; i < numOfResults; ++i) { RectTransform singleTestResult = Instantiate(testResultPrefab); testResults.Add(singleTestResult.gameObject); resultsLabels[i] = singleTestResult.Find("Label").GetComponent(); resultsAvgValue[i] = singleTestResult.Find("Avg_Value/Text").GetComponent(); resultsAvgFill[i] = singleTestResult.Find("Avg_Value/Fill").GetComponent(); resultsMaxValue[i] = singleTestResult.Find("Max_Value/Text").GetComponent(); resultsMaxFill[i] = singleTestResult.Find("Max_Value/Fill").GetComponent(); singleTestResult.SetParent(scrollView.content); singleTestResult.anchorMin = new Vector2(0, 0); singleTestResult.anchorMax = new Vector2(1, 0); singleTestResult.offsetMin = new Vector2(0, scrollView.content.rect.height - (i + 1) * 200f); singleTestResult.offsetMax = new Vector2(0, singleTestResult.offsetMin.y + 200f); int sceneIndex = i; singleTestResult.GetComponent