{"id":16210010,"url":"https://github.com/bian-sh/csvutility-for-unity","last_synced_at":"2025-09-17T21:05:37.068Z","repository":{"id":169386772,"uuid":"645334475","full_name":"Bian-Sh/CsvUtility-For-Unity","owner":"Bian-Sh","description":"This tool is a compact single file co-created by me and AI for CSV read/write. It is user-friendly, customizable, and supports bilingual usage.此工具是我与 AI 共同打造的小巧单文件，可用于 CSV 读写。本工具易于使用，支持自定义。","archived":false,"fork":false,"pushed_at":"2024-04-21T15:43:08.000Z","size":14206,"stargazers_count":27,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-17T15:54:37.040Z","etag":null,"topics":["csv","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bian-Sh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-25T12:27:08.000Z","updated_at":"2025-07-02T07:07:04.000Z","dependencies_parsed_at":"2024-04-21T17:53:26.821Z","dependency_job_id":null,"html_url":"https://github.com/Bian-Sh/CsvUtility-For-Unity","commit_stats":null,"previous_names":["bian-sh/csvutility-for-unity"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Bian-Sh/CsvUtility-For-Unity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bian-Sh%2FCsvUtility-For-Unity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bian-Sh%2FCsvUtility-For-Unity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bian-Sh%2FCsvUtility-For-Unity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bian-Sh%2FCsvUtility-For-Unity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bian-Sh","download_url":"https://codeload.github.com/Bian-Sh/CsvUtility-For-Unity/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bian-Sh%2FCsvUtility-For-Unity/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266732624,"owners_count":23976065,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","unity"],"created_at":"2024-10-10T10:34:46.457Z","updated_at":"2025-09-17T21:05:32.007Z","avatar_url":"https://github.com/Bian-Sh.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca id=\"chinese\"\u003e[English](#english)\u003c/a\u003e\n# CsvUtility 中文文档\n\n此工具是我与 AI 共同打造的小巧单文件，可用于 CSV 读写。本工具接口丰富，易于使用。我的目标是和 JsonUtiliy 一样简单好用。\n\n# 开发环境\nUnity 2021.3.16f1\n\n# 功能简介\n1. 支持读取所有行到对象\n2. 支持读取指定行到对象 \n3. 支持将指定对象更新到 csv\n4. 支持将指定对象新增到 csv。\n5. 支持 overwrite 方式加载 csv 数据到对象\n6. 支持使用 [CsvIgnoreAttribute] 标记不需要处理的字段。\n7. 支持使用 [ColumnAttribute] 为字段指定别名，csv数据中的列名无需与字段名一致。\n8. 理论上支持所有 .net 开发情景中使用（仅在 Unity 开发、测试）\n\n# 安装方法\n\n### 通过 git url 安装\n\n将 `https://github.com/Bian-Sh/CsvUtility-For-Unity.git?path=Packages/CsvUtility` 拷贝到 UPM （如下图）即可。\n            \n![](./doc/UPM.png)\n\n\u003e1. 需要使用支持 git 包路径查询参数的 Unity 版本（Unity \u003e= 2019.3.4f1，Unity \u003e= 2020.1a21）。\n\u003e\n\u003e2. 对于中国用户来说，失败的可能性很高。\n   \n\n\n\n# 使用方法\n\n\u003e1. 读取 csv 文件内容到指定的对象列表 \n\n```csharp\nvar result = CsvUtility.Read\u003cDisplayConfiguration\u003e(testCsvPath);\n```\n\n\u003e2. 将指定的对象列表存储成 csv 文件\n\n```csharp\n var data = new List\u003cDisplayConfiguration\u003e\n {\n     new DisplayConfiguration { index = 2, size_x = 4.5f, size_y = 4.9f, width = 1922, height = 1082 },\n     new DisplayConfiguration { index = 3, size_x = 5.5f, size_y = 5.9f, width = 1923, height = 1083 }\n };\n CsvUtility.Write(data, testCsvPath);\n\n```\n\n\u003e3. 更新给定的对象中的数据\n\n ```csharp\n    var index = 1;\n    var target = new DisplayConfiguration() { index = index };\n    CsvUtility.FromCsvOverwrite(testCsvPath, target, v=\u003ev.index == index);\n```\n\n\n\u003e4. 根据指定的对象更新  csv 数据\n\n```csharp\n var index = 1;\n var target = new DisplayConfiguration { index = index, size_x = 4.5f, size_y = 4.9f, width = 1925, height = 1085 };\n CsvUtility.Write(target, testCsvPath, v=\u003ev.index == index, KeyinType.Update);\n```\n\n\u003e5. 根据指定的对象新增 csv 数据\n\n```csharp\n//新增数据，会在 csv 的最后一行新增一行数据，如果指定的字段的值在 csv 中已经存在，则会抛出异常\n var index = 4;\n var target = new DisplayConfiguration { index = index, size_x = 1.1f, size_y = 6.6f, width = 1928, height = 1088 };\n CsvUtility.Write(target, testCsvPath, v=\u003ev.index == index, KeyinType.Append);\n ```\n\n\u003e6. 获取 csv 指定数据并返回一个对象 \n\n```csharp\nvar result = CsvUtility.Read\u003cDisplayConfiguration\u003e(testCsvPath, v =\u003ev.index == 1);\n```\n\n\u003e7. 支持通过 [CsvIgnoreAttribute ] 标记不需要处理的字段 \n\n```csharp\n public class DisplayConfiguration\n {\n        [CsvIgnore]\n        public string name; // name 将不会保存到 csv 中\n        public int index;\n }\n```\n\n\u003e 8. 支持通过 [ColumnAttribute] 为字段指定别名\n\n```csharp\n public class DisplayConfiguration\n {\n\t\t[Column(\"aliasname\")]\n\t\tpublic string name; // csv 中的列名为 aliasname\n\t\tpublic int index;\n }\n```\n\n\n\u003e如果数据量过大，为避免主线程卡死，操作可以尝试在 Task 中进行。\n\n\n# 示例\n请使用 upm 导入示例项目，示例项目中包含了上面提到的使用情景对应的示例代码。\n将功能划分为保存、加载、更新、新增，每个功能对应一个系列的示例情景，如表格所示。\n只需要点击对应的按钮即可运行示例代码，示例代码的运行结果会在控制台中打印出来。同时部分测试还会定位到 csv 文件。\n\n|保存|加载|更新|新增|\n|:---:|:---:|:---:|:---:|\n|![](doc/save_cn.png)|![](doc/load_cn.png)|![](doc/update_cn.png)|![](doc/append_cn.png)|\n\n# 单例测试\n为保证工具的稳定性，我编写了单例测试，测试用例覆盖了工具的所有功能，测试用例的代码在 CsvUtility/Tests/文件夹下，测试结果如下图所示。\n\n![](doc/TestRunner.png)\n\n\n\u003ca id=\"english\"\u003e[简体中文](#chinese)\u003c/a\u003e\n# CsvUtility-For-Unity\n\nThis tool is a compact single file co-created by me and AI for CSV read/write. It has a rich interface and is user-friendly. My goal is to make it as easy to use as JsonUtiliy.\n\n# Development Environment\nUnity 2021.3.16f1\n\n# Function Introduction\n1. Supports reading all rows to an object\n2. Supports reading specified rows to an object\n3. Supports updating specified objects to csv\n4. Supports adding specified objects to csv.\n5. Supports loading csv data into an object in overwrite mode\n6. Supports using [CsvIgnoreAttribute] to mark fields that do not need to be processed.\n7. Supports using [ColumnAttribute] to specify aliases for fields, so that the column names in the csv data do not have to match the field names.\n8. Theoretically supports all .net development scenarios (only developed and tested in Unity)\n\n# Installation\n\n### Install via git URL\n\nYou can add `https://github.com/Bian-Sh/CsvUtility-For-Unity.git?path=Packages/CsvUtility` to Package Manager\n\n![](./doc/UPM.png)\n\n\u003e 1. Requires a version of unity that supports path query parameter for git packages (Unity \u003e= 2019.3.4f1, Unity \u003e= 2020.1a21).\n\u003e \n\u003e 2. There is a high chance of failure for users in China.\n\u003e\n\n# Usage\n\n\u003e1. Read csv file content to specified object list\n\n```csharp\nvar result = CsvUtility.Read\u003cDisplayConfiguration\u003e(testCsvPath);\n```\n\n\u003e2. Store the specified object list as a csv file\n\n```csharp\n var data = new List\u003cDisplayConfiguration\u003e\n {\n     new DisplayConfiguration { index = 2, size_x = 4.5f, size_y = 4.9f, width = 1922, height = 1082 },\n     new DisplayConfiguration { index = 3, size_x = 5.5f, size_y = 5.9f, width = 1923, height = 1083 }\n };\n CsvUtility.Write(data, testCsvPath);\n\n```\n\n\u003e3. Update the data in the given object\n\n ```csharp\n    var index = 1;\n    var target = new DisplayConfiguration() { index = index };\n    CsvUtility.FromCsvOverwrite(testCsvPath, target, v =\u003e v.index == index );\n            \n```\n\n\n\u003e4. Update csv data based on the specified object\n\n```csharp\n//Update data, will find the correct item that predicate matched, and then update the data of that row\n var index = 1;\n var target = new DisplayConfiguration { index = index, size_x = 4.5f, size_y = 4.9f, width = 1925, height = 1085 };\n CsvUtility.Write(target, testCsvPath, v =\u003e v.index == index, KeyinType.Update);\n```\n\n\u003e5. Add csv data based on the specified object\n\n```csharp\n//Add data, will add a new line of data at the end of the csv. If the value of the specified field already exists in the csv, an exception will be thrown\n var index = 4;\n var target = new DisplayConfiguration { index = index, size_x = 1.1f, size_y = 6.6f, width = 1928, height = 1088 };\n CsvUtility.Write(target, testCsvPath,  v =\u003e v.index == index , KeyinType.Append);\n\n```\n\n\u003e6. Get the data of the specified row according to the specified field and value and return an object \n\n```csharp\nvar result = CsvUtility.Read\u003cDisplayConfiguration\u003e(testCsvPath, v =\u003e v.index == 1);\n```\n\n\u003e7. Support marking fields that do not need to be processed through [CsvIgnoreAttribute] \n\n```csharp\n public class DisplayConfiguration\n {\n        [CsvIgnore]\n        public string name; // name will not be saved to csv\n        public int index;\n }\n```\n\n\u003e8. Support specifying aliases for fields through [ColumnAttribute]\n\n```csharp\n public class DisplayConfiguration\n {\n\t\t[Column(\"aliasname\")]\n\t\tpublic string name; // The column name in csv is aliasname\n\t\tpublic int index;\n }\n```\n\n\n\u003eIf the data volume is too large, in order to avoid the main thread from being stuck, operations can be attempted in Task.\n\n\n# Example\nPlease import the example project using upm. The example project contains example code corresponding to the usage scenarios mentioned above.\n\nThe functions are divided into save/load/update/append line and each function corresponds to a series of example scenarios as shown in the table.\n\nJust click on the corresponding button to run the example code and the result of running the example code will be printed out in the console.\n\nAt the same time some tests will also locate to csv file.\n\n|Save|Load|Update|Append Line|\n|:---:|:---:|:---:|:---:|\n|![](doc/save_en.png)|![](doc/load_en.png)|![](doc/update_en.png)|![](doc/append_en.png)|\n\n# Unit Test\nTo ensure tool stability I wrote unit tests covering all tool functions.\nThe test case code is located under CsvUtility/Tests/ folder and test results are shown below.\n![](doc/TestRunner.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbian-sh%2Fcsvutility-for-unity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbian-sh%2Fcsvutility-for-unity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbian-sh%2Fcsvutility-for-unity/lists"}