Search Unity

Sharing and custom messages not working

Discussion in 'VR' started by foxvalleysoccer, Sep 21, 2017.

  1. foxvalleysoccer

    foxvalleysoccer

    Joined:
    May 11, 2015
    Posts:
    108
    I'm attempting to highlight a model and then send message to other Hololens to show that highlight also. The highlight works on my device but does not turn to highlighted on the other devices.

    Any idea where I'm going wrong?

    Code (CSharp):
    1.  private void HightlightCamShaft()
    2.     {
    3.         CustomMessages.Instance.SendHightlightCamShaft();
    4.         TheEnergyHub.GetComponent<EnergyHubBase>().HighlightCamShaft();
    5.     }
    6.  
    CustomMessages.cs
    Code (CSharp):
    1. public void SendHightlightCamShaft()
    2.     {
    3.         // If we are connected to a session, broadcast our head info
    4.         if (this.serverConnection != null && this.serverConnection.IsConnected())
    5.         {
    6.             // Create an outgoing network message to contain all the info we want to send
    7.             NetworkOutMessage msg = CreateMessage((byte)TestMessageID.HightlightCamShaft);
    8.  
    9.  
    10.             // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
    11.             this.serverConnection.Broadcast(
    12.                 msg,
    13.                 MessagePriority.Immediate,
    14.                 MessageReliability.ReliableOrdered,
    15.                 MessageChannel.Avatar);
    16.         }
    17.     }
    18.  
    EnergyHubBase.cs

    Code (CSharp):
    1. public void HighlightCamShaft()
    2.     {
    3.         Color32 col = pCylinder13.gameObject.GetComponent<Renderer>().material.GetColor("_Color");
    4.         col.r = 229;
    5.         col.g = 253;
    6.         col.b = 0;
    7.         col.a = 100;
    8.  
    9.         pCylinder13.gameObject.GetComponent<Renderer>().material.SetColor("_Color", col);
    10.         pCylinder14.gameObject.GetComponent<Renderer>().material.SetColor("_Color", col);
    11.         pCylinder17.gameObject.GetComponent<Renderer>().material.SetColor("_Color", col);
    12.         pCylinder19.gameObject.GetComponent<Renderer>().material.SetColor("_Color", col);
    13.         pCylinder20.gameObject.GetComponent<Renderer>().material.SetColor("_Color", col);
    14.     }
    15.  
     
  2. sharkweek42

    sharkweek42

    Joined:
    Jul 30, 2013
    Posts:
    14
    Are you registering your HighlightCamShaft function with the dictionary in the CustomMessages script? If I remember correctly you have to add an enum value to that script, then you use your new enum in the dictionary in CustomMessages to tell it which function to call when it receives a message containing that enum. I believe the head sync example has something like that in it.
     
    foxvalleysoccer likes this.
  3. foxvalleysoccer

    foxvalleysoccer

    Joined:
    May 11, 2015
    Posts:
    108
    I was missing this line in the Start method.
    CustomMessages.Instance.MessageHandlers[CustomMessages.TestMessageID.HightlightCamShaft] = this.HighlightCamShaft;

    Is that what you ment Sharkweek42?
     
  4. sharkweek42

    sharkweek42

    Joined:
    Jul 30, 2013
    Posts:
    14
    Yeah, that sounds right. Did that help?
     
  5. foxvalleysoccer

    foxvalleysoccer

    Joined:
    May 11, 2015
    Posts:
    108
    yes once i applied that line in my start method everything worked properly.
     
    Last edited: Sep 25, 2017
    sharkweek42 likes this.