赞
踩
1.首先要切换按钮的 Transition 为 SpriteSwap
2.拖拽实现
3.代码控制
c#:
- public Button button;
- public Sprite normalSprite; //正常显示图片
- public Sprite highlightedSprite; //高亮显示图片
- public Sprite pressedSprite; //点击显示图片
- public Sprite disabledSprite; //禁用显示图片
- private void OnClickButton()
- {
- button.GetComponent<Image>().sprite = normalSprite;
- //设置按钮模式改为 SpriteSwap
- button.transition = Selectable.Transition.SpriteSwap;
- //设置变化状态
- SpriteState state = new SpriteState();
- state.highlightedSprite = highlightedSprite;
- state.pressedSprite = pressedSprite;
- state.disabledSprite = disabledSprite;
- //赋值
- button.spriteState = state;
- }
Lua:
原理是一样的
- local curr_btn = self._control.class_btn
- local sprite_state = UnityEngine.UI.SpriteState.New()
- sprite_state.pressedSprite = ResourceLoader:loadSprite("res url")
- --赋值
- curr_btn .button.spriteState = sprite_state
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。