Y
Y
Yura Berezovsky2017-10-13 09:41:32
C++ / C#
Yura Berezovsky, 2017-10-13 09:41:32

How to save a custom array in Unity?

We have:

public class Account
   { public string Id;
     public string country;
     public DateTime startDate;
     public void Account(string _ID, string _country, DateTime _startDate){ 
Id = _ID;
country = _country;
startDate = _startDate;
}}

public Account[] account;
How to store the "account" array, provided that it is already filled with data from the Account class?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Basmanov, 2017-10-13
@Jurajkeee

First of all, you need to mark the class with the System.Serializable attribute , after that the unit will know that this class can be serialized and will show fields with this type in the inspector. True, you need to understand that the unit can serialize far from all types, so you will have to convert DateTime to a string representation. To fit into the overall serialization process, you need to implement the ISerializationCallbackReceiver interface and write methods where you will convert DateTime to string and back. After that, you can use JsonUtility to serialize to json and write to a file or somewhere else.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question