首页 文章

如何在Unity C#脚本中引用ServiceStack库?

提问于
浏览
5

我必须制作一个Unity脚本来导入和导出一些3D模型 . 我正在尝试从我的脚本中引用Servicestack.Redis,以便我可以与redis交谈 . 它编译得很好,但统一不会加载库 .

我是从Build / Release / MonoDevelop / SericeStack.Redis.zip到我的资产文件夹中的统一,(这是正确的吗?)我刚刚通过克隆https://github.com/ServiceStack/ServiceStack.Redis得到了ServiceStack

当Unity试图加载脚本时,它说

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0

到目前为止我的代码是这样的 . 这是一个编辑器脚本 . 它只是创建一个带有按钮的窗口,当单击该按钮时,它会尝试连接到localhost上的redis并获取密钥

using UnityEngine;
using UnityEditor;
using System.Collections;
using ServiceStack.Redis;

public class MyWindow : EditorWindow
{

    // Add menu item named "My Window" to the Window menu
    [MenuItem("Window/My Window")]
    public static void ShowWindow()
    {
        //Show existing window instance. If one doesn't exist, make one.
        EditorWindow.GetWindow(typeof(MyWindow));
    }

    void OnGUI()
    {
        if (GUILayout.Button("Press to Rotate"))
        {
            ProcessAsset();
        }
    }

    void ProcessAsset()
    {
        using (var client = new RedisClient("localhost"))
        {
            client.Get ("hello");
        }
    }
}

我可能只是没有正确引用库 . 我是编译语言的新手 .

2 回答

  • 1

    我有一个类似的错误 . 但它没有任何自定义dll . 原因是因为我在代码中使用了Func . 单声道不支持Func . 我试着下载dll的源代码,他们使用了很多Func . 所以这可能是你得到这个错误的原因 .

  • 1

    我知道这有点旧,但它出现在我的搜索结果中 . 因此,对于遇到此问题的其他人,请确保将Unity项目设置设置为 .Net 2.0 而不是 .Net 2.0 Subset .

    菜单可以找到 File -> Build Settings -> Player Settings -> Optimization.

相关问题