Example #1
0
    public bool InitNetWork(string _serverIp, int _serverPort)
    {
        if (string.IsNullOrEmpty(_serverIp) || _serverPort == 0)
        {
            return(false);
        }

        if (uNetSocket == null)
        {
            uNetSocket = new UnitySocket();
        }

        if (IsConnectServer && IsSameIpAndPort(_serverIp, _serverPort))
        {
            return(true);
        }

        IsConnectServer = uNetSocket.ConnectServer(_serverIp, _serverPort);
        if (IsConnectServer)
        {
            strConnectIp = _serverIp;
            iConnectPort = _serverPort;
        }
        return(IsConnectServer);
    }
Example #2
0
 public NetWorkClient()
 {
     uNetSocket      = null;
     IsConnectServer = false;
     strConnectIp    = null;
     iConnectPort    = 0;
 }
    void OnGUI()
    {
        GUI.skin = mySkin;
        for (int i = 0; i < 4; i++)
        {
            String s = textAreaString[i * 3] + "\n" + textAreaString[i * 3 + 1] + "\n" + textAreaString[i * 3 + 2];
            GUI.TextArea(new Rect(i % 2 * Screen.width / 2, i / 2 * (Screen.height / 2) + 50, 100, 60), s);
            textFieldString[i] = GUI.TextField(new Rect(i % 2 * Screen.width / 2 + 50, i / 2 * (Screen.height / 2), 100, 20), textFieldString[i]);
            if (GUI.Button(new Rect(i % 2 * Screen.width / 2, i / 2 * (Screen.height / 2), 40, 20), "连接"))
            {
                socket[i] = null;
                socket[i] = new UnitySocket();
                socket[i].SocketConnection("127.0.0.1", 7981, this, i);
                socket[i].DoLogin(textFieldString[i]);
            }
            else if (GUI.Button(new Rect(i % 2 * Screen.width / 2, i / 2 * (Screen.height / 2) + 25, 40, 20), "关闭"))
            {
                if (socket[i] != null)
                {
                    socket[i].close();
                    socket[i] = null;
                }
            }
        }

        if (GUI.Button(new Rect(Screen.width - 60, Screen.height - 30, 60, 30), "退出"))
        {
            Application.Quit();
        }
    }
Example #4
0
 public bool Reconnect()
 {
     if (uNetSocket == null)
     {
         uNetSocket = new UnitySocket();
     }
     IsConnectServer = uNetSocket.ConnectServer(strConnectIp, iConnectPort);
     return(IsConnectServer);
 }
Example #5
0
 public void CloseNetwork()
 {
     if (uNetSocket != null)
     {
         uNetSocket.close();
     }
     uNetSocket      = null;
     IsConnectServer = false;
     //strConnectIp = null;
     //iConnectPort = 0;
 }
