public static string Serialize(this IEntity entity, Type[] includedTypes = null, Type[] ignoredTypes = null) { FastJson.Clear(); Types.Clear(); FastJson.Append(idHeader).Append("\"").Append(entity.Id).Append("\"").Append(lineSeparator); Types.Append(typesHeader); Types.Append(string.Join(",", entity.Components.Where(c => { if (includedTypes != null && includedTypes.Contains(c.GetType())) { return(true); } else { if (!c.GetType().ShouldIgnore(ignoredTypes)) { return(true); } } return(false); }).Select(c => "\"" + c.GetType().ToString() + "\"").ToArray()) + "]"); FastJson.Append(types).Append(lineSeparator); FastJson.Append(componentsHeader); for (componentIndex = 0; componentIndex < entity.Components.Count(); componentIndex++) { component = entity.Components.ElementAt(componentIndex); if (component.GetType().ShouldIgnore(ignoredTypes)) { continue; } componentAsJson = JsonUtility.ToJson(component); FastJson.Append(componentAsJson); if (componentIndex < entity.Components.Count() - 1) { FastJson.Append(lineSeparator); } } FastJson.Append("]}"); json = FastJson.ToString(); return(json); }