Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

c# - What's a performance friendly way to pre-store 412.000 strings so they're searchable in Unity?

I have a CSV file with 412.000 strings in that I would like to pre-store locally so that I can deploy to Android and iOS. The game must then be able to look through these strings to check if there's a match based on user input.

The only viable solution that I can see would be SQLite. I haven't come across a very good SQLite solution for Unity yet.

Is there a built-in solution in Unity that I am overlooking?

The solution has to work locally. No HTTP calls.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

400,000 strings is absolutely trivial.

Just put them in a dictionary (list, whatever is relevant and that you prefer).

It's a total non-issue.

It's likely you would just load them from a text file, easy as pie.

 public TextAsset theTextFile;

(Just drag to the link in the Inspector, like any texture or similar.)

you can then very easily read that file as, say, JSON. (Just use JsonUtility. You can find numerous examples of this in SO and elsewhere.) For example,

   Blah bb = JsonUtility.FromJson< Blah >(ta.text);
   yourDict = bb.fieldname.ToDictionary(i => i.tag, i => i);

Note that you mention "memory" and so on. It's totally irrelevant, the data you are talking about is the fraction of the size of any tiny image - ! , it's a non-issue, you don't have to think about it. The hardware/software system will handle it.

P.S. ...

If you literally want to use csv, it's totally easy. I suggest you ask a new question giving the details of your file and so on, so you can get an exact answer.

Note that you'd just use a HashSet rather than a Dictionary. It's even easier.

It's just something like:

var wordList = theTextFile.text.Split('
');

You can google many examples!

https://stackoverflow.com/a/9791488/294884

http://answers.unity.com/answers/397537/view.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.7k users

...