public void AddOrMoveCell(UpdatedCell UC)
    {
        Vector3 pos = new Vector3(UC.x, 0, UC.y);

        CellGJ CGJ;

        if (CellList[UC.cellType].TryGetValue(UC.id, out CGJ))
        {
            if (UC.removed)
            {
                Destroy(CellList[UC.cellType][UC.id].GJ);
                CellList[UC.cellType].Remove(UC.id);
            }
            else
            {
                CGJ.GJ.transform.position = pos;
            }
        }
        else
        {
            Quaternion rot = new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble());
            CellList[UC.cellType].Add(UC.id, new CellGJ(UC.cellType, UC.id, Instantiate(prefabs[UC.cellType], pos, rot)));

            float VirusScale = 0.2f;
            if (UC.cellType == 0) //virus
            {
                CellList[UC.cellType][UC.id].GJ.transform.localScale = new Vector3(VirusScale, VirusScale, VirusScale);
                CellList[UC.cellType][UC.id].GJ.tag = "Virus";
            }

            float WBCScale = 0.5f;
            if (UC.cellType == 1) //WBC
            {
                CellList[UC.cellType][UC.id].GJ.transform.localScale = new Vector3(WBCScale, WBCScale, WBCScale);
                CellList[UC.cellType][UC.id].GJ.tag = "WBC";
            }

            float antibodyScale = 0.6f;
            if (UC.cellType == 2) //antibody
            {
                CellList[UC.cellType][UC.id].GJ.transform.localScale = new Vector3(antibodyScale, antibodyScale, antibodyScale);
            }

            float CellScale = 0.8f;
            if (UC.cellType == 3) //Cell
            {
                CellList[UC.cellType][UC.id].GJ.transform.localScale = new Vector3(CellScale, CellScale, CellScale);
            }
        }
    }
    public void Start()
    {
        prefabs.Add(virusPrefab);
        prefabs.Add(wbcPrefab);
        prefabs.Add(antiBodyPrefab);
        prefabs.Add(cellPrefab);

        for (int i = 0; i < prefabs.Count; i++)
        {
            CellList.Add(new Dictionary <int, CellGJ>());
        }

        UpdatedCell UP = new UpdatedCell(0, 1, 0, 0, false);

        //AddOrMoveCell(UP);

        socket = ConnectSocket(ipServer, 8000);
    }
    public void FixedUpdate()
    {
        string requestParams = "";

        foreach (object mes in messages)
        {
            foreach (var field in mes.GetType().GetFields())
            {
                requestParams += field.Name + "=" + field.GetValue(mes).ToString() + "&";
            }
        }
        messages.Clear();

        int length = requestParams.Length;

        string request = "POST / HTTP/1.1\r\nHost: " + ipServer + "\r\nConnection: Keep-Alive\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: " + length.ToString() + "\r\n\r\n";

        request += requestParams;
        Byte[] bytesSent = Encoding.ASCII.GetBytes(request);

        if (socket != null && socket.Connected)
        {
            socket.Send(bytesSent, bytesSent.Length, 0);

            int inpByteCount = socket.Receive(inpBuffer);

            String input = Encoding.ASCII.GetString(inpBuffer, 0, inpByteCount);
            Debug.Log(input);
            String[] inputArr = input.Split('\n');

            if (inputArr[inputArr.Length - 1].Length == 2)
            {
                return;
            }

            String intermediate = inputArr[inputArr.Length - 1].Replace(":", ",").Replace("}", "").Replace("{", "").Replace("]", "").Replace("[", "").Replace("\"", "");
            Debug.Log(intermediate);
            String[] JSONArr = intermediate.Split(',');

            List <object> resultList = new List <object>();

            for (int i = 0; i < JSONArr.Length; i += 2)
            {
                if (!JSONArr[i].Equals("type"))
                {
                    Debug.Log("UnkownType: " + JSONArr[i]);
                    continue;
                    //throw new Exception("Incoming parsing error");
                }

                Type   currentType = Type.GetType(JSONArr[i + 1]);
                object newObj      = Activator.CreateInstance(currentType);

                foreach (var field in currentType.GetFields())
                {
                    i += 2;

                    if (!field.Name.Equals(JSONArr[i]))
                    {
                        Debug.Log(field.Name);
                        throw new Exception("Incoming parsing error");
                    }

                    field.SetValue(newObj, Convert.ChangeType(JSONArr[i + 1], field.FieldType));
                }

                resultList.Add(newObj);
            }

            foreach (object obj in resultList)
            {
                if (obj.GetType() == typeof(UpdatedCell))
                {
                    UpdatedCell uc = ((UpdatedCell)obj);

                    AddOrMoveCell(uc);
                    //AddVirus(vp.id, new Vector3(vp.x, 0, vp.z));
                }
                //entry.Key.GetMethod("Process").Invoke(entry.Value, new object[] { this });
            }
        }
    }