Skip to content

Commit 1f3a004

Browse files
committed
Fix issues with storing arrays of UdonSharpBehaviour and accessing elements
- Fix storing arrays of UdonSharpBehaviour - Fix accessing elements on UdonSharpBehaviour arrays not propagating the user type correctly in some cases - Partially fix the component type restrictions on drawing arrays of UdonSharpBehaviours. This still needs more work to restrict to the correct type of UdonSharpBehaviour.
1 parent 50ac53e commit 1f3a004

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,15 @@ public System.Type GetReturnType(bool getUserType = false)
866866
if (!accessSymbol.symbolCsType.IsArray)
867867
throw new System.Exception("Type is not an array type");
868868

869+
if (getUserType)
870+
return accessSymbol.userCsType.GetElementType();
871+
872+
if (accessSymbol.IsUserDefinedBehaviour() && accessSymbol.userCsType.IsArray)
873+
{
874+
// Special case for arrays since the symbolCsType needs to return a Component[], but we need to get the element type of the UdonBehaviour[]
875+
return typeof(VRC.Udon.UdonBehaviour);
876+
}
877+
869878
return accessSymbol.symbolCsType.GetElementType();
870879
}
871880
else
@@ -930,7 +939,7 @@ public bool ResolveAccessToken(string accessToken)
930939
HandleExternUserMethodLookup(accessToken) ||
931940
HandleMemberPropertyAccess(accessToken) ||
932941
HandleMemberFieldAccess(accessToken) ||
933-
HandleMemberMethodLookup(accessToken);
942+
HandleMemberMethodLookup(accessToken);
934943
}
935944

936945

Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private object DrawUnityObjectField(string fieldName, string symbol, (object val
267267
objectRect = EditorGUI.PrefixLabel(objectRect, new GUIContent(fieldName));
268268

269269
currentUserScript = fieldDefinition.userBehaviourSource;
270-
270+
271271
UnityEngine.Object objectFieldValue = (UnityEngine.Object)doObjectFieldMethod.Invoke(null, new object[] {
272272
objectRect,
273273
objectRect,
@@ -345,6 +345,11 @@ private object DrawFieldForType(string fieldName, string symbol, (object value,
345345

346346
Type elementType = declaredType.GetElementType();
347347

348+
if (fieldDefinition != null && (fieldDefinition.fieldSymbol.IsUserDefinedBehaviour() || fieldDefinition.fieldSymbol.userCsType == typeof(UdonBehaviour[])))
349+
{
350+
elementType = typeof(UdonBehaviour);
351+
}
352+
348353
for (int i = 0; i < valueArray.Length; ++i)
349354
{
350355
var elementData = (valueArray.GetValue(i), elementType);

Assets/UdonSharp/Editor/UdonSharpResolverContext.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,20 @@ public string GetUdonMethodName(MethodBase externMethod, bool validate = true, L
372372

373373
methodSourceType = RemapBaseType(methodSourceType);
374374

375+
bool isUdonSharpBehaviour = false;
376+
377+
if (methodSourceType == typeof(UdonSharpBehaviour) || methodSourceType.IsSubclassOf(typeof(UdonSharpBehaviour)))
378+
{
379+
methodSourceType = typeof(VRC.Udon.UdonBehaviour);
380+
isUdonSharpBehaviour = true;
381+
}
382+
375383
string functionNamespace = SanitizeTypeName(methodSourceType.FullName).Replace("VRCUdonUdonBehaviour", "VRCUdonCommonInterfacesIUdonEventReceiver");
376384

377385
string methodName = $"__{externMethod.Name.Trim('_').TrimStart('.')}";
378386
ParameterInfo[] methodParams = externMethod.GetParameters();
379387

380-
if ((functionNamespace == "UdonSharpUdonSharpBehaviour")
388+
if (isUdonSharpBehaviour
381389
&& methodName == "__VRCInstantiate")
382390
{
383391
functionNamespace = "VRCInstantiate";

Assets/UdonSharp/Editor/UdonSharpSymbolTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ private SymbolDefinition CreateNamedSymbolInternal(string symbolName, System.Typ
375375
}
376376

377377
System.Type typeForName = resolvedSymbolType;
378-
if (resolvedSymbolType.IsSubclassOf(typeof(UdonSharpBehaviour)))
378+
if (resolvedSymbolType == typeof(UdonSharpBehaviour) || resolvedSymbolType.IsSubclassOf(typeof(UdonSharpBehaviour)))
379379
typeForName = typeof(VRC.Udon.UdonBehaviour);
380380
else if (resolvedSymbolType.IsArray && (resolvedSymbolType.GetElementType() == typeof(UdonSharpBehaviour) || resolvedSymbolType.GetElementType().IsSubclassOf(typeof(UdonSharpBehaviour))))
381381
typeForName = typeof(Component[]); // Hack because VRC doesn't expose UdonBehaviour array type

0 commit comments

Comments
 (0)