【发布时间】:2015-10-08 13:32:23
【问题描述】:
我有一个 dll 用于存储图像资源、字体资源等...
我在程序集中有一个类,它有一个返回方法,我希望能够从 dll 中提取资源并将它们作为 abject 返回,然后我可以将其转换为相应的类型。
这是我目前的代码。
public class GetResource
{
public static T LoadDllResource<T>(string ResourceFolder, string resourceName, string Extension, int width = 10, int height = 10)
{
Assembly myAssembly = Assembly.GetExecutingAssembly();
Stream myStream = myAssembly.GetManifestResourceStream(myAssembly.GetName().Name + "." + ResourceFolder + "." + resourceName + "." + Extension);
// convert stream to object by doing something like this (I'm not sure)
//return (T)Convert.ChangeType(EndResultOFStreamConversion, typeof(object));
}
}
并以这种方式使用它
Font SomeFont1= GetResource.LoadDllResource<Font>("Resources","Splash","ttf")
UnityEngine.Texture2D SomeImage2= GetResource.LoadDllResource<UnityEngine.Texture2D>("Resources","SnowImage","png")
如果问题有问题,请告诉我。感谢您的帮助!
我在 Unity 引擎中工作,它不能很好地支持使用 System.Drawing 的混合程序集
【问题讨论】: