Simplify JSON.net persist example
parent
5ad3ef7eb6
commit
99c604424f
|
|
@ -139,23 +139,22 @@ public class VelConnectDemo1 : MonoBehaviour
|
||||||
|
|
||||||
ExampleJSON dataToPersist = null;
|
ExampleJSON dataToPersist = null;
|
||||||
|
|
||||||
void persist()
|
|
||||||
{
|
|
||||||
VELConnectManager.SetUserData("mydata", JsonConvert.SerializeObject(dataToPersist));
|
|
||||||
}
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
VELConnectManager.AddUserDataListener("mydata", this, (s) => {
|
VELConnectManager.OnInitialState += (state) =>
|
||||||
try { //this will deal with any bad data (or null)
|
{
|
||||||
dataToPersist = JsonConvert.DeserializeObject<ExampleJSON>(s);
|
try
|
||||||
} catch (Exception e) {
|
{
|
||||||
|
dataToPersist = JsonConvert.DeserializeObject<ExampleJSON>(state.device.TryGetData("mydata"));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
dataToPersist = new ExampleJSON();
|
dataToPersist = new ExampleJSON();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}, true);
|
|
||||||
|
|
||||||
StartCoroutine(exampleProcess());
|
StartCoroutine(exampleProcess());
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator exampleProcess()
|
IEnumerator exampleProcess()
|
||||||
|
|
@ -173,7 +172,9 @@ public class VelConnectDemo1 : MonoBehaviour
|
||||||
}
|
}
|
||||||
private void OnApplicationQuit()
|
private void OnApplicationQuit()
|
||||||
{
|
{
|
||||||
persist();
|
VELConnectManager.SetUserData("mydata", JsonConvert.SerializeObject(dataToPersist));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue