Skip to content

Commit

Permalink
Add support for UdonBehaviour.enabled in the latest beta SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinVR committed Oct 16, 2020
1 parent 66f5bc9 commit 5587b7c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
14 changes: 10 additions & 4 deletions Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1819,11 +1819,9 @@ private bool HandleLocalUdonBehaviourMethodLookup(string localUdonMethodName)
private bool HandleLocalUdonBehaviourPropertyLookup(string localUdonPropertyName)
{
PropertyInfo[] foundProperties = typeof(Component).GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(e => e.Name == localUdonPropertyName).ToArray();

if (localUdonPropertyName == "enabled")
{
throw new System.NotSupportedException("Udon does not expose the `enabled` property on UdonBehaviours try using gameObject.active instead and find my post on the canny complaining about it");
}
foundProperties = typeof(VRC.Udon.Common.Interfaces.IUdonEventReceiver).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(e => e.Name == localUdonPropertyName).ToArray();

if (foundProperties.Length == 0)
return false;
Expand Down Expand Up @@ -2007,6 +2005,14 @@ private bool HandleMemberPropertyAccess(string propertyToken)

PropertyInfo[] foundProperties = currentReturnType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(e => e.Name == propertyToken).ToArray();

if (propertyToken == "enabled" &&
(currentReturnType == typeof(VRC.Udon.UdonBehaviour) ||
currentReturnType == typeof(UdonSharpBehaviour) ||
currentReturnType.IsSubclassOf(typeof(UdonSharpBehaviour))))
{
foundProperties = typeof(VRC.Udon.Common.Interfaces.IUdonEventReceiver).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(e => e.Name == propertyToken).ToArray();
}

if (foundProperties.Length == 0)
return false;

Expand Down
18 changes: 17 additions & 1 deletion Assets/UdonSharp/Tests/TestScripts/Core/MethodCallsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,23 @@ public void ExecuteTests()
tester.TestAssertion("String Join Objects params", string.Join(", ", this, this, this, this) == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");
tester.TestAssertion("String Join Objects array", string.Join(", ", new object[] { this, this, this, this }) == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");

//tester.TestAssertion("Split test", "a b c d".Split(new [] { ' ' }, System.StringSplitOptions.None).Length == 4);
tester.TestAssertion("Split test", "a b c d".Split(new [] { ' ' }, System.StringSplitOptions.None).Length == 4);

enabled = false;
tester.TestAssertion("UdonBehaviour enabled", enabled == false);
enabled = true;

UdonSharpBehaviour self = this;

self.enabled = false;
tester.TestAssertion("UdonSharpBehaviour ref enabled", self.enabled == false);
self.enabled = true;

UdonBehaviour selfUdon = (UdonBehaviour)(Component)this;

selfUdon.enabled = false;
tester.TestAssertion("UdonSharpBehaviour ref enabled", selfUdon.enabled == false);
selfUdon.enabled = true;
}

//public void test(int a, bool b, float c = 5f, params float[] d)
Expand Down

0 comments on commit 5587b7c

Please sign in to comment.