用NGUI做一个图片圆切角的效果,shader有了,但是用来控制圆切角半径的参数却无法进行更新。
通过各种查阅,发现UIWidget中有个
/// <summary> /// Set the callback that will be triggered when the widget is being rendered (OnWillRenderObject). /// This is where you would set material properties and shader values. /// </summary>
public UIDrawCall.OnRenderCallback onRender { } NGUI给材质更新参数是在通过这个回调修改的,故给这个委托赋值一个方法,即可实现。例如
public float cutRadius; UITexture tx; // Use this for initialization void Start () { tx = GetComponent<UITexture>(); tx.onRender +=SetMaterialValue; } void SetMaterialValue(Material mat) { if (mat != null) { mat.SetFloat("_Radius", cutRadius); } }
|