Add null (missing component) safety checks

release
David Gileadi 2017-08-12 16:56:22 -07:00
parent c5edc0cdf1
commit 382a19cb36
2 changed files with 25 additions and 6 deletions

View File

@ -79,16 +79,24 @@ namespace UnityEngine.UI.Extensions
{
if (selectedSegment)
{
selectedSegment.GetComponent<Segment>().selected = false;
var segment = selectedSegment.GetComponent<Segment>();
if (segment)
{
segment.selected = false;
}
selectedSegment = null;
}
}
else
{
var segment = selectedSegment.GetComponent<Segment>();
if (segment)
{
#if UNITY_EDITOR
segments[value].GetComponent<Segment>().StoreTextColor();
segment.StoreTextColor();
#endif
segments[value].GetComponent<Segment>().selected = true;
segment.selected = true;
}
}
}
}
@ -164,7 +172,11 @@ namespace UnityEngine.UI.Extensions
continue;
var sprite = CutSprite(segments[i].image.sprite, i == 0, i == segments.Length - 1);
segments[i].GetComponent<Segment>().cutSprite = sprite;
var segment = segments[i].GetComponent<Segment>();
if (segment)
{
segment.cutSprite = sprite;
}
segments[i].image.overrideSprite = sprite;
}
}
@ -328,7 +340,10 @@ namespace UnityEngine.UI.Extensions
{
var segment = segmentedControl.selectedSegment.GetComponent<Segment>();
segmentedControl.selectedSegment = null;
segment.TransitionButton();
if (segment)
{
segment.TransitionButton();
}
}
segmentedControl.selectedSegment = this.button;

View File

@ -174,7 +174,11 @@ namespace UnityEngine.UI.Extensions
continue;
var sprite = CutSprite(sides[i].image.sprite, i == 0);
sides[i].GetComponent<StepperSide>().cutSprite = sprite;
var side = sides[i].GetComponent<StepperSide>();
if (side)
{
side.cutSprite = sprite;
}
sides[i].image.overrideSprite = sprite;
}
}