You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

80 lines
2.7 KiB

using UnityEngine;
using UnityEngine.UI;
public class ButtonIV : Button
{
public Transition transition2;
public Graphic targetGraphic2;
public ColorBlock colors2;
public Sprite normalSprite2;
public SpriteState spriteState2;
public Transition transition3;
public Graphic targetGraphic3;
public ColorBlock colors3;
public Sprite normalSprite3;
public SpriteState spriteState3;
public Transition transition4;
public Graphic targetGraphic4;
public ColorBlock colors4;
public Sprite normalSprite4;
public SpriteState spriteState4;
public Transition transition5;
public Graphic targetGraphic5;
public ColorBlock colors5;
public Sprite normalSprite5;
public SpriteState spriteState5;
protected override void DoStateTransition(SelectionState state, bool instant)
{
base.DoStateTransition(state, instant);
ApplyTransition(state, transition2, targetGraphic2, colors2, spriteState2, normalSprite2);
ApplyTransition(state, transition3, targetGraphic3, colors3, spriteState3, normalSprite3);
ApplyTransition(state, transition4, targetGraphic4, colors4, spriteState4, normalSprite4);
ApplyTransition(state, transition5, targetGraphic5, colors5, spriteState5, normalSprite5);
}
void ApplyTransition(SelectionState state, Transition transition, Graphic graphic, ColorBlock colorBlock, SpriteState spriteState, Sprite normalSprite)
{
if (graphic is null) return;
if (transition == Transition.ColorTint)
{
switch (state)
{
case SelectionState.Pressed:
graphic.color = colorBlock.pressedColor;
break;
case SelectionState.Disabled:
graphic.color = colorBlock.disabledColor;
break;
default:
graphic.color = colorBlock.normalColor;
break;
}
}
else if (transition == Transition.SpriteSwap)
{
if (!(graphic is Image img)) return;
switch (state)
{
case SelectionState.Pressed:
if (spriteState.pressedSprite != null)
img.sprite = spriteState.pressedSprite;
break;
case SelectionState.Disabled:
if (spriteState.disabledSprite != null)
img.sprite = spriteState.disabledSprite;
break;
default:
if (normalSprite != null)
img.sprite = normalSprite2;
break;
}
}
}
}