diff --git a/Assets/Mirror/Editor/NetworkBehaviourInspector.cs b/Assets/Mirror/Editor/NetworkBehaviourInspector.cs index 3f272bcb2..8915959cc 100644 --- a/Assets/Mirror/Editor/NetworkBehaviourInspector.cs +++ b/Assets/Mirror/Editor/NetworkBehaviourInspector.cs @@ -1,6 +1,4 @@ using System; -using System.Collections; -using System.Collections.Generic; using System.Reflection; using UnityEditor; using UnityEngine; @@ -94,74 +92,4 @@ protected void DrawDefaultSyncSettings() serializedObject.ApplyModifiedProperties(); } } - - public class SyncObjectDrawer - { - readonly UnityEngine.Object targetObject; - readonly List syncObjectFields; - - public SyncObjectDrawer(UnityEngine.Object targetObject) - { - this.targetObject = targetObject; - syncObjectFields = new List(); - foreach (FieldInfo field in InspectorHelper.GetAllFields(targetObject.GetType(), typeof(NetworkBehaviour))) - { - if (field.IsSyncObject() && field.IsVisibleSyncObject()) - { - syncObjectFields.Add(new SyncObjectField(field)); - } - } - } - - public void Draw() - { - if (syncObjectFields.Count == 0) { return; } - - EditorGUILayout.Space(); - EditorGUILayout.LabelField("Sync Objects", EditorStyles.boldLabel); - - for (int i = 0; i < syncObjectFields.Count; i++) - { - DrawSyncObject(syncObjectFields[i]); - } - } - - void DrawSyncObject(SyncObjectField syncObjectField) - { - syncObjectField.visible = EditorGUILayout.Foldout(syncObjectField.visible, syncObjectField.label); - if (syncObjectField.visible) - { - using (new EditorGUI.IndentLevelScope()) - { - object fieldValue = syncObjectField.field.GetValue(targetObject); - if (fieldValue is IEnumerable synclist) - { - int index = 0; - foreach (object item in synclist) - { - string itemValue = item != null ? item.ToString() : "NULL"; - string itemLabel = $"Element {index}"; - EditorGUILayout.LabelField(itemLabel, itemValue); - - index++; - } - } - } - } - } - - class SyncObjectField - { - public bool visible; - public readonly FieldInfo field; - public readonly string label; - - public SyncObjectField(FieldInfo field) - { - this.field = field; - visible = false; - label = $"{field.Name} [{field.FieldType.Name}]"; - } - } - } } diff --git a/Assets/Mirror/Editor/SyncObjectDrawer.cs b/Assets/Mirror/Editor/SyncObjectDrawer.cs new file mode 100644 index 000000000..6ab078d4a --- /dev/null +++ b/Assets/Mirror/Editor/SyncObjectDrawer.cs @@ -0,0 +1,78 @@ +// helper class for NetworkBehaviourInspector +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using UnityEditor; + +namespace Mirror +{ + class SyncObjectField + { + public bool visible; + public readonly FieldInfo field; + public readonly string label; + + public SyncObjectField(FieldInfo field) + { + this.field = field; + visible = false; + label = $"{field.Name} [{field.FieldType.Name}]"; + } + } + + public class SyncObjectDrawer + { + readonly UnityEngine.Object targetObject; + readonly List syncObjectFields; + + public SyncObjectDrawer(UnityEngine.Object targetObject) + { + this.targetObject = targetObject; + syncObjectFields = new List(); + foreach (FieldInfo field in InspectorHelper.GetAllFields(targetObject.GetType(), typeof(NetworkBehaviour))) + { + if (field.IsSyncObject() && field.IsVisibleSyncObject()) + { + syncObjectFields.Add(new SyncObjectField(field)); + } + } + } + + public void Draw() + { + if (syncObjectFields.Count == 0) { return; } + + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Sync Objects", EditorStyles.boldLabel); + + for (int i = 0; i < syncObjectFields.Count; i++) + { + DrawSyncObject(syncObjectFields[i]); + } + } + + void DrawSyncObject(SyncObjectField syncObjectField) + { + syncObjectField.visible = EditorGUILayout.Foldout(syncObjectField.visible, syncObjectField.label); + if (syncObjectField.visible) + { + using (new EditorGUI.IndentLevelScope()) + { + object fieldValue = syncObjectField.field.GetValue(targetObject); + if (fieldValue is IEnumerable synclist) + { + int index = 0; + foreach (object item in synclist) + { + string itemValue = item != null ? item.ToString() : "NULL"; + string itemLabel = $"Element {index}"; + EditorGUILayout.LabelField(itemLabel, itemValue); + + index++; + } + } + } + } + } + } +} diff --git a/Assets/Mirror/Editor/SyncObjectDrawer.cs.meta b/Assets/Mirror/Editor/SyncObjectDrawer.cs.meta new file mode 100644 index 000000000..44ba75dff --- /dev/null +++ b/Assets/Mirror/Editor/SyncObjectDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6f90afab12e04f0e945d83e9d38308a3 +timeCreated: 1632556645 \ No newline at end of file