This commit is contained in:
CortexCore
2025-07-11 11:45:45 +08:00
parent fc189b98cc
commit ecae0f809c
76 changed files with 237471 additions and 33136 deletions

View File

@@ -12,6 +12,7 @@ using System.Threading.Tasks;
using BITKit.Mod;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
#if UNITY_5_3_OR_NEWER
using System.Collections;
using UnityEngine;
@@ -22,6 +23,40 @@ namespace BITKit
{
public static class BITSharp
{
public static Type[] GetAllBaseType(Type type)
{
try
{
switch (type)
{
case null:
case not null when type == typeof(object):
#if UNITY_5_3_OR_NEWER
case not null when type == typeof(UnityEngine.Object):
case not null when type == typeof(MonoBehaviour):
case not null when type == typeof(Behaviour):
case not null when type == typeof(Component):
case not null when type == typeof(Component):
#endif
throw new OperationCanceledException();
}
}
catch (OperationCanceledException)
{
return Array.Empty<Type>();
}
var hashSet = new HashSet<Type> { type };
foreach (var x in GetAllBaseType(type.BaseType))
{
hashSet.Add(x);
}
return hashSet.ToArray();
}
public static ICodeGenerator SharedCodeGenerator = new CodeGenerator();
public interface ICodeGenerator
{
@@ -302,7 +337,7 @@ namespace BITKit
public static string CSharpName(this Type type)
{
var sb = new StringBuilder();
var name = type.Name;
var name = type.FullName!.Replace("+",".");
if (!type.IsGenericType) return name;
sb.Append(name.Substring(0, name.IndexOf('`')));
sb.Append("<");
@@ -322,8 +357,15 @@ namespace BITKit
using var ms = new MemoryStream();
var result = script.GetCompilation().Emit(ms);
//ClipboardService.SetText(code);
#if UNITY_5_3_OR_NEWER
UnityEngine.GUIUtility.systemCopyBuffer = code;
#endif
if (!result.Success)
{
var report = new StringBuilder();
report.AppendLine(code);