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

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

问题描述

我正在开发一个2D游戏,稍后将用作摊位上的广告活动,我需要存储用户信息,姓名,号码,电子邮件和分数。有数据可能超过千个条目。什么是最好的和自由的方式来实现它在unity5?

解决方案

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



只需使用琐碎的File.Write命令。



这是Unity中一个非常常见的误解!



Unity中有一个巨大的问题,人们看到网络上的完全错误的示例代码,可笑的问题已经传播了多年。从来没有,使用StreamWriter - 只是使用普通的File.Write功能。不容易。






对于上面的问题:数千条目绝对没有。 (您应用中的任何不相关的小图标图片将完全使您的姓名/地址数据的大小变小。)

(1)您只需保存文本文件,



在Unity中写入和读取文件非常容易。

  // IO crib sheet .. 
// filePath = Application.persistentDataPath +/+ fileName;
//检查文件是否存在System.IO.File.Exists(f)
//写入文件File.WriteAllText(f,t)
//如果需要,删除文件File。删除(f)
//从文件读取File.ReadAllText(f)

所有有它。

  string currentText = File.ReadAllText(filePath); 

注意WELL ...........

  // filePath = Application.persistentDataPath +/+ fileName; 
//您必须使用Application.persistentDataPath
//您不能使用任何其他选项
//除Application.persistentDataPath以外的任何操作WORKS
//所有其​​他选项失败在所有平台上
//您可以> USE Application.persistentDataPath IN UNITY

您可以将信息存储为任何可能的格式,例如JSON或csv 。因为你有很少的信息,你可以轻轻地把json作为一个列表,并轻松访问。



注意,如果你不熟悉非常基本的编程任务像使用JSON或csv(所有非常容易),你将需要研究。 SO问题/答案不能是教程。



(2)您可以了解如何使用本地 SQL数据库,这是值得学习的。做什么ŁukaszMotyczka在评论中说。



(3)这是真的,你的任务是这么小,你可以使用 PlayerPrefs 。注意,这实际上是最难的方式!这将是一个真正的混乱,试图使用PlayerPrefs作为一个简单的数据库。所以不要这样做。



(4)请注意,在实践中,这些天没有本地应用程序。要成为一个应用程序开发人员是一个云开发人员,可能你需要使用Firebase等(Parse今年惊喜地关闭了)。


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.

解决方案

NOTE - do not use "StreamWriter" for any reason.

Just use the trivial File.Write commands.

This is an extremely common misunderstand in Unity!

There's a huge problem in Unity that folks see totally wrong example code on the net, and ridiculous problems get propagated for years. Never, ever use "StreamWriter" - just use the trivial File.Write functions. Couldn't be easier.


Regarding the question above: "thousands" of entries is absolutely nothing. (Any irrelevant small icon image in your app will totally dwarf the size of your name/address data.)

(1) you can just save a text file(s),

It's incredibly easy to write and read files in Unity.

// 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)

that's all there is to it.

   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

You can store the info in any of may formats such as JSON or csv. Since you have a tiny amount of information, you can trivially just keep the json as a List and access it easily.

Note that if you are unfamiliar with very basic programming tasks like using JSON or csv (all extremely easy) you will need to study that. SO questions/answers cannot be tutorials.

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

(3) it's true that your task is so small you could just use PlayerPrefs. note however this is actually the hardest way! It would be a real mess, trying to use PlayerPrefs as a simple database. So don't do that.

(4) Note that in practice there are no "local apps" these days. To be an "app developer" is to be a cloud developer, likely you will need to use Firebase or the like (Parse having surprisingly closed down this year!)

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

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