-
Notifications
You must be signed in to change notification settings - Fork 6
Data
chaolun edited this page Mar 23, 2019
·
1 revision
-
Use new EasyWriter (string path) Open or Create a data file
-
Most of data should be saved as
EasyDictionary<string, EasyObject> -
WriterExtensions(EasyDictionary<string, EasyObject>)orReactiveWritercan useGet<T>orSet<T>serialize and deserialize data
The reason why we gave up reading data in the original way is that it may take longer to read data (eg. Android need to use WWW to load resources under the streamingassets folder). So we need to a lazy and we can don't care when it was loaded way, like...
public class WriterSystem : SystemBehaviour
{
public EasyWriter SimpleWriter;
public override void Initialize (IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory, PrefabFactory prefabFactory)
{
base.Initialize (eventSystem, poolManager, groupFactory, prefabFactory);
SimpleWriter = new EasyWriter("Application.streamingAssetsPath + "/example.json");
}
public override void OnEnable ()
{
base.OnEnable ();
SimpleWriter.OnAdd ().Subscribe (writer =>
{
// Use writer.Set<T> (string key, T value) and writer.SetArray<T> (string key, object value) to save the data
// Use writer.Get<T> (string key) and writer.GetArray<T> (string key) to load the data
// Use writer.Get<T> (string key, T target) and writer.GetArray<T> (string key, T[] target) to overwrite the MonoBehavior or ScriptableObject
// Use writer.HasKey (string key) to check the data is exist or not
if (writer.HasKey ("...")) {
var b = writer.Get<bool> ("...");
}
// If you want to automatically Dispose when a ReactiveWriter is disposed, use AddTo(ReactiveWriter.Disposer):
Observable.EveryUpdate().Subscribe(_ => {
if (writer.HasKey ("...")) {
Debug.Log (writer.Get<string> ("..."));
}
}).AddTo(this.Disposer).AddTo(writer.Disposer);
}).AddTo(this.Disposer)
}
}