根据需求,动态修改UIButton下的Sprite的透明度,代码如下:
bgsprite.color = new Color(1.0f, 1.0f, 1.0f, 0.4f);
但是发现怎么设置都没用,显示bgsprite.color一直如下:
我明明没有在其它地方设置这个颜色值啊,为什么上面这个值了呢,纠结了一会儿之后发现是不是跟上层的UIButton有关系,果然发现:
Parent里有UIButton组件,该组件设置UIButton Disabled Color就是第一张的颜色值,果然在UIbutton enable=false之后,子UISprite的颜色就变成了这个颜色值了。
代码见UIButton:
/// <summary>
/// Whether the button should be enabled.
/// </summary>
public bool isEnabled
{
get
{
Collider col = collider;
return col && col.enabled;
}
set
{
Collider col = collider;
if (!col) return;
if (col.enabled != value)
{
col.enabled = value;
UpdateColor(value, false);
}
}
}
/// <summary>
/// Update the button's color to either enabled or disabled state.
/// </summary>
public void UpdateColor (bool shouldBeEnabled, bool immediate)
{
if (tweenTarget)
{
if (!mStarted)
{
mStarted = true;
Init();
}
Color c = shouldBeEnabled ? defaultColor : disabledColor;
TweenColor tc = TweenColor.Begin(tweenTarget, 0.15f, c);
if (immediate)
{
tc.color = c;
tc.enabled = false;
}
}
}