From 159c131aab2757d96b3a04446c07ad92438c7ddb Mon Sep 17 00:00:00 2001 From: ureishi Date: Tue, 6 Dec 2022 09:33:47 +0900 Subject: [PATCH] Support call `Utilities.ShuffleArray()` --- .../Binder/Symbols/ExternMethodSymbol.cs | 7 +++++- .../Compiler/Udon/CompilerUdonInterface.cs | 6 ++--- .../TestScripts/Core/GenericsTest.asset | 2 +- .../Tests~/TestScripts/Core/GenericsTest.cs | 24 +++++++++++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Packages/com.vrchat.UdonSharp/Editor/Compiler/Binder/Symbols/ExternMethodSymbol.cs b/Packages/com.vrchat.UdonSharp/Editor/Compiler/Binder/Symbols/ExternMethodSymbol.cs index dabe5d9e..f540f6c1 100644 --- a/Packages/com.vrchat.UdonSharp/Editor/Compiler/Binder/Symbols/ExternMethodSymbol.cs +++ b/Packages/com.vrchat.UdonSharp/Editor/Compiler/Binder/Symbols/ExternMethodSymbol.cs @@ -10,7 +10,12 @@ public ExternMethodSymbol(IMethodSymbol sourceSymbol, AbstractPhaseContext conte : base(sourceSymbol, context) { if (sourceSymbol != null) - ExternSignature = CompilerUdonInterface.GetUdonMethodName(this, context); + { + if (OriginalSymbol is ExternMethodSymbol originalMethodSymbol) + ExternSignature = CompilerUdonInterface.GetUdonMethodName(originalMethodSymbol, context); + else + ExternSignature = CompilerUdonInterface.GetUdonMethodName(this, context); + } } public override bool IsExtern => true; diff --git a/Packages/com.vrchat.UdonSharp/Editor/Compiler/Udon/CompilerUdonInterface.cs b/Packages/com.vrchat.UdonSharp/Editor/Compiler/Udon/CompilerUdonInterface.cs index a98f8392..c6b72733 100644 --- a/Packages/com.vrchat.UdonSharp/Editor/Compiler/Udon/CompilerUdonInterface.cs +++ b/Packages/com.vrchat.UdonSharp/Editor/Compiler/Udon/CompilerUdonInterface.cs @@ -281,8 +281,8 @@ public static string GetUdonEventName(string eventName) public static string GetUdonTypeName(TypeSymbol externSymbol) { if (externSymbol is TypeParameterSymbol) - return "T"; - + return SanitizeTypeName(externSymbol.IsArray ? "T[]" : "T"); + return GetUdonTypeName(externSymbol.UdonType.SystemType); } @@ -348,7 +348,7 @@ internal static string GetUdonMethodName(ExternMethodSymbol methodSymbol, Abstra foreach (IParameterSymbol parameter in parameters) { - paramStr += $"_{GetUdonTypeName(context.GetTypeSymbol(parameter.Type))}"; + paramStr += $"_{GetUdonTypeName(context.GetTypeSymbolWithoutRedirect(parameter.Type))}"; if (parameter.RefKind != RefKind.None) paramStr += "Ref"; } diff --git a/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/GenericsTest.asset b/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/GenericsTest.asset index 0d4906ac..975cb561 100644 --- a/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/GenericsTest.asset +++ b/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/GenericsTest.asset @@ -12,7 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3} m_Name: GenericsTest m_EditorClassIdentifier: - serializedUdonProgramAsset: {fileID: 11400000, guid: 3a6f059baa1b7af43966bc39afc1b73f, + serializedUdonProgramAsset: {fileID: 11400000, guid: 24a3704bc2443a041abc75adb3025726, type: 2} udonAssembly: assemblyError: diff --git a/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/GenericsTest.cs b/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/GenericsTest.cs index b26a087b..261735aa 100644 --- a/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/GenericsTest.cs +++ b/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/GenericsTest.cs @@ -32,6 +32,30 @@ public void ExecuteTests() tester.TestAssertion("Generic variant 3", objects.Length == 3 && objects[0] == gameObject && objects[1] == transform && objects[2] == this); + + CallUdonGenericMethod(); + } + + void CallUdonGenericMethod() + { + //float[] floatArray; + int[] intArray; + UnityEngine.Object[] unityEngineObjectArray; + + //floatArray = new float[] { 1f, 2f }; + //while (floatArray[0] == 1f) + // VRC.SDKBase.Utilities.ShuffleArray(floatArray); + //tester.TestAssertion("Call Udon generic method 1", floatArray[0] == 2f); + + intArray = new int[] { 1, 2 }; + while (intArray[0] == 1) + VRC.SDKBase.Utilities.ShuffleArray(intArray); + tester.TestAssertion("Call Udon generic method 2", intArray[0] == 2); + + unityEngineObjectArray = new UnityEngine.Object[] { gameObject, transform }; + while (unityEngineObjectArray[0].Equals(gameObject)) + VRC.SDKBase.Utilities.ShuffleArray(unityEngineObjectArray); + tester.TestAssertion("Call Udon generic method 3", unityEngineObjectArray[0].Equals(transform)); } }