Like a few Others on this forum, I'm trying to send data between multiple Hololenses using the custom messages class (CustomMessages.cs).
Since there is no step by step documentation on how to use this class I tried to follow the steps posted in this topic:
My Hololenses do connect to the sharing service and join the same session but it seems that no communication is happening.
These are my scripts:
-Added to the custom Messages script (I invoke the SendGameObj method by pressing a button ingame):
public enum TestMessageID : byte
{
HeadTransform = MessageID.UserMessageIDStart,
Max,
}
and:
public void SendGameObj(GameObject obj)
{
// If we are connected to a session, broadcast our head info
if (this.serverConnection != null && this.serverConnection.IsConnected())
{
// Create an outgoing network message to contain all the info we want to send
NetworkOutMessage msg = CreateMessage((byte)TestMessageID.Max);
//Appending a gameobj to the message
msg.Write(obj.name);
// Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
this.serverConnection.Broadcast(
msg,
MessagePriority.Immediate,
MessageReliability.ReliableOrdered,
MessageChannel.Avatar);
Debug.Log ("message sent");
}
}
-Separate script where I try to receive the sent messages:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HoloToolkit.Sharing.Tests;
using HoloToolkit.Sharing;
public class TestMessage : MonoBehaviour {
public GameObject testObject; //some random test object who's color will be changed
// Use this for initialization
void Start () {
CustomMessages.Instance.MessageHandlers[CustomMessages.TestMessageID.Max] = this.OnGameObjIdRcv;
}
void OnGameObjIdRcv(NetworkInMessage msg)
{
msg.ReadInt64();
string objname_in_msg = msg.ReadString();
print ("object name: " + objname_in_msg);
testObject.GetComponent<MeshRenderer> ().material.color = Color.red; //make object red to see whether this method triggers on Hololens
}
public void LocalPrint () {
print ("local button test");
}
}