Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
1. look into json: https://docs.unity3d.com/Manual/JSONSerialization.html
it can turn everything about an object into a string, and copy all values from the string into an object again.
and i think it works with lists too, saving everything on them.
then you would just need everything you want to save to be on a list
Suppose the class being converted to the JSON as the object type and to coordinates, just to keep things simple. It makes a string out of that data. Suppose then I have a hundred objects all do that, and they all throw their strings as a save file script. The save file script takes all the strings, and links them all as one string with XXX in-between as a separator, and saves it as a txt file in the datapath folder.
Upon loading, it takes the string from the txt file, seperates it all by the XXXs, and stores it in a string array. I could then grab the length of the array, create a "for" loop of that length, and for each entry in the array, I could create a prefab gameobject that has a script in it, and the array entry throws the string[] into that script. The script will then take that string[] entry, and use the fromJSON to convert it back to a class. It will then grab the object type variable from the class, "do something with it", and create a new gameobject of that type, grab the coordinates from the class and make the gameobject have those coordinates.
Does that make sense? I think that would work. The only problem I have is the "do something with it" part. How do you convert a class.object variable into a reference of a prefab? Like even if I have a script where it holds all the prefabs, how does the class.object variable with value "cat" know that it should reference the prefabscript.cat.gameobject?
Hopefully my question makes sense, lol.
i never used it before, but i think for loading you could use resource.load() to find prefabs
https://docs.unity3d.com/ScriptReference/Resources.html
and it doesnt really matter, the saving will work either way, but json files have a .json extension to them.
and things that you save need to have [Serializable] on them. i think a list isnt like that, so i think youd need to make a list class, which just has your list then mark it serializable.
[Serializable]
public class ListClass{
public List<int> list;
}
then you just use the class and i think it would work