Example #6
0
        public void loadPDB(string id)
        {
            UnitySocket.Send(CommandID.GETPDB);
            UnitySocket.Send(0);
            UnitySocket.Send(id);
            int num0 = UnitySocket.ReceiveInt();
            int num1 = UnitySocket.ReceiveInt();

            //print(num);

            Debug.Log(num0 + "|" + num1);

            for (int k = 0; k < num0 + num1; k++)
            {
                UnitySocket.Send(CommandID.GETPDB);
                UnitySocket.Send(k + 1);
                if (k < num0)
                {
                    string sonAtoms = UnitySocket.ReceiveString(60000);

                    Atoms += sonAtoms.Trim();
//					Debug.Log("sonAtoms is: "+sonAtoms);
                }

                else
                {
                    string sonClubs = UnitySocket.ReceiveString(68000);
                    Clubs += sonClubs.Trim();
                }
            }
            string [] sArray = Atoms.Split('$');
            Debug.Log("length:" + sArray.Length);
            for (int i = 0; i < sArray.Length - 1; i++)
            {
                if (sArray[i] == "")
                {
                    continue;
                }
                string [] ssArray = sArray[i].Split('#');

//						Debug.Log(i+"|"+sArray[i]+"////");

                float[] vect = new float[3];

                float.TryParse(ssArray[0], out vect[0]);
                float.TryParse(ssArray[1], out vect[1]);
                float.TryParse(ssArray[2], out vect[2]);
//						for(int kk=0;kk<vect.Length;kk++)
//						{
//							Debug.Log(i+"|"+vect[kk]+"////");
//						}
                typelist.Add(AtomModel.GetModel(ssArray[3]));
                alist.Add(vect);
            }

            Debug.Log(Clubs);
            Vector3 minPoint = Vector3.zero;
            Vector3 maxPoint = Vector3.zero;

            MoleculeModel.atomsLocationlist = alist;
            MoleculeModel.atomsTypelist     = typelist;
            //MoleculeModel.bondList=ControlMolecule.CreateBondsList(alist,typelist);
            //Debug.Log("======================= Bond List" + MoleculeModel.bondList.ToString());
            MoleculeModel.bondEPList      = ControlMolecule.CreateBondsEPList(alist, typelist);
            MoleculeModel.bondEPSugarList = ControlMolecule.CreateBondsEPList(MoleculeModel.atomsSugarLocationlist, MoleculeModel.atomsSugarTypelist);

//			float [] a0=alist[0] as float[];
//			MoleculeModel.cameraLocation.x=MoleculeModel.target.x=a0[0];
//			MoleculeModel.cameraLocation.y=MoleculeModel.target.y=a0[1];
//			MoleculeModel.target.z=a0[2];
//			MoleculeModel.cameraLocation.z=a0[2]-150;
//

            for (int i = 0; i < alist.Count; i++)
            {
                float[] position = alist[i] as float[];
                minPoint = Vector3.Min(minPoint, new Vector3(position[0], position[1], position[2]));
                maxPoint = Vector3.Max(maxPoint, new Vector3(position[0], position[1], position[2]));
            }
            Vector3 centerPoint = minPoint + ((maxPoint - minPoint) / 2);

            //MoleculeModel.target = centerPoint;

            MoleculeModel.Offset = -centerPoint;


            for (int i = 0; i < alist.Count; i++)
            {
                float[] position = alist[i] as float[];
                float[] vect     = new float[3];
                vect[0] = position[0] + MoleculeModel.Offset.x;
                vect[1] = position[1] + MoleculeModel.Offset.y;
                vect[2] = position[2] + MoleculeModel.Offset.z;

                alist[i] = vect;
            }


//			Debug.Log("MoleculeModel.target "+MoleculeModel.target);
            MoleculeModel.cameraLocation.x = MoleculeModel.target.x;
            MoleculeModel.cameraLocation.y = MoleculeModel.target.y;
//			MoleculeModel.cameraLocation.z=MoleculeModel.target.z-((maxPoint - minPoint) ).z;
            MoleculeModel.cameraLocation.z = MoleculeModel.target.z - ((maxPoint - minPoint)).z;



            //MoleculeModel.bondList=ControlMolecule.CreateBondsList(alist,typelist);
            MoleculeModel.bondEPList      = ControlMolecule.CreateBondsEPList(alist, typelist);
            MoleculeModel.bondEPSugarList = ControlMolecule.CreateBondsEPList(MoleculeModel.atomsSugarLocationlist, MoleculeModel.atomsSugarTypelist);



            MoleculeModel.atomsnumber = alist.Count;
            MoleculeModel.bondsnumber = MoleculeModel.bondEPList.Count;


            string [] sClubArray = Clubs.Split('$');
            for (int i = 0; i < sClubArray.Length - 1; i++)
            {
                string [] ssClubArray = sClubArray[i].Split('#');
                float[]   vect        = new float[3];
                vect[0] = float.Parse(ssClubArray[0]);
                vect[1] = float.Parse(ssClubArray[1]);
                vect[2] = float.Parse(ssClubArray[2]);
                clubLocationalist.Add(vect);


                float[] vectRotation = new float[3];
                vectRotation[0] = float.Parse(ssClubArray[3]);
                vectRotation[1] = float.Parse(ssClubArray[4]);
                vectRotation[2] = 0f;

                clubRotationList.Add(vectRotation);
            }

            Debug.Log(clubRotationList.Count);
        }