コード例 #1
0
ファイル: UGUI.cs プロジェクト: CKY1015/Unity3D
    public void OFF()//關閉連線(OFF)
    {
        Debug.Log("TSB_Stop");
        string msg = "#stop$";

        SocketApp.SendAll(msg);// do things
        Debug.Log("send_stop");
        stop = true;
    }
コード例 #2
0
ファイル: IMGUI.cs プロジェクト: CKY1015/Unity3D
 public void Constate1(int windowID)
 {
     if (GUI.Button(new Rect(10, 20, 150, 25), "OK"))
     {
         s = true;
         Debug.Log("TSB_Activate");
         string msg = "#send$";
         SocketApp.SendAll(msg);                                       // do things
         Debug.Log("send_activate");
         open = false;
     }
     // Make the windows be draggable.
     GUI.DragWindow(new Rect(0, 0, 10000, 10000));
 }
コード例 #3
0
    void OnGUI()
    {
        GUILayout.Label("pitch: " + TCP_Handler.pitch.ToString("0.00"));
        GUILayout.Label("roll: " + TCP_Handler.roll.ToString("0.00"));
        GUILayout.Label("yaw: " + TCP_Handler.yaw.ToString("0.00"));
        GUILayout.Label("Times: " + (int)time_f / 60 + "m" + (int)time_f % 60 + "s");
        GUILayout.Label("connected number: " + SocketApp.TCP_clientList.Count);

        /*if (GUILayout.Button(TSB_Open, GUILayout.Height(50), GUILayout.Width(50)))//測試按鍵改成圖片用
         *      {
         *              Debug.Log("TSB_Open");
         *  FileInfo.loadSettingFile();
         * }*/

        if (GUILayout.Button("TSB_Open"))//開啟
        {
            Debug.Log("TSB_Open");
            FileInfo.loadSettingFile();
        }

        if (GUILayout.Button("TSB_Start"))//開始
        {
            Debug.Log("TSB_Start");
            myThread = new Thread(new ThreadStart(ServerProcess));
            myThread.IsBackground = true;
            myThread.Start();
        }

        GUI.color = Color.gray;
        if (GUILayout.Button("TSB_CLose"))//關閉
        {
            s = false;
            //isGet = false;
            if (myThread != null)
            {
                SocketApp.isRun = false;
                if (myThread.IsAlive)
                {
                    SocketApp.CloseAll();
                    TCP_Handler.tcpClose();
                    //printall("no Loacal IP");
                    SocketApp.acceptDone.Set();
                }
                Thread.Sleep(100);
                myThread.Abort();
            }
            if (SocketApp.transMode == (int)SocketApp.Transfer_Mode.M_UDP)
            {
                SocketApp.CloseAll();
            }
        }
        GUI.color = Color.white;

        if (GUILayout.Button("TSB_Activate"))//啟動連線
        {
            s = true;
            Debug.Log("TSB_Activate");
            string msg = "#send$";
            SocketApp.SendAll(msg);                                       // do things
            Debug.Log("send_activate");
            //StartCoroutine("Activate");//註解比較穩定
        }

        GUI.color = Color.gray;
        if (GUILayout.Button("TSB_Stop"))//暫停
        {
            s = false;
            Debug.Log("TSB_Stop");
            string msg = "#stop$";
            SocketApp.SendAll(msg);                                       // do things
            Debug.Log("send_stop");
        }

        if (GUILayout.Button("Restart"))        //整個專案重新開始
        {
            Debug.Log("Restart");
            SocketApp.TCP_clientList.Clear();
            Application.LoadLevel(Application.loadedLevel);
        }
        GUI.color = Color.white;

        GUILayout.Label("");
        GUILayout.Label("connected sensors: ");
        if (TCP_Handler.SID_List.Count > 0)
        {
            foreach (int ID in TCP_Handler.SID_List)
            {
                //Debug.Log("sensor ID: " + ID);
                sensornumber += ID.ToString();
                sensornumber += " ";
            }
            TCP_Handler.SID_List.Clear();
        }
        GUILayout.Label(sensornumber);                        //目前連線的sensor
        if (TCP_Handler.sensor_num_ID.Count > 0 && s == true) //activate後傳值的數量
        {
            foreach (int ID in TCP_Handler.sensor_num_ID)
            {
                Debug.Log("sensor ID: " + ID);
            }
        }
    }
