By getting the amount of values with reader.Length, we can support multiple ways to interpret an argument. An example would be how a UnityEngine.Color can be interpreted both from a hex value and an RGB value.
[Converter]publicstaticColorColorConverter(ArgumentReader reader){float r, g, b, a;switch (reader.Length) { // In case the amount of components was 1case1:if (reader.IsNumeric()) { // If the component is a number, return an RGB color with this valuefloat value =reader.Read<float>() /255;returnnew(value, value, value); }else { // If the component can be read as a string, try to return a color based on a hex valuestring hex =reader.Read<string>();if (ColorUtility.TryParseHtmlString(hex,outColor hexColor))return hexColor;elsethrownewException($"Invalid hex value: '{hex}'."); } // In case the amount of components was 3case3: // Return an RGB value using the 3 numbers r =reader.Read<float>(); g =reader.Read<float>(); b =reader.Read<float>();returnnew(r, g, b); // In case the amount of components was 4case4: // Return an RGBA value using the 4 numbers r =reader.Read<float>(); g =reader.Read<float>(); b =reader.Read<float>(); a =reader.Read<float>();returnnew(r, g, b, a); } // If more or less components was provided, we notify of the errorthrownewException($"Could not retrieve color from input: {reader.Source}.");}
Note
This converter is built-in, and is purely used as an example. You wouldn't need to create this in order to support parameters of type UnityEngine.Color.