visual-studio - 如何将 ZeroMQ 导入 Unity 引擎?
问题描述
我正在尝试为 Unity 中的项目导入 ZeroMQ 库。我正在使用C#
Visual Studio 进行编辑。我使用 NuGet 将 ZeroMQ 导入 Visual Studio,但是当我尝试运行游戏时出现错误
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'ZeroMQ' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\<me>\OneDrive\Documents\UrBalls\Assets\Scripts\PlayerController.cs 4 Active
控制器文件来自教程:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ZeroMQ;
public class PlayerController : MonoBehaviour
{
public float speed;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
System.Console.WriteLine("Hey");
rb.AddForce(movement * speed);
}
// Update is called once per frame
void Update()
{
}
}
如何让编译器看到包?赞赏!
解决方案
我没有测试这是否真的有效,但我能够克服你在这里遇到的错误......
1) 如果您从 NuGet(metadings 包)安装了顶级结果,请将其卸载并尝试使用“clzmq”包(或 64 位版本)。
2) 将 DLL 从“C:\Users\.nuget\packages\clrzmq\2.2.5\lib”和“C:\Users\.nuget\packages\clrzmq\2.2.5\content”复制到“资产” ' Unity 项目的文件夹。
3) 在您的脚本中,切换“使用 ZeroMQ;” '使用 ZMQ;'
此时您应该可以运行了。
我没有尝试通过元数据从第一个“ZeroMQ”包中复制 DLL,因此如果您愿意,可以尝试。我会先尝试 clzmq,如果它不适合您的需求,那么再给 metadings 一个机会。您还必须为 Unity 配置 4.0 框架支持才能使用 metadings 包。
更新:我最终测试了这个。我必须使用 x64 版本,但它可以工作。这是完整的脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text;
using ZMQ;
public class mqtest : MonoBehaviour
{
public float speed;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
System.Console.WriteLine("Hey");
rb.AddForce(movement * speed);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("space"))
{
print("space key was pressed");
string endpoint = "tcp://127.0.0.1:5555";
// ZMQ Context and client socket
using (ZMQ.Context context = new ZMQ.Context())
using (ZMQ.Socket client = context.Socket(SocketType.REQ))
{
client.Connect(endpoint);
string request = "Hello";
client.Send(request, Encoding.UTF8);
}
}
}
}
推荐阅读
- android - 扫描时自动更改屏幕方向(使用 ZXING 库)
- android - 底部导航视图不起作用
- java - 文件夹中的文件存储在 _nXm_ 矩阵中,其中 n 给出行数,m 给出列数
- javascript - Webpack:如何更改导出模块的全局变量名称?
- angular - 使用 Get 而不是 Post 的 Angular 方式数据表
- ios - 如何将一个 Storyboard 的 ContainerView 链接到另一个 Storyboard 中的 ViewController?
- c# - 有没有办法将自定义枚举集合转换为另一个自定义枚举集合?
- python - 计算最大和最小特征值
- java - Primefaces 数据表不适用于过滤器 + 排序
- templates - 无法使用 vue js 在模板中处理 json 数据