Skip to content

Commit bb186c2

Browse files
authored
Samples (#26)
* readonly samples * update packages-lock * more samples * unify extension functions into one static class * only process code-gen on instance of type derived from UnityEngine.Object * indent position of nullable toggle. * interface types * more samples * draw any list and dictionary as single value * more samples * sample of nullable value.
1 parent d019211 commit bb186c2

File tree

59 files changed

+1387
-144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1387
-144
lines changed

Assets/Samples/AnySerialize.Samples.asmdef

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
"includePlatforms": [],
99
"excludePlatforms": [],
1010
"allowUnsafeCode": false,
11-
"overrideReferences": false,
12-
"precompiledReferences": [],
11+
"overrideReferences": true,
12+
"precompiledReferences": [
13+
"Newtonsoft.Json.dll"
14+
],
1315
"autoReferenced": true,
1416
"defineConstraints": [],
1517
"versionDefines": [],

Assets/Samples/ClassValues.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections.Generic;
2+
3+
namespace AnySerialize
4+
{
5+
//
6+
// public struct Struct
7+
// {
8+
// public int Value;
9+
// public string[] Array;
10+
// public List<int[]> ListArray;
11+
// public GenericClass<int, long[]> GenericValue;
12+
// }
13+
//
14+
// public record Record
15+
// {
16+
//
17+
// }
18+
}

Assets/Samples/ClassValues.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Samples/GameObject.prefab

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ GameObject:
1010
m_Component:
1111
- component: {fileID: 7557180844171351635}
1212
- component: {fileID: 7557180844171351634}
13-
- component: {fileID: 2050478359041717691}
1413
m_Layer: 0
1514
m_Name: GameObject
1615
m_TagString: Untagged
1716
m_Icon: {fileID: 0}
1817
m_NavMeshLayer: 0
1918
m_StaticEditorFlags: 0
20-
m_IsActive: 1
19+
m_IsActive: 0
2120
--- !u!4 &7557180844171351635
2221
Transform:
2322
m_ObjectHideFlags: 0
@@ -85,15 +84,13 @@ MonoBehaviour:
8584
- _value: 030000000200000001000000
8685
<AnyClassArray>k__BackingField:
8786
_value:
88-
- _field0:
89-
_value: 321
90-
_field1:
91-
_value: 123
87+
- _value:
88+
Int: 0
89+
Float: 0
9290
<A>k__BackingField:
93-
_field0:
94-
_value: 12333
95-
_field1:
96-
_value: 3333
91+
_value:
92+
Int: 111
93+
Float: 2222
9794
<B>k__BackingField:
9895
_field0:
9996
_value: 1
@@ -142,50 +139,3 @@ MonoBehaviour:
142139
_value: f3e0010000000000
143140
<IntValueROWithoutBacking>k__BackingField:
144141
_value: 333
145-
--- !u!114 &2050478359041717691
146-
MonoBehaviour:
147-
m_ObjectHideFlags: 0
148-
m_CorrespondingSourceObject: {fileID: 0}
149-
m_PrefabInstance: {fileID: 0}
150-
m_PrefabAsset: {fileID: 0}
151-
m_GameObject: {fileID: 7557180844171351637}
152-
m_Enabled: 1
153-
m_EditorHideFlags: 0
154-
m_Script: {fileID: 11500000, guid: 9752afb77b5043a7b59b931ca0525b5f, type: 3}
155-
m_Name:
156-
m_EditorClassIdentifier:
157-
<Self>k__BackingField:
158-
_value:
159-
Int: 1064
160-
<Self2>k__BackingField:
161-
_field0:
162-
_value: 2230
163-
_field1:
164-
<Value>k__BackingField:
165-
rid: 1828758672445276160
166-
references:
167-
version: 2
168-
RefIds:
169-
- rid: -2
170-
type: {class: , ns: , asm: }
171-
- rid: 1828758672445276160
172-
type: {class: CycleClasses/SelfCycle2, ns: AnySerialize, asm: AnySerialize.Samples}
173-
data:
174-
Int: 123
175-
<Self2>k__BackingField:
176-
<Value>k__BackingField:
177-
rid: 1828758672445276161
178-
- rid: 1828758672445276161
179-
type: {class: CycleClasses/SelfCycle2, ns: AnySerialize, asm: AnySerialize.Samples}
180-
data:
181-
Int: 44
182-
<Self2>k__BackingField:
183-
<Value>k__BackingField:
184-
rid: 1828758672445276162
185-
- rid: 1828758672445276162
186-
type: {class: CycleClasses/SelfCycle2, ns: AnySerialize, asm: AnySerialize.Samples}
187-
data:
188-
Int: 2222
189-
<Self2>k__BackingField:
190-
<Value>k__BackingField:
191-
rid: -2

Assets/Samples/JsonExtension.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Reflection;
3+
using System.Text.RegularExpressions;
4+
using Newtonsoft.Json;
5+
using UnityEngine;
6+
7+
namespace AnySerialize
8+
{
9+
public static class JsonExtension
10+
{
11+
private static readonly Regex _backingFieldName = new(@"<(\w+)>k__BackingField");
12+
13+
public static void JsonLog<T>(this T self) where T : MonoBehaviour
14+
{
15+
Debug.Log($"-------------------------{self.GetType().Name}---------------------------");
16+
var type = self.GetType();
17+
foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
18+
{
19+
var propertyName = _backingFieldName.Match(field.Name).Groups[1].Value;
20+
var property = type.GetProperty(propertyName)!;
21+
Debug.Log($"{property.Name} = {JsonConvert.SerializeObject(property.GetValue(self))}{Environment.NewLine}{field.FieldType}");
22+
}
23+
}
24+
}
25+
}

Assets/Samples/JsonExtension.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Samples/ReadOnlyArrayValues.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections.Generic;
2+
using UnityEngine;
3+
4+
namespace AnySerialize
5+
{
6+
public class ReadOnlyArrayValues : MonoBehaviour
7+
{
8+
[AnySerialize] public int[] IntArray { get; }
9+
[AnySerialize] public int[][] IntArray2 { get; }
10+
[AnySerialize] public List<long>[] LongListArray { get; }
11+
[AnySerialize] public Dictionary<string, int>[] DictionaryArray { get; }
12+
[AnySerialize] public string[][][] StringArray3 { get; }
13+
[AnySerialize] public IReadOnlyList<string> StringReadOnlyList { get; }
14+
[AnySerialize] public PlainClass[][] PlainClasses2 { get; }
15+
16+
private void Awake()
17+
{
18+
this.JsonLog();
19+
}
20+
}
21+
}

Assets/Samples/ReadOnlyArrayValues.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &4986915765763396050
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
serializedVersion: 6
10+
m_Component:
11+
- component: {fileID: 4986915765763396048}
12+
- component: {fileID: 4986915765763396051}
13+
m_Layer: 0
14+
m_Name: ReadOnlyArrayValues
15+
m_TagString: Untagged
16+
m_Icon: {fileID: 0}
17+
m_NavMeshLayer: 0
18+
m_StaticEditorFlags: 0
19+
m_IsActive: 1
20+
--- !u!4 &4986915765763396048
21+
Transform:
22+
m_ObjectHideFlags: 0
23+
m_CorrespondingSourceObject: {fileID: 0}
24+
m_PrefabInstance: {fileID: 0}
25+
m_PrefabAsset: {fileID: 0}
26+
m_GameObject: {fileID: 4986915765763396050}
27+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
28+
m_LocalPosition: {x: 0, y: 0, z: 0}
29+
m_LocalScale: {x: 1, y: 1, z: 1}
30+
m_ConstrainProportionsScale: 0
31+
m_Children: []
32+
m_Father: {fileID: 0}
33+
m_RootOrder: 0
34+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
35+
--- !u!114 &4986915765763396051
36+
MonoBehaviour:
37+
m_ObjectHideFlags: 0
38+
m_CorrespondingSourceObject: {fileID: 0}
39+
m_PrefabInstance: {fileID: 0}
40+
m_PrefabAsset: {fileID: 0}
41+
m_GameObject: {fileID: 4986915765763396050}
42+
m_Enabled: 1
43+
m_EditorHideFlags: 0
44+
m_Script: {fileID: 11500000, guid: e363d0226e324431b29268d9e210dfad, type: 3}
45+
m_Name:
46+
m_EditorClassIdentifier:
47+
<IntArray>k__BackingField:
48+
_value: 0100000002000000
49+
<IntArray2>k__BackingField:
50+
_value:
51+
- _value: 03000000
52+
- _value: 0400000005000000
53+
- _value: 060000000700000008000000
54+
<LongListArray>k__BackingField:
55+
_value:
56+
- _value: 09000000000000000a00000000000000
57+
- _value: 0b000000000000000c000000000000000d00000000000000
58+
<DictionaryArray>k__BackingField:
59+
_value:
60+
- _pairs:
61+
- _field0:
62+
_value: a
63+
_field1:
64+
_value: 14
65+
- _field0:
66+
_value: b
67+
_field1:
68+
_value: 15
69+
- _pairs:
70+
- _field0:
71+
_value: c
72+
_field1:
73+
_value: 16
74+
- _field0:
75+
_value: d
76+
_field1:
77+
_value: 17
78+
- _field0:
79+
_value: e
80+
_field1:
81+
_value: 18
82+
<StringArray3>k__BackingField:
83+
_value:
84+
- _value:
85+
- _value:
86+
- fdas
87+
- ggg
88+
- 3e21f
89+
- _value:
90+
- fdafdasfdas321
91+
<StringReadOnlyList>k__BackingField:
92+
_value:
93+
- _value: fdafdas
94+
- _value: 321312
95+
- _value: f3e12321
96+
<PlainClasses2>k__BackingField:
97+
_value:
98+
- _value:
99+
- _value:
100+
Int: 0
101+
Float: 0
102+
DoubleArray: []

Assets/Samples/ReadOnlyArrayValues.prefab.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)