@@ -5,32 +5,55 @@ Check out [releases](https://github.com/Persomatey/JSONSerializePackage/releases
5
5
6
6
<img src =" https://raw.githubusercontent.com/Persomatey/JSONSerializerPlugin/main/Logo/JSONSerializerPluginLogo.png " width =" 318 " />
7
7
8
- ## Details
9
-
10
- <details >
11
- <summary >Example Scene Explanation</summary >
12
- <blockquote >
13
-
14
- <details >
15
- <summary >JSON Reader</summary >
16
- <blockquote >
8
+ ## Tutorial
17
9
18
- <img src =" https://raw.githubusercontent.com/Persomatey/JSONSerializerPlugin/main/Images/ReadFileImg.png " width =" 860 " />
10
+ ### Setup
11
+ Since everything in this plugin is wrapped in a JSON namespace, you'll need to add it at the top of your script.
12
+ ```
13
+ using JSON;
14
+ ```
19
15
20
- </blockquote >
21
- </details >
16
+ Because .json files are read as TextAssets in Unity, you'll need a reference to the TextAsset in your script like so:
17
+ ```
18
+ [SerializeField] TextAsset file;
19
+ public TextAsset file;
20
+ ```
22
21
23
- <details >
24
- <summary >JSON Writer</summary >
25
- <blockquote >
22
+ ### Creating a new JSON object from a file
23
+ Call the constructor, using the TextAsset you want read in the parameters.
24
+ ```
25
+ JSON myJSON = new JSON(file);
26
+ ```
27
+ There is also a constructor for if you don't have a parameter.
28
+ ```
29
+ JSON myJSON = new JSON();
30
+ ```
26
31
27
- <img src =" https://raw.githubusercontent.com/Persomatey/JSONSerializerPlugin/main/Images/WriteFileImg.png " width =" 860 " />
32
+ ### Serializing JSON object to a file
33
+ You can serialize the JSON object to the provided TextAsset file.
34
+ ```
35
+ writeJSON.WriteToFile();
36
+ ```
37
+ If no parameter was provided when object was created, you'll need to include the TextAsset in the parameters of ` WriteToFile() `
38
+ ```
39
+ writeJSON.WriteToFile(file);
40
+ ```
28
41
29
- </blockquote >
30
- </details >
42
+ ### Reading and writing JSON variables
43
+ To read a specific variable (` GetBool ` , ` GetInt ` , ` GetFloat ` , ` GetString ` ):
44
+ ```
45
+ myJSON.GetString("myStr");
46
+ ```
47
+ To change a specific variable (` SetBool ` , ` SetInt ` , ` SetFloat ` , ` SetString ` ):
48
+ ```
49
+ myJSON.SetInt("myInt", 246);
50
+ ```
51
+ To add a variable to the JSON (` AddBool ` , ` AddInt ` , ` AddFloat ` , ` AddString ` ):
52
+ ```
53
+ myJSON.AddFloat("myFloat", 24.68);
54
+ ```
31
55
32
- </blockquote >
33
- </details >
56
+ ## Details
34
57
35
58
<details >
36
59
<summary >Specs</summary >
0 commit comments