【问题标题】:How do I reference the ServiceStack library in a Unity C# script?如何在 Unity C# 脚本中引用 ServiceStack 库?
【发布时间】:2014-07-30 21:54:55
【问题描述】:

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

我已将 Build/Release/MonoDevelop/SericeStack.Redis.zip 中的 dll 复制到 unity 中的资产文件夹中,(对吗?)我刚刚通过克隆 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");
        }
    }
}

我可能只是没有正确引用库。我对编译语言还很陌生。

【问题讨论】:

    标签: unity3d servicestack


    【解决方案1】:

    我有一个类似的错误。但它没有任何自定义 dll。原因是我在代码中使用了Func。 Mono 不支持Func。我尝试下载 dll 的源代码,它们使用了很多 Func。所以这可能是您收到该错误的原因。

    【讨论】:

    • 不幸的是,我发现的单声道和统一不兼容的数量导致我放弃统一并在 python 中重新编写我的导出过程。
    【解决方案2】:

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

    菜单可以找到File -&gt; Build Settings -&gt; Player Settings -&gt; Optimization.

    【讨论】:

      猜你喜欢
      • 2020-07-27
      • 1970-01-01
      • 2022-01-23
      • 2023-01-27
      • 2019-10-19
      • 2017-05-27
      • 2022-06-28
      • 1970-01-01
      • 2023-02-03
      相关资源
      最近更新 更多