Added Unity project files

This commit is contained in:
2026-06-07 16:58:24 +01:00
parent 3cc05d260b
commit 23bbcab156
3942 changed files with 453676 additions and 0 deletions

View File

@ -0,0 +1,119 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: ForLoopTest
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 71d377cf9607fc242830ba920de0baf8,
type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: 140041db77df18744b2318b4f5869ad7, type: 3}
scriptVersion: 2
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: -5310835517953851657
serializationData:
SerializedFormat: 2
SerializedBytes:
ReferencedUnityObjects: []
SerializedBytesString:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes:
- Name: fieldDefinitions
Entry: 7
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition,
UdonSharp.Editor]], mscorlib
- Name: comparer
Entry: 7
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String,
mscorlib]], mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: tester
- Name: $v
Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: tester
- Name: <UserType>k__BackingField
Entry: 7
Data: 3|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UdonSharp.Tests.IntegrationTestSuite, UdonSharp.Tests
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 4|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.Udon.UdonBehaviour, VRC.Udon
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 6|System.NonSerializedAttribute, mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: db172992aa06e97408acfca51fce41ce
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,70 @@
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
namespace UdonSharp.Tests
{
[AddComponentMenu("Udon Sharp/Tests/ForLoopTest")]
public class ForLoopTest : UdonSharpBehaviour
{
[System.NonSerialized]
public IntegrationTestSuite tester;
public void ExecuteTests()
{
int counter = 0;
for (int i = 0; i < 10; ++i)
counter++;
tester.TestAssertion("Basic for loop", counter == 10);
int[] ints = new[] { 1, 2, 3, 4, 5 };
counter = 0;
foreach (var val in ints)
{
counter += val;
}
tester.TestAssertion("Foreach loop", counter == 15);
counter = 0;
foreach (var child in transform)
{
++counter;
}
foreach (Transform child in transform)
{
++counter;
}
tester.TestAssertion("Foreach child Transform loop", counter == 6);
string helloStr = "hello!";
string builtStr = "";
foreach (char strChar in helloStr)
{
builtStr += strChar;
}
tester.TestAssertion("Foreach string loop", builtStr == helloStr);
GameObject[] gameObjects = new GameObject[2000];
int gameObjectLen = gameObjects.Length;
System.DateTime startTime = System.DateTime.UtcNow;
for (int i = 0; i < gameObjectLen; ++i)
{
gameObjects[i] = gameObject;
}
tester.TestAssertion("Array indexer performance", (System.DateTime.UtcNow - startTime).TotalSeconds < 1f);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 140041db77df18744b2318b4f5869ad7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,269 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: RecursionTest
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 6842528ddd61e8b43923eb462ec1d68d,
type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: 41aa655b07e37a84292568dd0dc1aac5, type: 3}
scriptVersion: 2
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: -443843821985656606
serializationData:
SerializedFormat: 2
SerializedBytes:
ReferencedUnityObjects: []
SerializedBytesString:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes:
- Name: fieldDefinitions
Entry: 7
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition,
UdonSharp.Editor]], mscorlib
- Name: comparer
Entry: 7
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String,
mscorlib]], mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 12
Data: 4
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: tester
- Name: $v
Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: tester
- Name: <UserType>k__BackingField
Entry: 7
Data: 3|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UdonSharp.Tests.IntegrationTestSuite, UdonSharp.Tests
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 4|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.Udon.UdonBehaviour, VRC.Udon
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 6|System.NonSerializedAttribute, mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: externChildCount
- Name: $v
Entry: 7
Data: 7|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: externChildCount
- Name: <UserType>k__BackingField
Entry: 7
Data: 8|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 8
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 9|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: customEventCounter
- Name: $v
Entry: 7
Data: 10|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: customEventCounter
- Name: <UserType>k__BackingField
Entry: 9
Data: 8
- Name: <SystemType>k__BackingField
Entry: 9
Data: 8
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 11|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: memory
- Name: $v
Entry: 7
Data: 12|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: memory
- Name: <UserType>k__BackingField
Entry: 9
Data: 8
- Name: <SystemType>k__BackingField
Entry: 9
Data: 8
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 13|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 48df62f63db4c32438044816f153d3f3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,363 @@

