void DrawTypeField(object instance, FieldInfo field, EntityObserver entity) { var fieldValue = field.GetValue(instance); var fieldType = field.FieldType; if (!EcsComponentInspectors.Render(field.Name, fieldType, fieldValue, entity)) { if (fieldType == typeof(UnityEngine.Object) || fieldType.IsSubclassOf(typeof(UnityEngine.Object))) { GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(field.Name, GUILayout.MaxWidth(EditorGUIUtility.labelWidth - 16)); var guiEnabled = GUI.enabled; GUI.enabled = false; EditorGUILayout.ObjectField(fieldValue as UnityEngine.Object, fieldType, false); GUI.enabled = guiEnabled; GUILayout.EndHorizontal(); return; } var strVal = fieldValue != null?string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", fieldValue) : "null"; if (strVal.Length > MaxFieldToStringLength) { strVal = strVal.Substring(0, MaxFieldToStringLength); } GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(field.Name, GUILayout.MaxWidth(EditorGUIUtility.labelWidth - 16)); EditorGUILayout.SelectableLabel(strVal, GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight)); GUILayout.EndHorizontal(); } }
void DrawComponents() { var count = _entity.World.GetComponents(_entity.Id, ref _componentsCache); for (var i = 0; i < count; i++) { var component = _componentsCache[i]; _componentsCache[i] = null; var type = component.GetType(); GUILayout.BeginVertical(GUI.skin.box); var typeName = EditorHelpers.GetCleanGenericTypeName(type); if (!EcsComponentInspectors.Render(typeName, type, component, _entity)) { EditorGUILayout.LabelField(typeName, EditorStyles.boldLabel); var indent = EditorGUI.indentLevel; EditorGUI.indentLevel++; foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public)) { DrawTypeField(component, field, _entity); } EditorGUI.indentLevel = indent; } GUILayout.EndVertical(); EditorGUILayout.Space(); } }