コード例 #4
0
ファイル: IMGUI.cs プロジェクト: CKY1015/Unity3D
    void OnGUI()
    {
        //(x位置, y位置, x長度, y長度)
        ///////////////////////////////////////BUTTON///////////////////////////////////////
        GUI.Box(new Rect(10, 10, 200, 500), "Button");

        ///////////////////////////////連線部分///////////////////////////////
        GUI.color = Color.green;
        GUI.Box(new Rect(20, 30, 180, 100), "連線:");
        GUI.color = Color.white;
        if (GUI.Button(new Rect(40, 60, 70, 50), "ON"))//開始連線(ON)
        {
            Debug.Log("TSB_Open");
            FileInfo.loadSettingFile();
            Debug.Log("TSB_Start");
            myThread = new Thread(new ThreadStart(ServerProcess));
            myThread.IsBackground = true;
            myThread.Start();
            open = true;
        }
        if (SocketApp.TCP_clientList.Count == 3 && open == true)//確定3顆都連線
        {
            GUI.color = Color.green;
            windowCon = GUI.Window(0, windowCon, Constate1, "System Connected!");
            GUI.color = Color.white;
            //StartCoroutine("Activate");//註解比較穩定
        }
        if (GUI.Button(new Rect(115, 60, 70, 50), "OFF"))//關閉連線(OFF)
        {
            Debug.Log("TSB_Stop");
            string msg = "#stop$";
            SocketApp.SendAll(msg);// do things
            Debug.Log("send_stop");
            stop = true;
        }
        if (stop == true)
        {
            GUI.color = Color.red;
            windowCon = GUI.Window(0, windowCon, Constate2, "System Disconnected?");
            GUI.color = Color.white;
        }


        ///////////////////////////////讀存檔部分///////////////////////////////
        GUI.color = Color.green;
        GUI.Box(new Rect(20, 140, 180, 70), "軌跡紀錄:");
        GUI.color = Color.white;
        if (GUI.Button(new Rect(55, 170, 50, 20), "Save"))//存檔
        {
            savedataflag = true;
            datastate    = "Save";
            Debug.Log("save data!!");
        }
        if (GUI.Button(new Rect(110, 170, 50, 20), "Load"))//讀檔
        {
            loaddataflag = true;
            datastate    = "Load";
            Debug.Log("load data!!");
        }

        ///////////////////////////////遊戲部分///////////////////////////////
        GUI.color = Color.green;
        GUI.Box(new Rect(20, 220, 180, 90), "遊戲模式:");
        GUI.color = Color.white;
        if (GUI.Button(new Rect(30, 250, 50, 20), "Mode1"))//模式1
        {
            Time.timeScale = 1;
            mode_flag      = 1;
            time_b         = true;
            time_f         = 0;
        }
        if (GUI.Button(new Rect(85, 250, 50, 20), "Mode2"))//模式2
        {
            Time.timeScale = 2;
            mode_flag      = 2;
            time_b         = true;
            time_f         = 0;
        }
        if (GUI.Button(new Rect(140, 250, 50, 20), "Mode3"))//模式3
        {
            Time.timeScale = 3;
            mode_flag      = 3;
            time_b         = true;
            time_f         = 0;
        }
        if (gameState == GameState.lost)
        {
            GUI.color = Color.red;
            windowWon = GUI.Window(0, windowWon, Gamestate, "You Lost!");
            GUI.color = Color.white;
        }
        if (gameState == GameState.won)
        {
            GUI.color  = Color.green;
            windowLost = GUI.Window(1, windowLost, Gamestate, "You Won!");
            GUI.color  = Color.white;
        }

        ///////////////////////////////系統部分///////////////////////////////
        GUI.color = Color.green;
        GUI.Box(new Rect(20, 320, 180, 90), "系統相關:");
        GUI.color = Color.white;
        if (GUI.Button(new Rect(40, 350, 70, 20), "Play"))//開始
        {
            StartCoroutine(down());
        }
        if (GUI.Button(new Rect(115, 350, 70, 20), "Pause"))//暫停
        {
            Time.timeScale = 0;
        }
        if (GUI.Button(new Rect(40, 380, 70, 20), "Continue"))//繼續
        {
            Time.timeScale = 1;
        }
        if (GUI.Button(new Rect(115, 380, 70, 20), "Restart"))//重整
        {
            Debug.Log("Restart");
            SocketApp.TCP_clientList.Clear();
            Application.LoadLevel(Application.loadedLevel);
        }


        ///////////////////////////////////////DATA///////////////////////////////////////
        GUI.Box(new Rect(Screen.width - 110, 10, 100, 500), "Data");

        ///////////////////////////////系統部分///////////////////////////////
        GUI.color = Color.green;
        GUI.Label(new Rect(Screen.width - 100, 30, 50, 20), "時間:");
        GUI.color = Color.white;
        switch (mode_flag)
        {
        case 1:
            GUI.TextField(new Rect(Screen.width - 100, 50, 85, 20), "Times: " + (int)time_f / 60 + "m" + (int)time_f % 60 + "s");
            break;

        case 2:
            GUI.TextField(new Rect(Screen.width - 100, 50, 85, 20), "Times: " + (int)time_f / 2 / 60 + "m" + (int)time_f / 2 % 60 + "s");
            break;

        case 3:
            GUI.TextField(new Rect(Screen.width - 100, 50, 85, 20), "Times: " + (int)time_f / 3 / 60 + "m" + (int)time_f / 3 % 60 + "s");
            break;
        }
        GUI.color = Color.green;
        GUI.Label(new Rect(Screen.width - 100, 70, 50, 20), "角度:");
        GUI.color = Color.white;
        GUI.TextField(new Rect(Screen.width - 100, 90, 85, 20), "Pitch: " + TCP_Handler.pitch.ToString("0.000"));
        GUI.TextField(new Rect(Screen.width - 100, 110, 85, 20), "Roll: " + TCP_Handler.roll.ToString("0.000"));
        GUI.TextField(new Rect(Screen.width - 100, 130, 85, 20), "Yaw: " + TCP_Handler.yaw.ToString("0.000"));

        ///////////////////////////////連線部分///////////////////////////////
        GUI.color = Color.green;
        GUI.Box(new Rect(Screen.width - 105, 160, 90, 110), "連線狀況:");
        GUI.color = Color.white;
        GUI.Label(new Rect(Screen.width - 95, 180, 85, 20), "Sensors:");
        if (TCP_Handler.SID_List.Count > 0)
        {
            foreach (int ID in TCP_Handler.SID_List)
            {
                //Debug.Log("sensor ID: " + ID);
                sensornumber += ID.ToString();
                sensornumber += " ";
            }
            TCP_Handler.SID_List.Clear();
        }
        GUI.TextField(new Rect(Screen.width - 102, 200, 85, 20), sensornumber);
        GUI.Label(new Rect(Screen.width - 95, 220, 85, 20), "Numbers:");
        GUI.TextField(new Rect(Screen.width - 102, 240, 85, 20), SocketApp.TCP_clientList.Count.ToString());
        if (TCP_Handler.sensor_num_ID.Count > 0 && s == true)//activate後傳值的數量
        {
            foreach (int ID in TCP_Handler.sensor_num_ID)
            {
                Debug.Log("sensor ID: " + ID);
            }
        }

        ///////////////////////////////讀存檔部分///////////////////////////////
        GUI.color = Color.green;
        GUI.Box(new Rect(Screen.width - 105, 280, 90, 60), "檔案結果:");
        GUI.color = Color.white;
        GUI.TextField(new Rect(Screen.width - 102, 310, 85, 20), datastate);

        ///////////////////////////////遊戲部分///////////////////////////////
        GUI.color = Color.green;
        GUI.Box(new Rect(Screen.width - 105, 350, 90, 80), "遊戲分數:");
        GUI.color = Color.white;
        GUI.Label(new Rect(Screen.width - 100, 370, 85, 20), "Found gems:");
        GUI.TextField(new Rect(Screen.width - 102, 390, 85, 20), foundGems + "/" + totalGems);
        guiNumber.fontSize         = 200;
        guiNumber.normal.textColor = Color.red;
        if (countdownText != "")
        {
            GUI.Label(new Rect((Screen.width - 100) / 2 - 100, (Screen.height - 30) / 2, 100, 30), countdownText, guiNumber);
        }
    }