Skip to content

Commit b1bf79e

Browse files
author
Jared Bienz
committed
Working on Json serialization.
1 parent f3cc27c commit b1bf79e

17 files changed

+69
-10661
lines changed

SpatialAlignment-Unity/Assembly-CSharp.Player.csproj

Lines changed: 0 additions & 1641 deletions
This file was deleted.

SpatialAlignment-Unity/Assets/SpatialAlignment-Examples/MultiParent/Scenes/SA-MultiParent.unity

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,6 @@ MonoBehaviour:
521521
m_Script: {fileID: 11500000, guid: acbe461e1fd0d1541aae9edae3fddc44, type: 3}
522522
m_Name:
523523
m_EditorClassIdentifier:
524-
mode: 0
525524
parentOptions:
526525
- frame: {fileID: 1478666017}
527526
minimumAccuracy: {x: 0, y: 0, z: 0}
@@ -634,6 +633,53 @@ MeshFilter:
634633
m_PrefabAsset: {fileID: 0}
635634
m_GameObject: {fileID: 992500263}
636635
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
636+
--- !u!1 &1034952781
637+
GameObject:
638+
m_ObjectHideFlags: 0
639+
m_CorrespondingSourceObject: {fileID: 0}
640+
m_PrefabInstance: {fileID: 0}
641+
m_PrefabAsset: {fileID: 0}
642+
serializedVersion: 6
643+
m_Component:
644+
- component: {fileID: 1034952783}
645+
- component: {fileID: 1034952782}
646+
m_Layer: 0
647+
m_Name: PersistenceExample
648+
m_TagString: Untagged
649+
m_Icon: {fileID: 0}
650+
m_NavMeshLayer: 0
651+
m_StaticEditorFlags: 0
652+
m_IsActive: 1
653+
--- !u!114 &1034952782
654+
MonoBehaviour:
655+
m_ObjectHideFlags: 0
656+
m_CorrespondingSourceObject: {fileID: 0}
657+
m_PrefabInstance: {fileID: 0}
658+
m_PrefabAsset: {fileID: 0}
659+
m_GameObject: {fileID: 1034952781}
660+
m_Enabled: 1
661+
m_EditorHideFlags: 0
662+
m_Script: {fileID: 11500000, guid: 13265d8d7bf8cc04fa7aa108cf67a889, type: 3}
663+
m_Name:
664+
m_EditorClassIdentifier:
665+
Frames:
666+
- {fileID: 1478666017}
667+
- {fileID: 1891623029}
668+
- {fileID: 332004590}
669+
--- !u!4 &1034952783
670+
Transform:
671+
m_ObjectHideFlags: 0
672+
m_CorrespondingSourceObject: {fileID: 0}
673+
m_PrefabInstance: {fileID: 0}
674+
m_PrefabAsset: {fileID: 0}
675+
m_GameObject: {fileID: 1034952781}
676+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
677+
m_LocalPosition: {x: 0, y: 0, z: 0}
678+
m_LocalScale: {x: 1, y: 1, z: 1}
679+
m_Children: []
680+
m_Father: {fileID: 0}
681+
m_RootOrder: 9
682+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
637683
--- !u!1 &1231208087
638684
GameObject:
639685
m_ObjectHideFlags: 0

SpatialAlignment-Unity/Assets/SpatialAlignment-Examples/Persistence/Scripts/PersistenceExampleManager.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ private async Task LoadAsync()
5050

5151
private async Task SaveAsync()
5252
{
53+
string result = null;
5354
foreach (var frame in Frames)
5455
{
5556
await store.SaveFrameAsync(frame);
@@ -60,17 +61,20 @@ private async Task SaveAsync()
6061
using (JsonTextWriter jw = new JsonTextWriter(sw))
6162
{
6263
await store.SaveDocumentAsync(jw);
64+
result = sw.ToString();
6365
}
64-
6566
}
6667

68+
Debug.Log(result);
69+
6770
}
6871

