From 7de061b5595c3b849c3e010ed7c7deed9ce7a1ff Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 30 Jun 2023 19:20:16 +0800 Subject: *misc --- .../Assets/Scripts/Common/CommonFunction.cs | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'WorldlineKeepers/Assets/Scripts/Common/CommonFunction.cs') diff --git a/WorldlineKeepers/Assets/Scripts/Common/CommonFunction.cs b/WorldlineKeepers/Assets/Scripts/Common/CommonFunction.cs index ae5a132..b4de592 100644 --- a/WorldlineKeepers/Assets/Scripts/Common/CommonFunction.cs +++ b/WorldlineKeepers/Assets/Scripts/Common/CommonFunction.cs @@ -1,7 +1,11 @@ +using System; +using System.Reflection; +using System.Reflection.Emit; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; +using System.Linq; public static class CommonFunction { @@ -22,4 +26,27 @@ public static class CommonFunction File.WriteAllText(file, content); } + public static Type GetTypeByName(string name) + { + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Reverse()) + { + var tt = assembly.GetType(name); + if (tt != null) + { + return tt; + } + } + + return null; + } + + public static System.Object CreateInstance(string typeName) + { + Type t = GetTypeByName(typeName); + if (t == null) + return null; + var obj = Activator.CreateInstance(t); + return obj; + } + } -- cgit v1.1-26-g67d0