在unity中加載打包中的dll內容:
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityEngine;
namespace VacuumShaders
{
public static class VacuumDLLUtility
{
public static Texture2D LoadTexture(string dll, string nameSpace, string resourceName, int width, int height)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Texture2D val = (Texture2D)(object)new Texture2D(width, height, (TextureFormat)5, false, true);
val.hideFlags = ((HideFlags)61);
Assembly assembly = Assembly.LoadFrom(dll);
if (assembly != null)
{
Stream manifestResourceStream = assembly.GetManifestResourceStream(nameSpace + "." + resourceName + ".png");
if (manifestResourceStream != null)
{
byte[] array = ReadToEnd(manifestResourceStream);
if (array != null && array.Length > 0)
{
ImageConversion.LoadImage(val, array);
}
}
}
return val;
}
public static string[] ReadFile(string dll, string resourceName)
{
List<string> list = new List<string>();
Assembly assembly = Assembly.LoadFrom(dll);
if (assembly != null)
{
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
using (StreamReader streamReader = new StreamReader(stream))
{
string item;
while ((item = streamReader.ReadLine()) != null)
{
list.Add(item);
}
}
}
}
return list.ToArray();
}
public static void DebugAllResources(string dll)
{
Assembly assembly = Assembly.LoadFrom(dll);
if (assembly != null)
{
string[] manifestResourceNames = assembly.GetManifestResourceNames();
foreach (string text in manifestResourceNames)
{
Debug.Log((object)text);
}
}
else
{
Debug.Log((object)("Assembel == null: " + dll));
}
}
private static byte[] ReadToEnd(Stream stream)
{
long position = stream.Position;
stream.Position = 0L;
try
{
byte[] array = new byte[4096];
int num = 0;
int num2;
while ((num2 = stream.Read(array, num, array.Length - num)) > 0)
{
num += num2;
if (num == array.Length)
{
int num3 = stream.ReadByte();
if (num3 != -1)
{
byte[] array2 = new byte[array.Length * 2];
Buffer.BlockCopy(array, 0, array2, 0, array.Length);
Buffer.SetByte(array2, num, (byte)num3);
array = array2;
num++;
}
}
}
byte[] array3 = array;
if (array.Length != num)
{
array3 = new byte[num];
Buffer.BlockCopy(array, 0, array3, 0, num);
}
return array3;
}
finally
{
stream.Position = position;
}
}
public static string[] LoadPluginInfo(string _dll)
{
string name = "GetVersion";
string name2 = "GetVersionStr";
string[] array = new string[2]
{
" ",
" "
};
Assembly assembly = Assembly.LoadFrom(_dll);
if (assembly != null)
{
Type type = assembly.GetTypes()[0];
MethodInfo method = type.GetMethod(name);
object obj = Activator.CreateInstance(type);
object obj2 = method.Invoke(obj, null);
MethodInfo method2 = type.GetMethod(name2);
object obj3 = Activator.CreateInstance(type);
object obj4 = method2.Invoke(obj3, null);
array[0] = obj2.ToString();
array[1] = obj4.ToString();
}
return array;
}
}
}