{"id":13661502,"url":"https://github.com/sinbad/UnityCsvUtil","last_synced_at":"2025-04-25T02:33:26.497Z","repository":{"id":38553493,"uuid":"83980890","full_name":"sinbad/UnityCsvUtil","owner":"sinbad","description":"Lightweight but type safe CSV serialise/deserialise of objects","archived":true,"fork":false,"pushed_at":"2022-07-17T10:17:59.000Z","size":20,"stargazers_count":137,"open_issues_count":3,"forks_count":27,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-08-02T05:13:13.419Z","etag":null,"topics":["csv","serialise","unity","unity3d"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sinbad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-05T15:32:40.000Z","updated_at":"2024-04-19T05:17:22.000Z","dependencies_parsed_at":"2022-07-09T17:46:54.751Z","dependency_job_id":null,"html_url":"https://github.com/sinbad/UnityCsvUtil","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinbad%2FUnityCsvUtil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinbad%2FUnityCsvUtil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinbad%2FUnityCsvUtil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinbad%2FUnityCsvUtil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinbad","download_url":"https://codeload.github.com/sinbad/UnityCsvUtil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223979363,"owners_count":17235385,"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","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","serialise","unity","unity3d"],"created_at":"2024-08-02T05:01:35.948Z","updated_at":"2024-11-10T16:30:44.103Z","avatar_url":"https://github.com/sinbad.png","language":"C#","funding_links":[],"categories":["C\\#","Open Source Repositories","Open Source Packages"],"sub_categories":["Document Reader","Utilities"],"readme":"# Unity simple CSV/object serialiser\n\n\u003e #### Note: I have stopped using Unity and so am not maintaining this library any more.\n\n## Purpose\n\nI find it useful to be able to expose game parameters and other tweakables via\nCSV when prototyping so that non-coders can easily open them in a spreadsheet\ntool to experiment with game design without having to use Unity.\n\nI also like to serialize values in a type safe manner, directly from/to my\nobjects; much like `JsonUtility` works but with friendlier CSV (and no nested\nobjects).\n\nThis class works with public fields on C# objects, and definitely works with\nfields which are of type `string`, `int`, `float`, `double`, and `enum` (value\nnames are used in the CSV). Other types will also work so long as they have\na `TypeConverter` available for parsing and implement `ToString`.\n\n## How to use\n\nLet's say we have an object with public fields, e.g.\n\n```c#\npublic class MyObject {\n    public string Name;\n    public int Level;\n    public float Dps;\n    public enum Colour {\n        Red = 1,\n        Green = 2,\n        Blue = 3,\n        Black = 4,\n        Purple = 15\n    }\n    public Colour ShirtColour;\n}\n```\n\n### Single instance per file\n\nIf you want to store a single instance of an object in a file, for example game\nsettings which change difficulty etc, then fields of an object are stored\nper line.\n\n#### Saving:\n```c#\nvar obj = new MyObject(\"Steve\", 20, 1002.5f, MyObject.Colour.Red);\nSinbad.CsvUtil.SaveObject(obj, \"filename.csv\");\n```\n\nThis will create a CSV file which looks like this:\n```\nName,Steve\nLevel,20\nDps,1002.5\nShirtColour,Red\n```\n\nNotice that for a single instance this defaults to one field per line which is\nconvenient for editing.\n\n#### Loading:\n\nYou could load that same CSV file back into an object instance:\n\n```c#\nvar obj = new MyObject();\nSinbad.CsvUtil.LoadObject(\"filename.csv\", obj);\n```\n\nThe CSV file can include additional columns if you want, for example if you have\na notes column to explain what a setting does. `CsvUtil` will ignore any column\nafter the first 2 if you want to do this.\n\nAlso, if you want to include a header row in the CSV you can, so long as the\nrow is prefixed with `#`. E.g. an alternative CSV for the above could be:\n\n```\n#Field,#Value,#Notes\nName,Steve,The character name\nLevel,20,The level of the character\nDps,1002.5,Damager per second\nShirtColour,Red,Colour of the fabric covering the torso\n```\n\nThis would load back in exactly the same way but would be more descriptive for\nsomeone editing the CSV in Excel for example.\n\n### Multiple instances per file\n\nIf you want to store many instances of an object in one file, for example\nweapon tables, you can do that too; in this case there is one instance per\nline and a header row indicates the field names.\n\n#### Saving:\n\n```c#\nvar objs = new List\u003cMyObject\u003e() {\n    new MyObject(\"Steve\", 20, 1002.5f, MyObject.Colour.Red);\n    new MyObject(\"Batman\", 12, 600.6f, MyObject.Colour.Black);\n    new MyObject(\"Peewee Herman\", 1, -2f, MyObject.Colour.Purple),\n};\nSinbad.CsvUtil.SaveObjects(objs, \"filename.csv);\n```\n\nThe CSV created from this would be:\n```\nName,Level,Dps,ShirtColour\nSteve,20,1002.5,Red\nBatman,12,600.6,Black\nPeewee Herman,1,-2,Purple\n```\n\n#### Loading:\n\n```c#\nvar objs = Sinbad.CsvUtil.LoadObjects\u003cMyObject\u003e(\"filename.csv\")\n```\n\nAgain if you want to you can include additional columns in the CSV which are\nignored during import, if you wanted to add comments. Simply prefix the header\nof the column to be ignored with `#` and that column won't be imported, e.g.\n\n```\nName,Level,Dps,ShirtColour,#Notes\nSteve,20,1002.5,Red,Probably OP\nBatman,12,600.6,Black,Who are you\nPeewee Herman,1,-2,Purple,wat\n```\n\nIn this case the last column will be ignored when loading that CSV.\n\n### Embedded commas\n\nIf there are any commas embedded in the strings then they're quoted before being\nwritten, and those quotes are dealt with on import too.\n\n## Tests\n\nTests are included in this library and if you're using a recent version of\nUnity they'll show up in the Editor Test Runner.\n\n## License (MIT)\n\nCopyright (c) 2017 Steve Streeting\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n## Acknowledgements\n\nThe regex for CSV splitting comes from [CSVReader](http://wiki.unity3d.com/index.php?title=CSVReader)\non the Unity wiki.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinbad%2FUnityCsvUtil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinbad%2FUnityCsvUtil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinbad%2FUnityCsvUtil/lists"}