Preserve sprite modifications in more situations

release
David Gileadi 2017-08-19 21:57:27 -07:00
parent 382a19cb36
commit ea8a9e9d36
3 changed files with 27 additions and 9 deletions

View File

@ -1666,6 +1666,7 @@ namespace UnityEditor.UI
for (int i = 0; i < 3; i++)
{
var button = AddButtonAsChild(go);
button.gameObject.AddComponent<Segment>();
button.name = "Segment " + (i + 1);
var text = button.GetComponentInChildren<Text>();
text.text = labels[i];

View File

@ -74,9 +74,11 @@ namespace UnityEngine.UI.Extensions
{
value = Math.Max(value, -1);
value = Math.Min(value, segments.Length - 1);
if (value == m_selectedSegmentIndex)
return;
m_selectedSegmentIndex = value;
if (value == -1)
{
if (selectedSegment)
{
var segment = selectedSegment.GetComponent<Segment>();
@ -86,9 +88,10 @@ namespace UnityEngine.UI.Extensions
}
selectedSegment = null;
}
}
else
if (value != -1)
{
selectedSegment = segments[value];
var segment = selectedSegment.GetComponent<Segment>();
if (segment)
{
@ -314,6 +317,13 @@ namespace UnityEngine.UI.Extensions
MaintainSelection();
}
protected override void OnEnable()
{
base.OnEnable();
if (segmentedControl)
MaintainSelection();
}
public virtual void OnSubmit(BaseEventData eventData)
{
selected = true;
@ -388,6 +398,7 @@ namespace UnityEngine.UI.Extensions
switch (button.transition)
{
case Selectable.Transition.ColorTint:
button.image.overrideSprite = cutSprite;
StartColorTween(tintColor * button.colors.colorMultiplier, instant);
ChangeTextColor(textColor * button.colors.colorMultiplier);
break;
@ -397,6 +408,7 @@ namespace UnityEngine.UI.Extensions
DoSpriteSwap(transitionSprite);
break;
case Selectable.Transition.Animation:
button.image.overrideSprite = cutSprite;
TriggerAnimation(triggerName);
break;
}

View File

@ -104,6 +104,11 @@ namespace UnityEngine.UI.Extensions
}
#endif
protected override void Start()
{
RecreateSprites(sides);
}
private Selectable[] GetSides()
{
var buttons = GetComponentsInChildren<Selectable>();