public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component) { var componentType = component.GetType(); var componentName = componentType.Name.RemoveComponentSuffix(); if (componentName.ToLower().Contains(_componentNameSearchTerm.ToLower())) { var boxStyle = getColoredBoxStyle(entity.totalComponents, index); EntitasEditorLayout.BeginVerticalBox(boxStyle); { var memberInfos = componentType.GetPublicMemberInfos(); EntitasEditorLayout.BeginHorizontal(); { if (memberInfos.Count == 0) { EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel); } else { unfoldedComponents[index] = EditorGUILayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle); } if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) { entity.RemoveComponent(index); } } EntitasEditorLayout.EndHorizontal(); if (unfoldedComponents[index]) { var componentDrawer = getComponentDrawer(componentType); if (componentDrawer != null) { var newComponent = entity.CreateComponent(index, componentType); component.CopyPublicMemberValues(newComponent); EditorGUI.BeginChangeCheck(); { componentDrawer.DrawComponent(newComponent); } var changed = EditorGUI.EndChangeCheck(); if (changed) { entity.ReplaceComponent(index, newComponent); } else { entity.GetComponentPool(index).Push(newComponent); } } else { foreach (var info in memberInfos) { DrawAndSetElement(info.type, info.name, info.GetValue(component), entity, index, component, info.SetValue); } } } } EntitasEditorLayout.EndVertical(); } }
public static void DrawAndSetElement(Type memberType, string memberName, object value, Entity entity, int index, IComponent component, Action<IComponent, object> setValue) { var newValue = DrawAndGetNewValue(memberType, memberName, value, entity, index, component); if (DidValueChange(value, newValue)) { var newComponent = entity.CreateComponent(index, component.GetType()); component.CopyPublicMemberValues(newComponent); setValue(newComponent, newValue); entity.ReplaceComponent(index, newComponent); } }