// Setup the results context object
        public override void SetupResultsContext(ResultsContext context, ResultsIOData inputData, ResultsIOData inputDataB)
        {
            CleanupResultsContext();
            FrameComparisonResults inputResults = (FrameComparisonResults)logic.DeserializeResults(inputData); // Deserialize input and cast to typed results

            if (TestRunner.Instance)
            {
                if (!TestRunner.Instance.isAnalytic)
                {
                    comparisonData = (FrameComparisonComparison)logic.ProcessComparison(inputResults); // Get comparison data
                }
                else
                {
                    FrameComparisonResults inputResultsB = (FrameComparisonResults)logic.DeserializeResults(inputDataB); // Deserialize input and cast to typed results
                    comparisonData = (FrameComparisonComparison)logic.ProcessComparison(inputResultsB, inputResults);
                }
            }
            else
            {
                comparisonData = (FrameComparisonComparison)logic.ProcessComparison(inputResults);        // Get comparison data
            }
            buttons = new Button[3];                                                                      // Create button array
            for (int i = 0; i < buttons.Length; i++)                                                      // Iterate
            {
                buttons[i] = context.objects[i].GetComponent <Button>();                                  // Get the button
                int index = i;                                                                            // Set this so delegate doesnt get reference that iterates
                buttons[i].onClick.AddListener(delegate { SetTextureContext(comparisonData, index); });   // Add listener
            }
            resultsContextImage = context.objects[3].GetComponent <RawImage>();                           // Get image
            context.objects[4].GetComponent <Text>().text = comparisonData.DiffPercentage.ToString("N4"); // Set diff to field
            SetTextureContext(comparisonData, 0);                                                         // Set default
        }
        // Set context for textures
        public void SetTextureContext(FrameComparisonComparison comparisonData, int context)
        {
            foreach (Button b in buttons)          // Iterate buttons
            {
                b.interactable = true;             // Enable
            }
            buttons[context].interactable = false; // Disable requested
            switch (context)
            {
            case 0:                                                       // Results
                resultsContextImage.material = null;                      // Null material
                resultsContextImage.texture  = comparisonData.resultsTex; // Set texture
                break;

            case 1:                                                                   // Comparison
                SetupMaterial(comparisonData.baselineTex, comparisonData.resultsTex); // Setup material
                resultsContextImage.texture  = comparisonData.resultsTex;             // Set texture
                resultsContextImage.material = material;                              // Set material
                break;

            case 2:                                                        // Baseline
                resultsContextImage.material = null;                       // Null material
                resultsContextImage.texture  = comparisonData.baselineTex; // Set texture
                break;
            }
        }
 public void CleanupResultsContext()
 {
     comparisonData = null;
     if (resultsContextImage)
     {
         Texture tex = resultsContextImage.texture;
         if (tex)
         {
             Destroy(tex);
         }
     }
 }