Skip to content

Commit d5b9986

Browse files
committed
Update GameObjectSetActiveBinding.cs
Better naming and error handling.
1 parent 04bf8c7 commit d5b9986

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

Runtime/GameObjectSetActiveBinding.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ namespace Gameframe.Bindings
66
public class GameObjectSetActiveBinding : BindingBehaviour
77
{
88
public GameObject target;
9-
public ConversionType conversionType = ConversionType.EnableWhenNotEqual;
9+
public ConversionType conversionType = ConversionType.EnableWhenNumberNotEqual;
1010
public int numberCompareValue = 0;
1111
public string stringCompareValue = string.Empty;
1212
public bool invert = false;
1313

1414
public enum ConversionType
1515
{
16-
EnableWhenNotEqual,
17-
EnableWhenGreaterThan,
18-
EnableWhenLessThan,
19-
EnableWhenNotNull,
16+
None,
17+
EnableWhenNumberNotEqual,
18+
EnableWhenNumberGreaterThan,
19+
EnableWhenNumberLessThan,
20+
EnableWhenObjectNotNull,
2021
EnableWhenStringEquals
2122
}
2223

@@ -41,11 +42,21 @@ protected override void SetupBindingTarget(Binding binding)
4142

4243
private object Converter(object sourceValue)
4344
{
44-
if (invert)
45+
try
4546
{
46-
return !ConvertValue(sourceValue);
47+
if (invert)
48+
{
49+
return !ConvertValue(sourceValue);
50+
}
51+
52+
return ConvertValue(sourceValue);
53+
}
54+
catch (Exception exception)
55+
{
56+
Debug.LogError($"GameObjectSetActiveBinding conversion failed with exception: {exception}", this);
57+
enabled = false;
58+
return false;
4759
}
48-
return ConvertValue(sourceValue);
4960
}
5061

5162
private bool ConvertValue(object sourceValue)
@@ -57,16 +68,18 @@ private bool ConvertValue(object sourceValue)
5768

5869
switch (conversionType)
5970
{
60-
case ConversionType.EnableWhenNotNull:
71+
case ConversionType.EnableWhenObjectNotNull:
6172
return true;
62-
case ConversionType.EnableWhenNotEqual:
73+
case ConversionType.EnableWhenNumberNotEqual:
6374
return ConvertNotEqual(sourceValue);
64-
case ConversionType.EnableWhenGreaterThan:
75+
case ConversionType.EnableWhenNumberGreaterThan:
6576
return ConvertGreaterThan(sourceValue);
66-
case ConversionType.EnableWhenLessThan:
77+
case ConversionType.EnableWhenNumberLessThan:
6778
return ConvertLessThan(sourceValue);
6879
case ConversionType.EnableWhenStringEquals:
6980
return ((string)sourceValue) == stringCompareValue;
81+
case ConversionType.None:
82+
return (bool)sourceValue;
7083
default:
7184
throw new ArgumentOutOfRangeException();
7285
}

0 commit comments

Comments
 (0)