/// <summary> /// sends the caracteristics of your object to the server /// </summary> /// <param name="obj"></param> public void SendObjectCaracteristics(GameObject obj) { try { if (connector.GetServerConnection() == null) { } else if (connector.GetServerConnection().ConnectionAlive()) // is it connected ? { // serialize the object int ID = obj.GetComponent <AdditionnalProperties>().ID; MyGameObject myObj = new MyGameObject(obj); DataContractSerializer DCS = new DataContractSerializer(myObj.GetType()); MemoryStream streamer = new MemoryStream(); DCS.WriteObject(streamer, myObj); streamer.Seek(0, SeekOrigin.Begin); string content = XElement.Parse(Encoding.ASCII.GetString(streamer.GetBuffer()).Replace("\0", "")).ToString(); string monString = "Name: " + StringHelper.GetBetween(content, "<a:name>", "</a:name>") + "\n\n"; monString = monString + "<ID \n " + ID.ToString() + "\nID> \n\n"; monString = monString + "<Position " + StringHelper.GetBetween(content, "<position xmlns:a=\"http://schemas.datacontract.org/2004/07/UnityEngine\">", "</position>") + "Position> \n\n"; monString = monString + "<Scale " + StringHelper.GetBetween(content, "<scale xmlns:a=\"http://schemas.datacontract.org/2004/07/UnityEngine\">", "</scale>") + "Scale> \n\n"; CommunicateUpdate messageUpdate = new CommunicateUpdate(NetworkComms.NetworkIdentifier, monString, ID); connector.GetServerConnection().SendObject("Update", messageUpdate); } } catch (Exception e) { System.IO.File.WriteAllText(@"Content.txt", e.ToString()); } }
/// <summary> /// get a message that asks us to update our object and UI /// </summary> /// <param name="header">The PacketHeader corresponding with the received object</param> /// <param name="connection">The Connection from which this object was received</param> /// <param name="incomingMessage">The incoming CommunicateElement we are after</param> private void HandleIncomingObjectUpdate(PacketHeader header, Connection connection, CommunicateUpdate incomingMessage) { // verifies it is an object if (incomingMessage.ID != -1) { if (NetworkComms.NetworkIdentifier != connection.ConnectionInfo.NetworkIdentifier) { foreach (MyMesh mesh in constructor.GetConstructedElements()) { if (mesh.obj.GetComponent("AdditionnalProperties") != null) { if (mesh.obj.GetComponent <AdditionnalProperties>().ID == incomingMessage.ID) { string content = incomingMessage.Message; Manager manager = GameObject.Find("Manager").GetComponent <Manager>(); manager.SetObj(mesh.obj); manager.TryUpdating(content); manager.TryDesigning(content); break; // get out of the loop } } } } } }