using System.Collections; using System.Collections.Generic; using UnityExplorer.UI; using UnityEngine; using System; using System.Runtime.InteropServices; using System.Text; using UnityExplorer.Unstrip; #if CPP using UnhollowerBaseLib; using UnityExplorer.Helpers; #endif namespace UnityExplorer.Tests { internal enum TestByteEnum : byte { One, Two, Three, TwoFiftyFive = 255, } public static class StaticTestClass { public static int StaticProperty => 5; public static int StaticField = 69; public static List StaticList = new List { "one", "two", "three", }; public static void StaticMethod() { } } public class TestClass { internal static TestByteEnum testingByte = TestByteEnum.One; public string AAALongString = @"1 2 3 4 5"; public Vector2 AATestVector2 = new Vector2(1, 2); public Vector3 AATestVector3 = new Vector3(1, 2, 3); public Vector4 AATestVector4 = new Vector4(1, 2, 3, 4); public Rect AATestRect = new Rect(1, 2, 3, 4); public Color AATestColor = new Color(0.1f, 0.2f, 0.3f, 0.4f); public bool ATestBoolMethod() => false; public bool this[int index] { get => index % 2 == 0; set => m_thisBool = value; } internal bool m_thisBool; static int testInt; public static List ExceptionList { get { testInt++; if (testInt % 2 == 0) throw new Exception("its even"); else return new List { "one" }; } } static bool abool; public static bool ATestExceptionBool { get { abool = !abool; if (!abool) throw new Exception("false"); else return true; } } public static string ExceptionString => throw new NotImplementedException(); public static string ANullString = null; public static float ATestFloat = 420.69f; public static int ATestInt = -1; public static string ATestString = "hello world"; public static uint ATestUInt = 1u; public static byte ATestByte = 255; public static ulong AReadonlyUlong = 82934UL; public static TestClass Instance => m_instance ?? (m_instance = new TestClass()); private static TestClass m_instance; public object AmbigObject; public List>> ANestedNestedList = new List>> { new List> { new List { "one", "two", }, new List { "three", "four" } }, new List> { new List { "five", "six" } } }; public static bool SetOnlyProperty { set => m_setOnlyProperty = value; } private static bool m_setOnlyProperty; public static bool ReadSetOnlyProperty => m_setOnlyProperty; public Texture2D TestTexture; public static Sprite TestSprite; #if CPP public static Il2CppSystem.Collections.Generic.HashSet CppHashSetTest; public static Il2CppSystem.Collections.Generic.List CppStringTest; public static Il2CppSystem.Collections.IList CppIList; //public static Il2CppSystem.Collections.Generic.Dictionary CppDictTest; //public static Il2CppSystem.Collections.Generic.Dictionary CppDictTest2; #endif public TestClass() { int a = 0; foreach (var list in ANestedNestedList) { foreach (var list2 in list) { for (int i = 0; i < 33; i++) list2.Add(a++.ToString()); } } #if CPP TextureSpriteTest(); CppHashSetTest = new Il2CppSystem.Collections.Generic.HashSet(); CppHashSetTest.Add("1"); CppHashSetTest.Add("2"); CppHashSetTest.Add("3"); CppStringTest = new Il2CppSystem.Collections.Generic.List(); CppStringTest.Add("1"); CppStringTest.Add("2"); //CppDictTest = new Il2CppSystem.Collections.Generic.Dictionary(); //CppDictTest.Add("key1", "value1"); //CppDictTest.Add("key2", "value2"); //CppDictTest.Add("key3", "value3"); //CppDictTest2 = new Il2CppSystem.Collections.Generic.Dictionary(); //CppDictTest2.Add(0, 0.5f); //CppDictTest2.Add(1, 0.5f); //CppDictTest2.Add(2, 0.5f); #endif } private void TextureSpriteTest() { TestTexture = new Texture2D(32, 32, TextureFormat.ARGB32, false) { name = "TestTexture" }; TestSprite = ImageConversionUnstrip.CreateSprite(TestTexture); GameObject.DontDestroyOnLoad(TestTexture); GameObject.DontDestroyOnLoad(TestSprite); // test loading a tex from file if (System.IO.File.Exists(@"D:\Downloads\test.png")) { var dataToLoad = System.IO.File.ReadAllBytes(@"D:\Downloads\test.png"); ExplorerCore.Log($"Tex load success: {TestTexture.LoadImage(dataToLoad, false)}"); } } public static string TestRefInOutGeneric(ref string arg0, in int arg1, out string arg2) where T : Component { arg2 = "this is arg2"; return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'"; } // test a non-generic dictionary public Hashtable TestNonGenericDict() { return new Hashtable { { "One", 1 }, { "Two", 2 }, { "Three", 3 }, }; } // test HashSets public static HashSet HashSetTest = new HashSet { "One", "Two", "Three" }; // Test indexed parameter public string this[int arg0, string arg1] { get { return $"arg0: {arg0}, arg1: {arg1}"; } } // Test basic list public static List TestList = new List { "1", "2", "3", "etc..." }; // Test a nested dictionary public static Dictionary> NestedDictionary = new Dictionary> { { 1, new Dictionary { { "Sub 1", 123 }, { "Sub 2", 456 }, } }, { 2, new Dictionary { { "Sub 3", 789 }, { "Sub 4", 000 }, } }, }; // Test a basic method public static Color TestMethod(float r, float g, float b, float a) { return new Color(r, g, b, a); } // A method with default arguments public static Vector3 TestDefaultArgs(float arg0, float arg1, float arg2 = 5.0f) { return new Vector3(arg0, arg1, arg2); } } }