EZGUI: 代码控制刷UIButton四态的贴图
/// <summary> /// 新增物品Icon(不删除之前的icon) /// </summary> /// <param name="index">物品在packsprite中的index</param> /// <param name="button">物品所在控件</param> public void AddItemIcon(int index, AutoSpriteControlBase button, PackedSprite sprites) { SPRITE_FRAME mySpriteFrame = sprites.animations[0].GetFrame(index); UVAnimation uiAnimation = button.animations[0];//0:normal 1:over 2:active 3:disable uiAnimation.SetAnimFrame(0, mySpriteFrame); // Update mesh UVs: button.SetFrameInfo(mySpriteFrame); }
/// <summary> /// 更新物品Icon(替换icon) /// </summary> /// <param name="index">物品在packsprite中的index</param> /// <param name="button">物品所在控件</param> public void UpdateItemIcon(int index, AutoSpriteControlBase button, PackedSprite sprites) { SPRITE_FRAME mySpriteFrame = sprites.animations[0].GetFrame(index); UVAnimation uiAnimation = button.GetCurAnim(); uiAnimation.SetAnimFrame(0, mySpriteFrame); // Update mesh UVs: button.SetFrameInfo(mySpriteFrame);
/// <summary> /// 删除物品Icon /// </summary> /// <param name="index">物品在packsprite中的index</param> /// <param name="button">物品所在控件</param> public void DeleteItemIcon(int index, AutoSpriteControlBase button, PackedSprite sprite) { SPRITE_FRAME mySpriteFrame = sprite.animations[0].GetFrame(index); UVAnimation uiAnimation = button.GetCurAnim(); uiAnimation.SetAnimFrame(0, mySpriteFrame); button.SetFrameInfo(mySpriteFrame); }
PS:EZGUI的其他控制组件也可用。
在SpriteBase.cs脚本中添加这个方法:
/// <summary> /// 修改控件的某状态的图片 如:UIButton的四态 /// </summary> /// <param name="index">状态索引</param> /// <param name="frameData">sprite frame</param> public void SetAnimFrame(int index, SPRITE_FRAME frameData) { Debug.LogError("frames.length=" + frames.Length); if (index < frames.Length) { frames[index] = frameData; } }