Example #1
0
    /// <summary>
    /// Called once per frame.
    ///
    /// Currently designed so that if messages are recieved more frequently than Update is called
    /// (i.e. at a rate higher than the framerate) then only the last message received is kept.
    /// This can be changed by extending the OnRecieve method, but for now there is no downside to this approach.
    /// </summary>
    private void Update()
    {
        if (messageReceived == true)
        {
            //Message message = Unity_CVE.Message.GetRootAsMessage(new ByteBuffer(receiveBytes));
            ChildUpdateHolder ObjectToUpdate = null;
            switch (this.lastMessage.Channel)
            {
            case "CH0":
                ObjectToUpdate = this.CH0_ChildUpdateHolder;
                break;

            case "CH1":
                ObjectToUpdate = this.CH1_ChildUpdateHolder;
                break;

            case "CH2":
                ObjectToUpdate = this.CH2_ChildUpdateHolder;
                break;

            case "CH3":
                ObjectToUpdate = this.CH3_ChildUpdateHolder;
                break;

            case "CH4":
                ObjectToUpdate = this.CH4_ChildUpdateHolder;
                break;

            case "CH5":
                ObjectToUpdate = this.CH5_ChildUpdateHolder;
                break;

            case "CH6":
                ObjectToUpdate = this.CH6_ChildUpdateHolder;
                break;

            default:
                //Channel is not one that is monitored.
                UnityEngine.Debug.Log("Received message on unwatched channel. Channel: " + this.lastMessage.Channel);
                break;
            }
            if (ObjectToUpdate != null)
            {
                //This switch is based on message type.
                switch (this.lastMessage.MessageDataType)
                {
                case Data.Location:
                    //this.lastMessage.GetMessageData<>();
                    Location loc = this.lastMessage.GetMessageData <Location>(new Location());
                    ObjectToUpdate.setLocation(loc.X, loc.Y, loc.Z);
                    UnityEngine.Debug.Log("Recieved loc: " + loc.X + loc.Y + loc.Z);
                    break;

                case Data.Position:
                    Position pos = this.lastMessage.GetMessageData <Position>(new Position());
                    ObjectToUpdate.setPosition(pos.X, pos.Y, pos.Z, pos.Roll, pos.Pitch, pos.Yaw);
                    UnityEngine.Debug.Log("Recieved pos: " + pos.X + pos.Y + pos.Z + pos.Roll + pos.Pitch + pos.Yaw);
                    break;

                case Data.Orientation:
                    Orientation ori = this.lastMessage.GetMessageData <Orientation>(new Orientation());
                    ObjectToUpdate.setOrientation(ori.Roll, ori.Pitch, ori.Yaw);
                    UnityEngine.Debug.Log("Recieved ori: " + ori.ToString());
                    break;

                case Data.ExtraParam:
                    ExtraParam ext = this.lastMessage.GetMessageData <ExtraParam>(new ExtraParam());
                    ObjectToUpdate.setExtraParam(ext.Name, ext.Value);
                    UnityEngine.Debug.Log("Recieved ext: " + ext.ToString());
                    break;

                default:
                    //Empty Message or Error.
                    UnityEngine.Debug.Log("Networking Script unable to determine the type of a recieved message.");
                    break;
                }
            }
            messageReceived = false;
        }
    }