如何将ZeroMQ导入Unity引擎?
How to import ZeroMQ into Unity engine?
我正在尝试为 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.5\lib' &
'C:\Users\.nuget\packages\clrzmq.2.5\content'
到您的 Unity 项目的 'Assets' 文件夹。
3) 在您的脚本中,将 'using ZeroMQ;' 切换为 'using ZMQ;'
此时您应该可以 运行。
我没有尝试通过 metadings 从第一个 'ZeroMQ' 包中复制 DLL,因此如果您愿意,可以尝试一下。我会先尝试 clzmq,如果它不适合您的需求,那么再试一次 metadings。您还必须配置支持 4.0 框架的 Unity 才能使用 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);
}
}
}
}
我正在尝试为 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.5\lib' & 'C:\Users\.nuget\packages\clrzmq.2.5\content' 到您的 Unity 项目的 'Assets' 文件夹。
3) 在您的脚本中,将 'using ZeroMQ;' 切换为 'using ZMQ;'
此时您应该可以 运行。
我没有尝试通过 metadings 从第一个 'ZeroMQ' 包中复制 DLL,因此如果您愿意,可以尝试一下。我会先尝试 clzmq,如果它不适合您的需求,那么再试一次 metadings。您还必须配置支持 4.0 框架的 Unity 才能使用 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);
}
}
}
}