Ejemplo n.º 1
0
        /// <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()); }
        }
Ejemplo n.º 2
0
        public MyDesignArgs(GameObject UI, GameObject objPrinted)
        {
            this.UI         = UI;
            this.objPrinted = objPrinted;

            // serialize the object
            MyGameObject           myObj    = new MyGameObject(objPrinted);
            DataContractSerializer DCS      = new DataContractSerializer(myObj.GetType());
            MemoryStream           streamer = new MemoryStream();

            DCS.WriteObject(streamer, myObj);
            streamer.Seek(0, SeekOrigin.Begin);
            objPrintedString = XElement.Parse(Encoding.ASCII.GetString(streamer.GetBuffer()).Replace("\0", "")).ToString();
        }