public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Edit the foldout property.isExpanded = EditorGUIAuto.Foldout(ref position, property.isExpanded, label); if (property.isExpanded) { // Increase indent EditorGUI.indentLevel++; // Edit the first sub property property.Next(true); EditorGUIAuto.PropertyField(ref position, property, true); // Display the popup for the channel SerializedProperty mixerIndex = property.FindPropertyRelative("index"); property.Next(false); position = EditorGUI.PrefixLabel(position, new GUIContent(property.displayName)); int oldIndent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; property.intValue = EditorGUI.Popup(position, property.intValue, AllChannelContent(mixerIndex.intValue)); EditorGUI.indentLevel = oldIndent; // Restore old indent EditorGUI.indentLevel--; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Get the properties SerializedProperty questionsToPick = property.FindPropertyRelative(nameof(questionsToPick)); SerializedProperty questionPool = property.FindPropertyRelative(nameof(questionPool)); // Layout the foldout property.isExpanded = EditorGUIAuto.Foldout(ref position, property.isExpanded, label); if (property.isExpanded) { EditorGUI.indentLevel++; // Display the slider only if there are questions to pick if (questionPool.arraySize >= 1) { questionsToPick.intValue = Mathf.Clamp(questionsToPick.intValue, 1, questionPool.arraySize); EditorGUIAuto.IntSlider(ref position, questionsToPick, 1, questionPool.arraySize); } // If there are no questions to pick then do not display an int slider else { questionsToPick.intValue = 0; EditorGUIAuto.PrefixedLabelField(ref position, new GUIContent(questionsToPick.displayName), "(No questions to pick)"); } // Layout the question pool EditorGUIAuto.PropertyField(ref position, questionPool, true); EditorGUI.indentLevel--; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Get the sub properties of this property SerializedProperty isPool = property.FindPropertyRelative(nameof(isPool)); SerializedProperty question = property.FindPropertyRelative(nameof(question)); SerializedProperty pool = property.FindPropertyRelative(nameof(pool)); // Layout the foldout property.isExpanded = EditorGUIAuto.Foldout(ref position, property.isExpanded, label); if (property.isExpanded) { EditorGUI.indentLevel++; EditorGUIAuto.PropertyField(ref position, isPool, true); // Display either the pool or the question depending on the is pool bool value if (isPool.boolValue) { EditorGUIAuto.PropertyField(ref position, pool, true); } else { EditorGUIAuto.PropertyField(ref position, question, true); } EditorGUI.indentLevel--; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Display the foldout property.isExpanded = EditorGUIAuto.Foldout(ref position, property.isExpanded, label); if (property.isExpanded) { // Increase indent EditorGUI.indentLevel++; // Get enumerable list of children IEnumerable <SerializedProperty> children = EditorGUIAuto.ToEnd( property, "optionalUnlockData", "explanation", false, false); SerializedProperty visualType = property.FindPropertyRelative(nameof(visualType)); // Layout every child foreach (SerializedProperty child in children) { // Only layout sprite if enum value is 0 if (child.name == "sprite" && visualType.enumValueIndex == 0) { EditorGUI.indentLevel++; EditorGUIAuto.PropertyField(ref position, child, true); EditorGUI.indentLevel--; } // Only layout video sub path if enum value is 1 else if (child.name == "videoStreamingSubPath" && visualType.enumValueIndex == 1) { EditorGUI.indentLevel++; EditorGUIAuto.PropertyField(ref position, child, true); EditorGUI.indentLevel--; } // No special layout rules for other properties else if (child.name != "sprite" && child.name != "videoStreamingSubPath") { EditorGUIAuto.PropertyField(ref position, child, true); } } // Reduce indent EditorGUI.indentLevel--; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Get the sub-properties SerializedProperty template = property.FindPropertyRelative(nameof(template)); SerializedProperty answers = property.FindPropertyRelative(nameof(answers)); // Set out the foldout property.isExpanded = EditorGUIAuto.Foldout(ref position, property.isExpanded, label); if (property.isExpanded) { // Increase indent EditorGUI.indentLevel++; // Layout the template EditorGUIAuto.PropertyField(ref position, template); // If an object reference exists then layout the answers if (template.objectReferenceValue) { // Get the quiz template QuizTemplate quizTemplate = template.objectReferenceValue as QuizTemplate; CheckRuntimeTemplate(quizTemplate); // Use a button to regenerate quiz questions from the template GUI.enabled = quizTemplate.Dynamic; if (GUIAuto.Button(ref position, "Generate new questions")) { runtimeTemplate = new QuizRuntimeTemplate(quizTemplate); } GUI.enabled = true; quizAnswersEditor.OnGUI(position, answers, runtimeTemplate.Questions); position.y += quizAnswersEditor.GetPropertyHeight(answers, runtimeTemplate.Questions); // Get a list of all the answers as integers int[] answersArray = Answers(property); resultsFoldout = EditorGUIAuto.Foldout(ref position, resultsFoldout, "Quiz Results"); if (resultsFoldout) { // Indent the next part and disable it EditorGUI.indentLevel++; GUI.enabled = false; // Compute if the important questions passed, what the score is, and what the max score was bool passed = QuizInstance.PassedImportantQuestions(runtimeTemplate, answersArray); int score = QuizInstance.ComputeScoreInImportantCategories(runtimeTemplate, answersArray); int maxScore = runtimeTemplate.GetMaximumPossibleScoreInImportantCategories(); string scoreString = $"{score} / {maxScore} - {(passed ? "Pass" : "Fail")}"; // Show the score on important questions EditorGUIAuto.PrefixedLabelField(ref position, new GUIContent("Score on Important Questions"), scoreString); // Compute if the unimportant questions passed, what the score is, and what the max score was passed = QuizInstance.PassedUnimportantQuestions(runtimeTemplate, answersArray); score = QuizInstance.ComputeScoreInUnimportantCategories(runtimeTemplate, answersArray); maxScore = runtimeTemplate.GetMaximumPossibleScoreInUnimportantCategories(); scoreString = $"{score} / {maxScore} - {(passed ? "Pass" : "Fail")}"; // Show the score on unimportant questions EditorGUIAuto.PrefixedLabelField(ref position, new GUIContent("Score on Unimportant Questions"), scoreString); // Show the final grade EditorGUIAuto.PrefixedLabelField(ref position, new GUIContent("Final Grade"), QuizInstance.ComputeGrade(runtimeTemplate, answersArray).ToString()); // Change the values back to before EditorGUI.indentLevel--; GUI.enabled = true; } } // Restore indent EditorGUI.indentLevel--; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Setup some useful variables SerializedProperty array = property.FindPropertyRelative(nameof(array)); SerializedProperty levelTypeFilter = property.FindPropertyRelative(nameof(levelTypeFilter)); string filter = levelTypeFilter.stringValue; if (!string.IsNullOrEmpty(filter)) { // Try to parse the string as a level type if (System.Enum.TryParse(filter, out LevelType type)) { array.isExpanded = EditorGUIAuto.Foldout(ref position, array.isExpanded, label); if (array.isExpanded) { // Increase indent EditorGUI.indentLevel++; // Make this array parallel to that array int numLevels = LevelSettings.GetAllLevelDataOfType(type).Length; array.arraySize = numLevels; // Get first array element for (int i = 0; i < array.arraySize; i++) { // Get the element and setup a nice looking label SerializedProperty element = array.GetArrayElementAtIndex(i); LevelID level = new LevelID(type, i); GUIContent elementLabel = new GUIContent(level.Data.EditorDisplayName); // Layout this element EditorGUIAuto.PropertyField(ref position, element, elementLabel, true); } // Restore indent EditorGUI.indentLevel--; } } else { EditorGUIAuto.PropertyField(ref position, array, label, true); } } else { EditorGUIAuto.PropertyField(ref position, array, label, true); } // Only display the button if the array is expanded if (array.isExpanded) { // Increase indent EditorGUI.indentLevel++; // Target state should be true if any are not completed SerializedProperty[] elements = EditorGUIAuto.GetArrayElements(array); bool targetState = elements .Any(elem => !elem.FindPropertyRelative("completed").boolValue); // Setup the button label string buttonLabel = "Complete all levels"; if (!targetState) { buttonLabel = "Un-complete all levels"; } // Indent the rect for the button Rect buttonRect = EditorGUI.IndentedRect(position); if (GUIAuto.Button(ref buttonRect, buttonLabel)) { // Go through each element and set it to the target state foreach (SerializedProperty elem in elements) { SerializedProperty encountered = elem.FindPropertyRelative(nameof(encountered)); SerializedProperty completed = elem.FindPropertyRelative(nameof(completed)); // Set encountered and completed to the target states encountered.boolValue = targetState; completed.boolValue = targetState; } } // Move the position down by button rect position.y = buttonRect.y; // Reduce indent EditorGUI.indentLevel--; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Get the array of names SerializedProperty array = property.FindPropertyRelative("name.names"); // If there are items in the array, then use them to change the content label if (array.arraySize > 0) { // Create a temporary item name and set it up with the values in the serialized property ItemName itemName = new ItemName(); ItemName.Type[] nameTypes = (ItemName.Type[])System.Enum.GetValues(typeof(ItemName.Type)); // Set each name in the temporary item name object for (int i = 0; i < array.arraySize; i++) { itemName.Set(nameTypes[i], array.GetArrayElementAtIndex(i).stringValue); } // Get the string version of the name label = new GUIContent(itemName.ToString()); } // Put in the foldout field property.isExpanded = EditorGUIAuto.Foldout(ref position, property.isExpanded, label); // If the property is expanded then layout the others if (property.isExpanded) { // Increase indent EditorGUI.indentLevel++; // Get other important properties SerializedProperty name = property.FindPropertyRelative(nameof(name)); SerializedProperty shopItem = property.FindPropertyRelative(nameof(shopItem)); SerializedProperty species = property.FindPropertyRelative(nameof(species)); SerializedProperty hasSpecies = property.FindPropertyRelative(nameof(hasSpecies)); SerializedProperty categoryFilter = property.FindPropertyRelative(nameof(categoryFilter)); EditorGUIAuto.PropertyField(ref position, name, true); EditorGUIAuto.PropertyField(ref position, shopItem, true); // If this item data has species then layout the field for it if (hasSpecies.boolValue) { System.Type typeFilter = typeof(ScriptableObject); // Filter specific species based on the category filter if (categoryFilter.enumValueIndex == 0) { typeFilter = typeof(AnimalSpecies); } else if (categoryFilter.enumValueIndex == 1) { typeFilter = typeof(FoodSourceSpecies); } // Layout the object field EditorGUIAuto.ObjectField(ref position, species, typeFilter); } // Restore old indent EditorGUI.indentLevel--; } }