Hello i have a problem regarding the function execution in events. Im currently writing a client for my Hololens (AR) to just set a TextMesh in the event when i receive a message. I already receive a message but the function SetMessageText(string message) is not working out.
The function is called but the text of the TextMesh is not set.
[SerializeField]
private TextMesh receivedMessageText;
IConnection connection;
IModel channel;
EventingBasicConsumer consumer;
// Start is called before the first frame update
void Start()
{
state = "not set";
ConnectionFactory factory = new ConnectionFactory();
factory.HostName = "localhost";
factory.UserName = "guest";
factory.Password = "guest";
factory.VirtualHost = "/";
factory.HostName = "localhost";
factory.Uri = "amqp://guest:guest@localhost:5672/";
connection = factory.CreateConnection();
channel = connection.CreateModel();
channel.QueueDeclare(queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null);
consumer = new EventingBasicConsumer(channel);
consumer.Received += (ch, ea) =>
{
var body = ea.Body;
string message = Encoding.UTF8.GetString(body);
Debug.Log("Got message! Body: " + message);
Debug.Log("Model: " + consumer.Model);
// set text from producer
receivedMessageText.text = message;
SetMessageText(message);
state = "message received";
Debug.Log("State: " + state);
};
channel.BasicConsume("hello", true, consumer);
Debug.Log("Channel open: " + channel.IsOpen);
}
private void SetMessageText(string message)
{
Debug.Log("Set TextMesh to: " + message);
receivedMessageText.text = message;
}