@@ -14,9 +14,7 @@ namespace Exiled.Loader.Features.Configs.CustomConverters
1414
1515 using Exiled . API . Features ;
1616 using Exiled . API . Features . Pools ;
17-
1817 using UnityEngine ;
19-
2018 using YamlDotNet . Core ;
2119 using YamlDotNet . Core . Events ;
2220 using YamlDotNet . Serialization ;
@@ -30,19 +28,26 @@ public sealed class VectorsConverter : IYamlTypeConverter
3028 public bool Accepts ( Type type )
3129 {
3230 Type baseType = Nullable . GetUnderlyingType ( type ) ?? type ;
33- return baseType == typeof ( Vector2 ) || baseType == typeof ( Vector3 ) || baseType == typeof ( Vector4 ) ;
31+ return baseType == typeof ( Vector2 ) || baseType == typeof ( Vector3 ) || baseType == typeof ( Vector4 ) || baseType == typeof ( Quaternion ) ;
3432 }
3533
3634 /// <inheritdoc cref="IYamlTypeConverter" />
3735 public object ReadYaml ( IParser parser , Type type )
3836 {
39- Type baseType = Nullable . GetUnderlyingType ( type ) ?? type ;
37+ Type baseType = Nullable . GetUnderlyingType ( type ) ;
38+
39+ bool isNullable = true ;
40+ if ( baseType == null )
41+ {
42+ isNullable = false ;
43+ baseType = type ;
44+ }
4045
4146 if ( parser . TryConsume ( out Scalar scalar ) )
4247 {
4348 if ( string . IsNullOrEmpty ( scalar . Value ) || scalar . Value . Equals ( "null" , StringComparison . OrdinalIgnoreCase ) )
4449 {
45- if ( Nullable . GetUnderlyingType ( type ) != null )
50+ if ( isNullable )
4651 return null ;
4752
4853 Log . Error ( $ "Cannot assign null to non-nullable type { baseType . FullName } .") ;
@@ -75,7 +80,11 @@ public object ReadYaml(IParser parser, Type type)
7580 coordinates . Add ( coordinate ) ;
7681 }
7782
78- object vector = Activator . CreateInstance ( baseType , coordinates . ToArray ( ) ) ;
83+ object vector ;
84+ if ( isNullable )
85+ vector = Activator . CreateInstance ( type , Activator . CreateInstance ( baseType , coordinates . ToArray ( ) ) ) ;
86+ else
87+ vector = Activator . CreateInstance ( type , coordinates . ToArray ( ) ) ;
7988
8089 ListPool < object > . Pool . Return ( coordinates ) ;
8190
@@ -111,6 +120,13 @@ public void WriteYaml(IEmitter emitter, object value, Type type)
111120 coordinates [ "z" ] = vector4 . z ;
112121 coordinates [ "w" ] = vector4 . w ;
113122 }
123+ else if ( value is Quaternion quaternion )
124+ {
125+ coordinates [ "x" ] = quaternion . x ;
126+ coordinates [ "y" ] = quaternion . y ;
127+ coordinates [ "z" ] = quaternion . z ;
128+ coordinates [ "w" ] = quaternion . w ;
129+ }
114130
115131 emitter . Emit ( new MappingStart ( ) ) ;
116132
0 commit comments