Use Json to realize the data storage of the backpack system (1)

1. Material preparation

1. Create an empty project, download resources from the store,
find an environment, find a character. The
Insert picture description here
Insert picture description here
character comes with a mobile script, just drag the prefab into it.
Insert picture description here
Now the villain is ready to move.
Insert picture description here
We also need a backpack UI panel.
Insert picture description here

2. UI panel construction

Start to build the backpack UI. The backpack is a panel, add a Text title, add a Panel with Grid Layou Group (for placing the grid), and add a description Text below.
Insert picture description here

Three. Json data read and write test

First add a Key to open and close the backpack,
Insert picture description here
add the Item class, add the JsonData that needs to be serialized,
Insert picture description here
Insert picture description here
add a Json data management (for reading and writing),
Insert picture description here
to test the reading and writing method. After
Insert picture description here
writing the test, format it on the beJson website (for easy modification)

Insert picture description here
Read test
Use unity's own JsonUtility.FromJson failed, it is recommended to use LitJson (download method: official website github download dll, put it into the Plugins folder (created
Insert picture description here
Insert picture description here
by yourself )) Use LitJson to read successfully
Insert picture description here
JsonUtility failed to read
Insert picture description here

4. The second way to download LitJson

You can also use the second method to download LitJson, which is also the recommended method. Download a Nuget plug-in:
https://github.com/GlitchEnzo/NuGetForUnity
Insert picture description here
Download and install it here to use, and it is also convenient to manage.
The next article will associate the obtained data with the UI panel. If it helps you, please like it

Guess you like

Origin blog.csdn.net/euphorias/article/details/108838522