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 OnInspectorGUI() { // Update the object serializedObject.Update(); // Get the end point type SerializedProperty endPointType = serializedObject.FindProperty(nameof(endPointType)); // Get the first and last properties SerializedProperty start = serializedObject.FindProperty("localStartPoint"); SerializedProperty end = serializedObject .FindProperty("conveyorSpeed") .GetEndProperty(); // Get all the properties in the object IEnumerable <SerializedProperty> properties = EditorGUIAuto.ToEnd(start, end, false, false); // Show the script referenced by the object GUI.enabled = false; EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Script")); GUI.enabled = true; // Go through each property in the list of properties foreach (SerializedProperty property in properties) { // Check if the end point changes if (property.name == "endPointType") { EditorGUI.BeginChangeCheck(); } // If end point is implicit then disable editing the end point if (endPointType.enumValueIndex == 0 && property.name == "localEndPoint") { GUI.enabled = false; } // If end point is explicit then disable editing the direction and offset if (endPointType.enumValueIndex == 1 && (property.name == "direction" || property.name == "objectOffset")) { GUI.enabled = false; } // Display the property EditorGUILayout.PropertyField(property, true); GUI.enabled = true; // Check if the end point type changed if (property.name == "endPointType") { if (EditorGUI.EndChangeCheck()) { // Apply the modified end point type serializedObject.ApplyModifiedProperties(); // Get the object targetted by the editor ObjectConveyor conveyor = target as ObjectConveyor; // If the end point is implicit, // then compute it and show it in the editor if (property.enumValueIndex == 0) { SerializedProperty localEndPoint = serializedObject.FindProperty(nameof(localEndPoint)); localEndPoint.vector3Value = conveyor.LocalEndPoint; } // If the end point is explicit, // then compute direction and offset to show in editor else { SerializedProperty direction = serializedObject.FindProperty(nameof(direction)); direction.vector3Value = conveyor.Direction; SerializedProperty objectOffset = serializedObject.FindProperty(nameof(objectOffset)); objectOffset.floatValue = conveyor.ObjectOffset; } // Update the serialized object to reflect the new values serializedObject.Update(); } } } // Apply any modified properties serializedObject.ApplyModifiedProperties(); }