1- using System ;
1+ using LiteNetLibManager . Serialization ;
2+ using System ;
23using System . Collections . Generic ;
34using UnityEngine ;
45
@@ -13,133 +14,18 @@ public static void PutValue<TType>(this NetDataWriter writer, TType value)
1314
1415 public static void PutValue ( this NetDataWriter writer , Type type , object value )
1516 {
16- #region Generic Values
1717 if ( type . IsEnum )
1818 type = type . GetEnumUnderlyingType ( ) ;
1919
20- if ( type == typeof ( bool ) )
20+ if ( WriterRegistry . TryGetWriter ( type , out Action < NetDataWriter , object > writeFunc ) )
2121 {
22- writer . Put ( ( bool ) value ) ;
22+ writeFunc ( writer , value ) ;
2323 return ;
2424 }
2525
26- if ( type == typeof ( byte ) )
27- {
28- writer . Put ( ( byte ) value ) ;
29- return ;
30- }
31-
32- if ( type == typeof ( char ) )
33- {
34- writer . Put ( ( char ) value ) ;
35- return ;
36- }
37-
38- if ( type == typeof ( double ) )
39- {
40- writer . Put ( ( double ) value ) ;
41- return ;
42- }
43-
44- if ( type == typeof ( float ) )
45- {
46- writer . Put ( ( float ) value ) ;
47- return ;
48- }
49-
50- if ( type == typeof ( int ) )
51- {
52- writer . PutPackedInt ( ( int ) value ) ;
53- return ;
54- }
55-
56- if ( type == typeof ( long ) )
57- {
58- writer . PutPackedLong ( ( long ) value ) ;
59- return ;
60- }
61-
62- if ( type == typeof ( sbyte ) )
63- {
64- writer . Put ( ( sbyte ) value ) ;
65- return ;
66- }
67-
68- if ( type == typeof ( short ) )
69- {
70- writer . PutPackedShort ( ( short ) value ) ;
71- return ;
72- }
73-
74- if ( type == typeof ( string ) )
75- {
76- writer . Put ( ( string ) value ) ;
77- return ;
78- }
79-
80- if ( type == typeof ( uint ) )
81- {
82- writer . PutPackedUInt ( ( uint ) value ) ;
83- return ;
84- }
85-
86- if ( type == typeof ( ulong ) )
87- {
88- writer . PutPackedULong ( ( ulong ) value ) ;
89- return ;
90- }
91-
92- if ( type == typeof ( ushort ) )
93- {
94- writer . PutPackedUShort ( ( ushort ) value ) ;
95- return ;
96- }
97- #endregion
98-
99- #region Unity Values
100- if ( type == typeof ( Color ) )
101- {
102- writer . PutColor ( ( Color ) value ) ;
103- return ;
104- }
105-
106- if ( type == typeof ( Quaternion ) )
107- {
108- writer . PutQuaternion ( ( Quaternion ) value ) ;
109- return ;
110- }
111-
112- if ( type == typeof ( Vector2 ) )
113- {
114- writer . PutVector2 ( ( Vector2 ) value ) ;
115- return ;
116- }
117-
118- if ( type == typeof ( Vector2Int ) )
119- {
120- writer . PutVector2Int ( ( Vector2Int ) value ) ;
121- return ;
122- }
123-
124- if ( type == typeof ( Vector3 ) )
125- {
126- writer . PutVector3 ( ( Vector3 ) value ) ;
127- return ;
128- }
129-
130- if ( type == typeof ( Vector3Int ) )
131- {
132- writer . PutVector3Int ( ( Vector3Int ) value ) ;
133- return ;
134- }
135-
136- if ( type == typeof ( Vector4 ) )
137- {
138- writer . PutVector4 ( ( Vector4 ) value ) ;
139- return ;
140- }
141- #endregion
142-
26+ #if UNITY_EDITOR || DEVELOPMENT_BUILD
27+ Debug . LogWarning ( $ "No writer registered for type: { type . FullName } ") ;
28+ #endif
14329 if ( typeof ( INetSerializable ) . IsAssignableFrom ( type ) )
14430 {
14531 ( value as INetSerializable ) . Serialize ( writer ) ;
0 commit comments