using System;
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using Random = UnityEngine.Random;
namespace UdonSharp.Tests
{
[AddComponentMenu("Udon Sharp/Tests/RecursionTest")]
public class RecursionTest : UdonSharpBehaviour
{
[System.NonSerialized]
public IntegrationTestSuite tester;
[RecursiveMethod]
int Factorial(int input)
{
if (input == 1)
return 1;
return input * Factorial(input - 1);
}
private static int Partition<T>(T[] arr, int left, int right) where T : IComparable
{
T pivot = arr[left];
while (true)
{
while (arr[left].CompareTo(pivot) < 0)
{
left++;
}
while (arr[right].CompareTo(pivot) > 0)
{
right--;
}
if (left < right)
{
T temp = arr[right];
arr[right] = arr[left];
arr[left] = temp;
}
else
{
return right;
}
}
}
// Copy paste from https://www.tutorialspoint.com/chash-program-to-perform-quick-sort-using-recursion
[RecursiveMethod]
private void QuickSort(int[] arr, int left, int right)
{
int pivot;
if (left < right)
{
pivot = Partition(arr, left, right);
if (pivot > 1)
QuickSort(arr, left, pivot - 1);
if (pivot + 1 < right)
QuickSort(arr, pivot + 1, right);
}
arr = null; // Just throw a curveball with something that should be handled, but could break stuff if it isn't handled
}
[RecursiveMethod]
private static void QuickSortStatic<T>(T[] arr, int left, int right) where T : IComparable
{
int pivot;
if (left < right)
{
pivot = Partition(arr, left, right);
if (pivot > 1)
QuickSortStatic(arr, left, pivot - 1);
if (pivot + 1 < right)
QuickSortStatic(arr, pivot + 1, right);
}
arr = null; // Just throw a curveball with something that should be handled, but could break stuff if it isn't handled
}
// https://www.geeksforgeeks.org/iterative-quick-sort/
// Just a test for relative performance of using recursive vs iterative
//void QuickSortIterative(int[] arr, int l, int h)
//{
// int[] stack = new int[h - l + 1];
// int top = -1;
// stack[++top] = l;
// stack[++top] = h;
// while (top >= 0)
// {
// h = stack[top--];
// l = stack[top--];
// int p = Partition(arr, l, h);
// if (p - 1 > l)
// {
// stack[++top] = l;
// stack[++top] = p - 1;
// }
// if (p + 1 < h)
// {
// stack[++top] = p + 1;
// stack[++top] = h;
// }
// }
//}
int[] InitTestArray(int size)
{
int[] testArray = new int[size];
for (int i = 0; i < testArray.Length; ++i)
testArray[i] = i;
return testArray;
}
void ShuffleArray(int[] shuffleArray)
{
Random.InitState(1337);
int n = shuffleArray.Length - 1;
for (int i = 0; i < n; ++i)
{
int r = Random.Range(i + 1, n);
int flipVal = shuffleArray[r];
shuffleArray[r] = shuffleArray[i];
shuffleArray[i] = flipVal;
}
}
bool IsSorted(int[] array)
{
for (int i = 0; i < array.Length; ++i)
{
if (array[i] != i)
{
return false;
}
}
return true;
}
[RecursiveMethod]
public string CombineStrings(int count, string a, string b)
{
if (count == 0)
return "";
return string.Concat(a, CombineStrings(count - 1, b, a), CombineStrings(count - 1, a, b));
}
[RecursiveMethod]
public string CombineStringsExtern(int count, string a, string b)
{
if (count == 0)
return "";
RecursionTest self = this;
//Debug.Log($"count: {count}, a: {a}, b: {b}"/*, a result: {aResult}, b result: {bResult}"*/);
return string.Concat(a, self.CombineStringsExtern(count - 1, b, a), self.CombineStringsExtern(count - 1, a, b));
}
[RecursiveMethod]
public string CombineStringsParams(int count, string a, string b, string c, string d, string e)
{
if (count == 0)
return "";
return string.Concat(a, CombineStringsParams(count - 1, e, d, c, b, a), CombineStringsParams(count - 1, a, b, c, d, e), CombineStringsParams(count - 1, a, a, c, d, e), CombineStringsParams(count - 1, a, b, b, e, e), CombineStringsParams(count - 1, a, b, a, d, e));
}
[RecursiveMethod]
public string CombineStringsNested(int count, string a, string b)
{
if (count == 0)
return "";
return string.Concat(a, CombineStringsNested(count - 1, CombineStringsNested(count - 1, b, a), CombineStringsNested(count - 1, a, b)), CombineStringsNested(count - 1, CombineStringsNested(count - 1, a, b), CombineStringsNested(count - 1, b, a)), "c");
}
Transform[] GetChildrenTransforms(Transform parent)
{
Transform[] children = new Transform[parent.childCount];
for (int i = 0; i < children.Length; ++i)
{
children[i] = parent.GetChild(i);
}
return children;
}
[RecursiveMethod]
int CountChildren(Transform transformToCount)
{
int childCount = transformToCount.childCount;
foreach (Transform child in transformToCount)
childCount += CountChildren(child);
return childCount;
}
[RecursiveMethod]
int CountChildrenForeachExpression(Transform transformToCount)
{
int childCount = transformToCount.childCount;
foreach (Transform child in GetChildrenTransforms(transformToCount))
childCount += CountChildrenForeachExpression(child);
return childCount;
}
[RecursiveMethod]
int CountChildrenForeachAccessExpression(Transform transformToCount)
{
int childCount = transformToCount.childCount;
foreach (Transform child in transformToCount.gameObject.transform)
childCount += CountChildrenForeachAccessExpression(child);
return childCount;
}
int externChildCount;
[RecursiveMethod]
void CountChildrenExternalCount(Transform transformToCount)
{
externChildCount += transformToCount.childCount;
foreach (Transform child in transformToCount)
CountChildrenExternalCount(child);
}
int customEventCounter = 4;
[RecursiveMethod]
public void CustomEventExternRecursion()
{
int originalCounter = customEventCounter;
RecursionTest self = this;
if (customEventCounter == 1)
return;
customEventCounter -= 1;
self.SendCustomEvent(nameof(CustomEventExternRecursion));
customEventCounter = originalCounter * customEventCounter;
}
[RecursiveMethod]
public void CustomEventRecursion()
{
int originalCounter = customEventCounter;
if (customEventCounter == 1)
return;
customEventCounter -= 1;
SendCustomEvent(nameof(CustomEventRecursion));
customEventCounter = originalCounter * customEventCounter;
}
/// <summary>
/// Tests if the temp value from the lhs of the short circuit gets stomped by the recursive call which causes the final expression to evaluate an inaccurate value
/// </summary>
[RecursiveMethod]
bool ShortCircuitRecursion(bool a, int count, bool useValue)
{
if (count == 0)
a = false;
bool result = a == false || !ShortCircuitRecursion(a, count - 1, false);
if (useValue)
return result;
return true;
}
private int memory;
[RecursiveMethod]
private int Sum() => memory == 0 ? 0 : memory-- + Sum();
[RecursiveMethod] // Just here to test calling out to other types from recursive methods
public void ExecuteTests()
{
tester.TestAssertion("Basic recursion 4!", Factorial(4) == 24);
tester.TestAssertion("Basic recursion 5!", Factorial(5) == 120);
tester.TestAssertion("Basic recursion 12!", Factorial(12) == 479001600);
int arraySize = Random.Range(10000, 11000);
int[] shuffleArray = InitTestArray(arraySize); // Fuzz a little
ShuffleArray(shuffleArray);
QuickSortStatic(shuffleArray, 0, shuffleArray.Length - 1);
bool sorted = IsSorted(shuffleArray);
if (!sorted)
Debug.LogWarning($"Array size that failed {arraySize}");
tester.TestAssertion("Quicksort recursion", sorted);
RecursionTest self = this;
ShuffleArray(shuffleArray);
self.QuickSort(shuffleArray, 0, shuffleArray.Length - 1);
tester.TestAssertion("Quicksort external call", IsSorted(shuffleArray));
tester.TestAssertion("Function parameter swap recursion", CombineStrings(6, "a", "b") == "abababababababababababababababababababababababababababababababa");
tester.TestAssertion("Function parameter swap recursion external call", self.CombineStringsExtern(6, "a", "b") == "abababababababababababababababababababababababababababababababa");
tester.TestAssertion("Params array recursion", CombineStringsParams(4, "a", "b", "c", "d", "e") == "aeaeaaaaeaeeeeeaeeeeeaeeeeeaeeeeaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaaaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaaaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaaaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaa");
tester.TestAssertion("Nested call recursion", CombineStringsNested(3, "a", "b") == "abaccbcccabccacccccbaccbccccccabccacccbaccbcccccabccaccccccc");
tester.TestAssertion("Count children recursively foreach", CountChildren(transform) == 20);
tester.TestAssertion("Count children recursively foreach expression", CountChildrenForeachExpression(transform) == 20);
tester.TestAssertion("Count children recursively foreach access", CountChildrenForeachAccessExpression(transform) == 20);
externChildCount = 0;
CountChildrenExternalCount(transform);
tester.TestAssertion("Count children recursively foreach external counter", externChildCount == 20);
customEventCounter = 4;
CustomEventExternRecursion();
tester.TestAssertion("SendCustomEvent extern recursion", customEventCounter == 24);
customEventCounter = 4;
CustomEventRecursion();
tester.TestAssertion("SendCustomEvent recursion", customEventCounter == 24);
tester.TestAssertion("Recursive short circuit operators", ShortCircuitRecursion(true, 2, true) == false);
memory = 10;
tester.TestAssertion("Postfix recursion", Sum() == 55);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 41aa655b07e37a84292568dd0dc1aac5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,119 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: SwitchTest
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 19c9444d30177414b90609b0fb25318d,
type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: 8f0162689102f3e49a3e668a1abb9a5d, type: 3}
scriptVersion: 2
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: 7603822365777958732
serializationData:
SerializedFormat: 2
SerializedBytes:
ReferencedUnityObjects: []
SerializedBytesString:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes:
- Name: fieldDefinitions
Entry: 7
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition,
UdonSharp.Editor]], mscorlib
- Name: comparer
Entry: 7
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String,
mscorlib]], mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: tester
- Name: $v
Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: tester
- Name: <UserType>k__BackingField
Entry: 7
Data: 3|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UdonSharp.Tests.IntegrationTestSuite, UdonSharp.Tests
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 4|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.Udon.UdonBehaviour, VRC.Udon
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 6|System.NonSerializedAttribute, mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a38ac6ceca99138488177bcaa4d3cbbe
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,264 @@

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
#pragma warning disable 162
namespace UdonSharp.Tests
{
enum MySwitchEnum
{
A,
B,
C,
D,
E = 10000000,
F = 20,
G,
}
[AddComponentMenu("Udon Sharp/Tests/SwitchTest")]
public class SwitchTest : UdonSharpBehaviour
{
[System.NonSerialized]
public IntegrationTestSuite tester;
public void ExecuteTests()
{
tester.TestAssertion("Switch 1", TestSwitch(1) == "one");
tester.TestAssertion("Switch 2", TestSwitch(2) == "two or three");
tester.TestAssertion("Switch 3", TestSwitch(3) == "two or three");
tester.TestAssertion("Switch 4", TestSwitch(4) == "default");
tester.TestAssertion("Switch 5", TestSwitch(5) == "it's five");
tester.TestAssertion("Switch 6", TestSwitch(20) == "twenty");
tester.TestAssertion("Switch 7", TestSwitch(100000000) == "no jump table");
tester.TestAssertion("User enum switch 1", TestUserEnumSwitch(MySwitchEnum.A) == "A");
tester.TestAssertion("User enum switch 2", TestUserEnumSwitch(MySwitchEnum.B) == "B");
tester.TestAssertion("User enum switch 3", TestUserEnumSwitch(MySwitchEnum.C) == "C");
tester.TestAssertion("User enum switch 4", TestUserEnumSwitch(MySwitchEnum.D) == "C");
tester.TestAssertion("User enum switch 5", TestUserEnumSwitch(MySwitchEnum.E) == "E");
tester.TestAssertion("Extern enum switch 1", ExternEnumSwitch(CameraClearFlags.Skybox) == "Skybox");
tester.TestAssertion("Extern enum switch 2", ExternEnumSwitch(CameraClearFlags.Color) == "Color");
tester.TestAssertion("Extern enum switch 3", ExternEnumSwitch(CameraClearFlags.Depth) == "Default enum handling Depth");
tester.TestAssertion("String switch 1", StringSwitch("testVal") == "the testVal");
tester.TestAssertion("String switch 2", StringSwitch("testVal2") == "the testVal2");
tester.TestAssertion("String switch 3", StringSwitch("aaaaa") == "no switch val found");
tester.TestAssertion("String switch 4", StringSwitch(null) == "null str");
tester.TestAssertion("Float switch 1", FloatSwitch(1) == "one");
tester.TestAssertion("Float switch 2", FloatSwitch(2) == "two");
tester.TestAssertion("Float switch 3", FloatSwitch(1.2f) == "no switch val found");
tester.TestAssertion("User enum jump table switch 1", TestUserJumpTableEnumSwitch(MySwitchEnum.A) == "A");
tester.TestAssertion("User enum jump table switch 2", TestUserJumpTableEnumSwitch(MySwitchEnum.B) == "B");
tester.TestAssertion("User enum jump table switch 3", TestUserJumpTableEnumSwitch(MySwitchEnum.C) == "C");
tester.TestAssertion("User enum jump table switch 4", TestUserJumpTableEnumSwitch(MySwitchEnum.D) == "C");
tester.TestAssertion("User enum jump table switch 5", TestUserJumpTableEnumSwitch(MySwitchEnum.E) == "C");
tester.TestAssertion("User enum jump table switch 6", TestUserJumpTableEnumSwitch(MySwitchEnum.F) == "f");
tester.TestAssertion("User enum jump table switch 7", TestUserJumpTableEnumSwitch(MySwitchEnum.G) == "C");
tester.TestAssertion("Object switch 1", ObjectSwitch(null) == "no switch val found");
tester.TestAssertion("Object switch 2", ObjectSwitch(2) == "two");
tester.TestAssertion("Object switch 3", ObjectSwitch(2L) == "two long");
tester.TestAssertion("Object switch 4", ObjectSwitch("testVal") == "the testVal");
// todo: handle null case on object switches
// tester.TestAssertion("Object switch 5", ObjectSwitchWithNull(null) == "null");
// tester.TestAssertion("Object switch 6", ObjectSwitchWithNull(1) == "default");
tester.TestAssertion("Const variable switch 1", ConstVariableSwitch(1) == "one");
tester.TestAssertion("Const variable switch 2", ConstVariableSwitch(2) == "two");
tester.TestAssertion("Const variable switch 3", ConstVariableSwitch(3) == "no switch val found");
tester.TestAssertion("Default case regression 1", TestDefaultCaseRegression(1) == 1);
tester.TestAssertion("Default case regression 2", TestDefaultCaseRegression(2) == 2);
tester.TestAssertion("Default case regression 3", TestDefaultCaseRegression(3) == -1);
tester.TestAssertion("Default case fallthrough 1", TestDefaultCaseFallThrough(3) == -1);
tester.TestAssertion("Default case fallthrough 2", TestDefaultCaseFallThrough(4) == -1);
tester.TestAssertion("Default case fallthrough 3", TestDefaultCaseFallThrough(1) == 1);
tester.TestAssertion("Default case fallthrough 4", TestDefaultCaseFallThrough(2) == 2);
}
private string TestSwitch(int switchVal)
{
switch (switchVal)
{
case 1:
return "one";
case 2:
case 3:
return "two or three";
case 5:
break;
default:
return "default";
case 20:
return "twenty";
case 100000000:
return "no jump table";
}
return "it's five";
}
private string TestUserEnumSwitch(MySwitchEnum mySwitchEnum)
{
switch (mySwitchEnum)
{
case MySwitchEnum.A:
return "A";
case MySwitchEnum.B:
return "B";
default:
case MySwitchEnum.C:
return "C";
case MySwitchEnum.E:
return "E";
}
return "This should not be hit";
}
private string TestUserJumpTableEnumSwitch(MySwitchEnum mySwitchEnum)
{
switch (mySwitchEnum)
{
case MySwitchEnum.A:
return "A";
case MySwitchEnum.B:
return "B";
default:
case MySwitchEnum.C:
return "C";
case MySwitchEnum.F:
return "f";
}
return "This should not be hit";
}
private string ExternEnumSwitch(CameraClearFlags clearFlags)
{
switch (clearFlags)
{
case CameraClearFlags.Color:
return "Color";
case CameraClearFlags.Skybox:
return "Skybox";
default:
return $"Default enum handling {clearFlags}";
}
}
private string StringSwitch(string val)
{
switch (val)
{
case "testVal":
return "the testVal";
case "testVal" + "2":
return "the testVal2";
case null:
return "null str";
}
return "no switch val found";
}
private string ObjectSwitch(object val)
{
switch (val)
{
case "testVal":
return "the testVal";
case 2:
return "two";
case 2L:
return "two long";
}
return "no switch val found";
}
private string ObjectSwitchWithNull(object val)
{
switch (val)
{
case null:
return "null";
case "testVal":
return "the testVal";
case 2:
return "two";
case 2L:
return "two long";
default:
return "default";
}
return "no switch val found";
}
private string FloatSwitch(float val)
{
switch (val)
{
case 1:
return "one";
case 2f:
return "two";
}
return "no switch val found";
}
const int one = 1;
private string ConstVariableSwitch(int val)
{
const int two = 2;
switch (val)
{
case one:
return "one";
case two:
return "two";
}
return "no switch val found";
}
// https://github.com/vrchat-community/UdonSharp/issues/26
private int TestDefaultCaseRegression(int val)
{
switch (val)
{
default:
return -1;
case 1:
return 1;
case 2:
return 2;
}
}
private int TestDefaultCaseFallThrough(int val)
{
switch (val)
{
case 4:
default:
case 3:
return -1;
case 1:
return 1;
case 2:
return 2;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8f0162689102f3e49a3e668a1abb9a5d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: