using System; using UnityEditor; using UnityEngine; namespace Unity.Netcode.Editor { /// /// The base Netcode Editor helper class to display derived based components
/// where each child generation's properties will be displayed within a FoldoutHeaderGroup. ///
[CanEditMultipleObjects] public partial class NetcodeEditorBase : UnityEditor.Editor where TT : MonoBehaviour { /// public virtual void OnEnable() { } /// /// Helper method to draw the properties of the specified child type component within a FoldoutHeaderGroup. /// /// The specific child type that should have its properties drawn. /// The component type of the . /// The to invoke that will draw the type properties. /// The current expanded property value /// The invoked to apply the updated value. protected void DrawFoldOutGroup(Type type, Action displayProperties, bool expanded, Action setExpandedProperty) { var baseClass = target as TT; EditorGUI.BeginChangeCheck(); serializedObject.Update(); var currentClass = typeof(T); if (type.IsSubclassOf(currentClass) || (!type.IsSubclassOf(currentClass) && currentClass.IsSubclassOf(typeof(TT)))) { var expandedValue = EditorGUILayout.BeginFoldoutHeaderGroup(expanded, $"{currentClass.Name} Properties"); if (expandedValue) { EditorGUILayout.EndFoldoutHeaderGroup(); displayProperties.Invoke(); } else { EditorGUILayout.EndFoldoutHeaderGroup(); } EditorGUILayout.Space(); setExpandedProperty.Invoke(expandedValue); } else { displayProperties.Invoke(); } serializedObject.ApplyModifiedProperties(); EditorGUI.EndChangeCheck(); } /// public override void OnInspectorGUI() { serializedObject.ApplyModifiedProperties(); } } }