您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

27 行
851 B

using System.Net.Sockets;
using System.Threading.Tasks;
using UnityEngine;
using RosColor = RosMessageTypes.RoboticsDemo.UnityColor;
public class RosSubscriberExample : RosSubscriber
{
public GameObject cube;
protected override async Task HandleConnectionAsync(TcpClient tcpClient)
{
await Task.Yield();
using (var networkStream = tcpClient.GetStream())
{
RosColor colorMessage = (RosColor)ReadMessage(networkStream, new RosColor());
Debug.Log("Color(" + colorMessage.r + ", " + colorMessage.g + ", " + colorMessage.b + ", " + colorMessage.a + ")");
cube.GetComponent<Renderer>().material.color = new Color32((byte)colorMessage.r, (byte)colorMessage.g, (byte)colorMessage.b, (byte)colorMessage.a);
}
}
void Start()
{
StartMessageServer();
}
}