Add extra index guard logic
This commit is contained in:
@@ -508,10 +508,17 @@ namespace FlaxEditor.Viewport
|
||||
{
|
||||
if (int.TryParse(defaultData, out var index))
|
||||
{
|
||||
_defaultScaleActiveIndex = index;
|
||||
if (index != -1)
|
||||
var options = Editor.Instance.UI.DefaultViewportScaleOptions;
|
||||
if (options.Count > index)
|
||||
{
|
||||
ChangeUIView(Editor.Instance.UI.DefaultViewportScaleOptions[index]);
|
||||
_defaultScaleActiveIndex = index;
|
||||
if (index != -1)
|
||||
ChangeUIView(Editor.Instance.UI.DefaultViewportScaleOptions[index]);
|
||||
}
|
||||
// Assume option does not exist anymore so move to default.
|
||||
else if (index != -1)
|
||||
{
|
||||
_defaultScaleActiveIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -521,10 +528,18 @@ namespace FlaxEditor.Viewport
|
||||
{
|
||||
if (int.TryParse(data, out var index))
|
||||
{
|
||||
_customScaleActiveIndex = index;
|
||||
if (index != -1)
|
||||
var options = Editor.Instance.UI.CustomViewportScaleOptions;
|
||||
if (options.Count > index)
|
||||
{
|
||||
ChangeUIView(Editor.Instance.UI.CustomViewportScaleOptions[index]);
|
||||
_customScaleActiveIndex = index;
|
||||
if (index != -1)
|
||||
ChangeUIView(options[index]);
|
||||
}
|
||||
// Assume option does not exist anymore so move to default.
|
||||
else if (index != -1)
|
||||
{
|
||||
_defaultScaleActiveIndex = 0;
|
||||
_customScaleActiveIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1199,13 +1199,22 @@ namespace FlaxEditor.Windows
|
||||
if (_defaultScaleActiveIndex != -1)
|
||||
{
|
||||
var options = Editor.UI.DefaultViewportScaleOptions;
|
||||
ChangeViewportRatio(options[_defaultScaleActiveIndex]);
|
||||
if (options.Count > _defaultScaleActiveIndex)
|
||||
ChangeViewportRatio(options[_defaultScaleActiveIndex]);
|
||||
else
|
||||
_defaultScaleActiveIndex = 0;
|
||||
}
|
||||
|
||||
if (_customScaleActiveIndex != -1)
|
||||
{
|
||||
var options = Editor.UI.CustomViewportScaleOptions;
|
||||
ChangeViewportRatio(options[_customScaleActiveIndex]);
|
||||
if (options.Count > _customScaleActiveIndex)
|
||||
ChangeViewportRatio(options[_customScaleActiveIndex]);
|
||||
else
|
||||
{
|
||||
_defaultScaleActiveIndex = 0;
|
||||
_customScaleActiveIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user