Update quick-start.md

Adjusted JSON.net example a bit to make it consistent with other example.
pull/1/head
kjjohnsen 2024-03-07 14:36:59 -05:00 committed by GitHub
parent 99c604424f
commit d3c5a582ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 16 deletions

View File

@ -108,7 +108,7 @@ public class VELConnectTesting : MonoBehaviour
---
JSON.Net Example
JSON.Net Example that illustrates how to persist a complex object of data using VEL-Connect, initializing at start, and saving on application quit
```cs
using Newtonsoft.Json;
@ -139,36 +139,35 @@ public class VelConnectDemo1 : MonoBehaviour
ExampleJSON dataToPersist = null;
// Start is called before the first frame update
void Start()
{
private IEnumerator Start()
{
VELConnectManager.OnInitialState += (state) =>
{
var s = state.device.TryGetData("mydata");
Debug.Log("Retrieved: " + s);
try
{
dataToPersist = JsonConvert.DeserializeObject<ExampleJSON>(state.device.TryGetData("mydata"));
{
dataToPersist = JsonConvert.DeserializeObject<ExampleJSON>(s);
}
catch (Exception e)
{
dataToPersist = new ExampleJSON();
Debug.Log("Error serializing state: " + e.Message);
}
if(dataToPersist == null)
{
Debug.Log("Null state, initializing");
dataToPersist =new ExampleJSON();
}
};
StartCoroutine(exampleProcess());
}
IEnumerator exampleProcess()
{
while(dataToPersist == null)
{
yield return null; //wait for persistent data
}
while (dataToPersist == null) yield return null;
dataToPersist.a_list.Add(
new ExampleChildJSON("" + UnityEngine.Random.Range(0, 10),
UnityEngine.Random.Range(0, 10))
);
Debug.Log(JsonConvert.SerializeObject(dataToPersist));
}
private void OnApplicationQuit()
{