Hi,
I'm trying to get this color picker
https://www.assetstore.unity3d.com/#/content/7353 working with NGUI but having a real pita.
I'm using NGui 2.7 for now.
I have a slider with color hues sending the update to a huebrightness material that is on a UITexture, which just has a color value.
This material is updating in the editor properly, and on the NGUI texture on initial start (it sets the right color when the OnSliderChange is sent on Start) but the UITexture will not update after that.
This is driving me nuts!
Any clues as to why this does not work properly?
It should be
. assign material to UITexture
. update material
. UITexture shows changed material
Here's the shader (one of them, the HueBrightness)
As I say this works on startup (see Start() below) but will not update on screen after that (see SetHue(hueSliderValue) ) but in the editor the background material is updating correctly.
Why does it work initially then fail to update?
public Material backgroundMaterial;
private UITexture texture;
private Texture2D tex;
void Start() {
texture = GetComponent<UITexture>();
//color = HSBColor.FromColor(renderer.sharedMaterial.GetColor("_Color"));
texture.material = backgroundMaterial;
}
public void SetHue(float hue)
{
texture
.material.SetColor("_Color",
new HSBColor
(hue,
1,
1).ToColor()); }
Shader "ColorPicker/ColorSaturationBrightness" {
Properties {
_Color ("Main Color", Color) = (0.75,0.15,0.56,1)
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
// vertex input: position, UV
struct appdata {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct pos_output {
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
};
pos_output vert(appdata v) {
pos_output o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = float4(v.texcoord.xy, 0, 0);
return o;
}
half4 frag(pos_output o) : COLOR {
half4 c = o.uv.y + (_Color - 1)*o.uv.x;
return c;
}
ENDCG
}
}
}
ty!