6972
// Start is called before the first frame update
7073
void Start()
7174
{
7275
store = new JsonStore();
73-
var t = LoadAsync();
76+
var t = SaveAsync();
77+
t.Wait();
7478
}
7579
}
7680
}

SpatialAlignment-Unity/Assets/SpatialAlignment/Persistence/Json/JsonStore.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ private JsonSerializer CreateSerializer()
5454
// Add converter
5555
settings.Converters.Add(new SpatialFrameConverter());
5656

57+
// Enable automatic type name handling to allow extensions for alignment strategies
58+
// WARNING: Must implement ISerializationBinder to safely handle instantiation
59+
// See https://stackoverflow.com/questions/39565954/typenamehandling-caution-in-newtonsoft-json
60+
settings.TypeNameHandling = TypeNameHandling.Auto;
61+
5762
// Create the serializer
5863
return JsonSerializer.Create(settings);
5964
}

SpatialAlignment-Unity/Assets/SpatialAlignment/SpatialFrame.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424
//
2525

26+
using Newtonsoft.Json;
2627
using System;
2728
using System.Collections.Generic;
2829
using System.Linq;
30+
using System.Runtime.Serialization;
2931
using System.Text;
3032
using System.Threading.Tasks;
3133
using UnityEngine;
@@ -42,16 +44,19 @@ namespace Microsoft.SpatialAlignment
4244
/// more than one frame of reference. The <see cref="ISpatialFrame"/> interface is used
4345
/// to represent one of potentially many frames of reference.
4446
/// </remarks>
47+
[DataContract]
4548
public class SpatialFrame : MonoBehaviour
4649
{
4750
#region Unity Inspector Variables
51+
[DataMember]
4852
[SerializeField]
4953
[Tooltip("A unique ID for the spatial frame.")]
5054
private string id;
5155
#endregion // Unity Inspector Variables
5256

5357
#region Public Properties
5458
/// <inheritdoc />
59+
[DataMember]
5560
public virtual IAlignmentStrategy AlignmentStrategy { get => GetComponent<IAlignmentStrategy>(); }
5661

5762
/// <inheritdoc />

SpatialAlignment-Unity/Assets/SpatialAlignment/Strategies/SimulatedAlignment.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using System.Collections;
2828
using System.Collections.Generic;
2929
using System.Linq;
30+
using System.Runtime.Serialization;
3031
using UnityEngine;
3132

3233
namespace Microsoft.SpatialAlignment
@@ -38,13 +39,16 @@ namespace Microsoft.SpatialAlignment
3839
/// This strategy doesn't modify the transform of the object it's applied to, it simply
3940
/// simulates the various states of the <see cref="IAlignmentStrategy"/> interface.
4041
/// </remarks>
42+
[DataContract]
4143
public class SimulatedAlignment : AlignmentStrategy
4244
{
4345
#region Unity Inspector Variables
46+
[DataMember]
4447
[SerializeField]
4548
[Tooltip("The current simulated accuracy.")]
4649
private Vector3 currentAccuracy;
4750

51+
[DataMember]
4852
[SerializeField]
4953
[Tooltip("The current simulated state.")]
5054
private AlignmentState currentState = AlignmentState.Resolved;

SpatialAlignment-Unity/ProjectSettings/EditorBuildSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ EditorBuildSettings:
66
serializedVersion: 2
77
m_Scenes:
88
- enabled: 1
9-
path: Assets/SpatialAlignment-Examples/MultiParent/SA-MultiParent.unity
9+
path: Assets/SpatialAlignment-Examples/MultiParent/Scenes/SA-MultiParent.unity
1010
guid: 99c9720ab356a0642a771bea13969a05
1111
m_configObjects: {}

SpatialAlignment-Unity/ProjectSettings/ProjectSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ PlayerSettings:
527527
scriptingDefineSymbols: {}
528528
platformArchitecture: {}
529529
scriptingBackend:
530-
Metro: 2
530+
Metro: 1
531531
il2cppCompilerConfiguration: {}
532532
managedStrippingLevel: {}
533533
incrementalIl2cppBuild: {}

0 commit comments

Comments
 (0)