在unity3D android中本地保存大量数据的最佳方法? [英] Best way to save large amount of data locally in unity3D android?

查看:148
本文介绍了在unity3D android中本地保存大量数据的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款 2D 游戏,稍后将用作摊位上的广告活动,我需要存储用户信息、姓名、号码、电子邮件和分数.有数据可能超过数千个条目.在 unity5 中实现它的最佳和免费方法是什么?游戏将部署在安卓上.

I am working on a 2D game which will be later used as advertisement activity on a stall, I need to store user information, Name, Number, Email and score. There data may exceed to thousands entries. What will be the best and free way to implement it in unity5? Game will be deployed on android.

推荐答案

注意 - 不要使用StreamWriter"出于任何原因.

只需使用简单的 File.Write 命令即可.

这是 Unity 中常见的误解!

关于这个话题,一个糟糕的示例代码在 www 上传播了多年.只需使用 File.Write.

关于此页面上的问题,数千"条目绝对没有.

Regarding the question on this page, "thousands" of entries is absolutely nothing.

请注意,例如:您应用中的任何小图标图像都会使您的姓名/地址数据的大小完全相形见绌!

Note that for example: any tiny icon image in your app will completely dwarf the size of your name/address data!

(1) 极其容易保存文本文件:

(1) extremely easy to save a text file:

// IO crib sheet..
// filePath = Application.persistentDataPath+"/"+fileName;
// check if file exists System.IO.File.Exists(f)
// write to file File.WriteAllText(f,t)
// delete the file if needed File.Delete(f)
// read from a file File.ReadAllText(f)

仅此而已.

   string currentText = File.ReadAllText(filePath);

注意...........

NOTE WELL...........

// filePath = Application.persistentDataPath+"/"+fileName;
// YOU MUST USE "Application.persistentDataPath"
// YOU CANNOT USE ANYTHING ELSE/
// NOTHING OTHER THAN "Application.persistentDataPath" WORKS/
// ALL OTHER OPTIONS FAIL ON ALL PLATFORMS/
// YOU CAN >ONLY< USE Application.persistentDataPath IN UNITY.

以您想要的任何方式存储信息,可能是 JSON 或 csv.

Store the info any way you want, probably JSON or csv.

在 Unity 中使用 Json 非常容易,stackoverflow 上有 100 多个示例.

It is dead easy to use Json in Unity, there are 100s of examples on stackoverflow.

示例 https://stackoverflow.com/a/38535392/294884

(2) 一旦你说了一百万个项目.可以学习使用本地SQL数据库,非常值得学习.按照 Łukasz Motyczka 在评论中所说的去做.

(2) once you have say one million items. you can learn about using the local SQL database, which is well worth learning. Do what Łukasz Motyczka says in the comments.

(3) 永远不要使用 PlayerPrefs - 它更难更乱!

(3) Never use PlayerPrefs - it is much harder and messy!

这篇关于在unity3D android中本地保存大量数据的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