示例#1
0
        public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component)
        {
            var componentType = component.GetType();

            var componentName = EntityExtension.RemoveComponentSuffix(componentType.Name);

            if (componentName.ToLower().Contains(_componentNameSearchTerm.ToLower()))
            {
                var fields = componentType.GetFields(BindingFlags.Public | BindingFlags.Instance);

                var boxStyle = getColoredBoxStyle(entity.totalComponents, index);
                EntitasEditorLayout.BeginVerticalBox(boxStyle);
                {
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        if (fields.Length == 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])
                    {
                        foreach (var field in fields)
                        {
                            var value = field.GetValue(component);
                            DrawAndSetElement(field.FieldType, field.Name, value,
                                              entity, index, component, field.SetValue);
                        }
                    }
                }
                EntitasEditorLayout.EndVertical();
            }
        }