Component not displaying properly in Unity when using a Converter
I have a component that uses a converter to convert a color into a darker version. The idea is to have the behind rectangle derive its color from a single color property in the viewModel.
If I export to unity without the converter, I can see the bottom rectangle. If I use the converter, this is what I see. Also some text on another part of the component that uses converter colors doesnt work as intended either.
So this could also be a converter issue? I am not sure as the converter was created by the AI agent. Please let me know if that is the case! Thank you so much.
The script in question:
type Darken1 = {}
function init(self: Darken1, context: Context): boolean
return true
end
function convert(self: Darken1, input: DataValueColor): DataValueColor
local output = DataValue.color()
-- Use the direct properties on DataValueColor
local r = input.red
local g = input.green
local b = input.blue
local a = input.alpha
-- Darken by 20% (multiply by 0.8)
output.red = math.floor(r * 0.6)
output.green = math.floor(g * 0.6)
output.blue = math.floor(b * 0.6)
output.alpha = a
return output
end
function reverseConvert(self: Darken1, input: DataValueColor): DataValueColor
local output = DataValue.color()
local r = input.red
local g = input.green
local b = input.blue
local a = input.alpha
-- Reverse: lighten by 25% (divide by 0.8 = multiply by 1.25)
output.red = math.min(255, math.floor(r / 0.6))
output.green = math.min(255, math.floor(g / 0.6))
output.blue = math.min(255, math.floor(b / 0.6))
output.alpha = a
return output
end
return function(): Converter<Darken1, DataValueColor, DataValueColor>
return {
init = init,
convert = convert,
reverseConvert = reverseConvert,
}
end