@@ -46,6 +46,8 @@ namespace SimpleJSON
4646 public enum JSONContainerType { Array , Object }
4747 public partial class JSONNode
4848 {
49+ public static byte Color32DefaultAlpha = 255 ;
50+ public static float ColorDefaultAlpha = 1f ;
4951 public static JSONContainerType VectorContainerType = JSONContainerType . Array ;
5052 public static JSONContainerType QuaternionContainerType = JSONContainerType . Array ;
5153 public static JSONContainerType RectContainerType = JSONContainerType . Array ;
@@ -259,9 +261,9 @@ public JSONNode WriteVector4(Vector4 aVec)
259261 public Color ReadColor ( Color aDefault )
260262 {
261263 if ( IsObject )
262- return new Color ( this [ "a " ] . AsFloat , this [ "r " ] . AsFloat , this [ "g " ] . AsFloat , this [ "b " ] . AsFloat ) ;
264+ return new Color ( this [ "r " ] . AsFloat , this [ "g " ] . AsFloat , this [ "b " ] . AsFloat , HasKey ( "a" ) ? this [ "a " ] . AsFloat : ColorDefaultAlpha ) ;
263265 if ( IsArray )
264- return new Color ( this [ 0 ] . AsFloat , this [ 1 ] . AsFloat , this [ 2 ] . AsFloat , this [ 3 ] . AsFloat ) ;
266+ return new Color ( this [ 0 ] . AsFloat , this [ 1 ] . AsFloat , this [ 2 ] . AsFloat , ( Count > 4 ) ? this [ 3 ] . AsFloat : ColorDefaultAlpha ) ;
265267 return aDefault ;
266268 }
267269 public Color ReadColor ( )
@@ -292,9 +294,9 @@ public JSONNode WriteColor(Color aCol)
292294 public Color32 ReadColor32 ( Color32 aDefault )
293295 {
294296 if ( IsObject )
295- return new Color32 ( ( byte ) this [ "r" ] . AsInt , ( byte ) this [ "g" ] . AsInt , ( byte ) this [ "b" ] . AsInt , ( byte ) this [ "a" ] . AsInt ) ;
297+ return new Color32 ( ( byte ) this [ "r" ] . AsInt , ( byte ) this [ "g" ] . AsInt , ( byte ) this [ "b" ] . AsInt , ( byte ) ( HasKey ( "a" ) ? this [ "a" ] . AsInt : Color32DefaultAlpha ) ) ;
296298 if ( IsArray )
297- return new Color32 ( ( byte ) this [ 0 ] . AsInt , ( byte ) this [ 1 ] . AsInt , ( byte ) this [ 2 ] . AsInt , ( byte ) this [ 3 ] . AsInt ) ;
299+ return new Color32 ( ( byte ) this [ 0 ] . AsInt , ( byte ) this [ 1 ] . AsInt , ( byte ) this [ 2 ] . AsInt , ( byte ) ( ( Count > 4 ) ? this [ 3 ] . AsInt : Color32DefaultAlpha ) ) ;
298300 return aDefault ;
299301 }
300302 public Color32 ReadColor32 ( )
0 commit comments