Beispiel #1
0
        private void OnEnable()
        {
            testList = new ReorderableList(serializedObject, serializedObject.FindProperty("integrationTests"), true, true, true, true);
            testList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                SerializedProperty testSuiteProperty = testList.serializedProperty.GetArrayElementAtIndex(index);

                Rect testFieldRect = new Rect(rect.x, rect.y + 2, rect.width, EditorGUIUtility.singleLineHeight);
                EditorGUI.PropertyField(testFieldRect, testSuiteProperty, label: new GUIContent());

                EditorGUI.BeginDisabledGroup(!EditorApplication.isPlaying);

                Rect progressBarRect = new Rect(testFieldRect.x, testFieldRect.y + testFieldRect.height + 2, testFieldRect.width, 23f);

                if (EditorApplication.isPlaying)
                {
                    IntegrationTestSuite testSuite = (IntegrationTestSuite)testSuiteProperty.objectReferenceValue;

                    if (testSuite != null)
                    {
                        if (testSuite.runSuiteTests)
                        {
                            int totalTestCount  = testSuite.GetTotalTestCount();
                            int passedTestCount = testSuite.GetSucceededTestCount();

                            float percentPassed = totalTestCount > 0 ? (passedTestCount / (float)totalTestCount) : 0f;

                            EditorGUI.ProgressBar(progressBarRect, percentPassed, $"{passedTestCount}/{totalTestCount}");
                        }
                        else
                        {
                            EditorGUI.ProgressBar(progressBarRect, 0f, "Tests disabled");
                        }
                    }
                    else
                    {
                        EditorGUI.ProgressBar(progressBarRect, 0f, "0/0");
                    }
                }
                else
                {
                    EditorGUI.ProgressBar(progressBarRect, 0f, "0/0");
                }

                EditorGUI.EndDisabledGroup();
            };
            testList.elementHeightCallback = (int index) =>
            {
                return(45f);
            };
            testList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Integration Tests"); };
        }