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++) for (int i = 0; i < 3; i++)
{ {
var button = AddButtonAsChild(go); var button = AddButtonAsChild(go);
button.gameObject.AddComponent<Segment>();
button.name = "Segment " + (i + 1); button.name = "Segment " + (i + 1);
var text = button.GetComponentInChildren<Text>(); var text = button.GetComponentInChildren<Text>();
text.text = labels[i]; text.text = labels[i];

View File

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

View File

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