Пример #1
0
    //public GetSurroundingRes SurroundingRes;

    //   private void OnGUI() {
    //	GUI.Label(new Rect(5, Screen.height - 60, 1000, 20), msg);
    //}


    IEnumerator Start()
    {
        print("111");

        msg = "1111";

        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
        {
            yield break;
        }

        print("222");

        msg = "2222";

        // Start service before querying location
        Input.location.Start();

        // Wait until service initializes
        int maxWait = 20;

        while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
        {
            yield return(new WaitForSeconds(1));

            maxWait--;
        }

        // Service didn't initialize in 20 seconds
        if (maxWait < 1)
        {
            msg = "Timed out";
            yield break;
        }

        print("333");

        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed)
        {
            msg = "Unable to determine device location";
            yield break;
        }
        else
        {
            // Access granted and location value could be retrieved
            msg = "Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp;
            //StartCoroutine(SurroundingRes.Get("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=+" + Input.location.lastData.latitude + "," + Input.location.lastData.longitude + "&radius=500&type=restaurant&key=AIzaSyDiC9HjxWI0dBa9x5hYL9xOmOnWJcFE-zU"));
        }
        // Stop service if there is no need to query location updates continuously
        Input.location.Stop();

        LogUI.Show(msg, 60);

        print("Msg: " + msg);
    }
Пример #2
0
    //=======呼叫進入/創立房間介面==========

    // 雖然共用,但創房 和 進房 還是需要分別 (color)

    public void buttonCer(bool isCreate)
    {
        if (UIRoomManager.roomWaitForServer)                // 正在等待伺服器回傳房間狀態
        {
            LogUI.Show("正在等待伺服器回應...");
        }
        else
        {
            CreateOrJoinRoom = isCreate;
            ShowCreateOrJoinRoomUI();
        }
        Sounds.PlayButton();
    }
Пример #3
0
    public void GoButton()
    {
        if (playersInRoom.Count > 0)                        // 已經進入等待室,不能再按這個按鈕 (實際在UI時,這情況不會發生)
        {
            LogUI.Show("已經在等待室");
            return;
        }

        myInfos.ready = false;
        curStage      = 2;
        client.SendPlayerInfos(myInfos);            // 傳送自己的 Infos 給 伺服器,伺服器將回傳在房裡的人和自己的ID
        //if (myInfos.foodSelected != DataClient.preRes && GetRes.getLocSucceed) {
        //	new DataClient().ConnectToServer(Generic.gData.DataServerIP, Generic.gData.DataServerPort);
        //}
    }
Пример #4
0
    public void NickNameButton(Text inputField)
    {
        string name = inputField.text;

        myInfos.nickName = name;
        PlayerPrefs.SetString(nickNameSaveStr, name);

        if (name == "")
        {
            LogUI.Show("請輸入暱稱");
        }
        else
        {
            CheckAllSet();
        }
    }
Пример #5
0
    void Init()
    {
        if (instance != null)
        {
            Destroy(gameObject);
            return;
        }

        instance = this;

        logDialog.SetActive(false);
        popup.SetActive(false);
        onPopup  = false;
        onDialog = false;
        Application.logMessageReceived += HandleLog;

        DontDestroyOnLoad(gameObject);
    }
Пример #6
0
 /// <summary>
 /// 如果尚未連線則嘗試連線,若連線失敗返回 false
 /// </summary>
 public void ConnectToServer()
 {
     if (client == null)
     {
         myInfos.roomName           = "";
         client                     = new TcpClient();
         client.OnJoinedRoom        = JoinRoomCallback;
         client.OnPlayerListChanged = ListChangedCallback;
         client.OnStartGame         = StartGameCallback;
         client.OnMyInfoChanged     = MyInfoChanged;
         client.OnConnectFailed     = () => {
             LogUI.Show("伺服器未開啟");
             roomWaitForServer = false;
         };
     }
     if (client.connectStatus != ClientActions.ConnectStatus.Connecting)
     {
         client.ConnectToServer(Generic.gData.ServerIP, Generic.gData.ServerPort);
     }
 }
Пример #7
0
    public void JoinRoom(string name)
    {
        tmpRoomName = name;
        ConnectToServer();

        if (tmpRoomName == "")
        {
            LogUI.Show("請輸入房名");
        }
        else if (tmpRoomName != myInfos.roomName)                     // 一樣的房名不再加入
        {
            if (client.connectStatus == ClientActions.ConnectStatus.Connected)
            {
                client.JoinRoom(tmpRoomName);
            }
            else if (client.connectStatus == ClientActions.ConnectStatus.Connecting)
            {
                client.OnConnectedToServer = () => { client.JoinRoom(tmpRoomName); };
            }
            roomWaitForServer = true;
        }
    }
Пример #8
0
    public void StartGameButton()
    {
        Sounds.PlayButton();

        if (tmpRoomName == "")
        {
            return;
        }
        bool canGO = true;

        if (myInfos.ready)                      // 如果自己 Ready 了再檢查別人
        {
            for (int i = 0; i < playersInRoom.Count; i++)
            {
                // 有一個人沒有 Ready,不給進入遊戲
                if (!playersInRoom[i].ready)
                {
                    canGO = false;
                    break;
                }
            }
        }
        else
        {
            canGO = false;
        }

        if (canGO)
        {
            client.SendGameReady();
        }
        else
        {
            LogUI.Show("等待所有玩家都 Ready 才可以 GO");
        }
    }
Пример #9
0
    void ShowResDetailInfo(Details d)
    {
        if (d == null)
        {
            LogUI.Show("無法取得這間餐廳的資料");
            return;
        }

        string closed = "";

        System.Text.StringBuilder str = new System.Text.StringBuilder();

        FoodLis.resInfoText[0].text = d.name;
        FoodLis.resInfoText[1].text = d.phoneNum;
        FoodLis.resInfoText[2].text = d.address;

        if (d.openingHours == null)
        {
            str = new System.Text.StringBuilder("無資料 _(´ཀ`」 ∠)_");
        }
        else
        {
            foreach (string s in d.openingHours)
            {
                str.AppendLine(s);
            }
        }

        if (str.ToString().Length <= 1)
        {
            FoodLis.resInfoText[3].text = "無資料 _(´ཀ`」 ∠)_";
        }
        else
        {
            FoodLis.resInfoText[3].text = str.ToString();
        }

        FoodLis.resInfoText[4].text = "評價:" + d.rating.ToString() + "/5";

        if (d.permanentlyClosed)
        {
            closed = "已歇業";
        }
        else if (!d.permanentlyClosed)
        {
            closed = "";
        }

        FoodLis.resInfoText[5].text = closed;

        str = new System.Text.StringBuilder();

        foreach (Reviews s in d.reviews)
        {
            str.AppendLine("評價者: " + s.name);
            str.AppendLine("評價分數: " + s.rating);
            str.AppendLine("留言: " + s.text);
            str.AppendLine("留言時間: " + s.time.ToString("yyyy-MM-dd HH:mm:ss \n\n\n"));
        }
        FoodLis.resInfoText[6].text = str.ToString();

        if (d.openNow == 0)
        {
            FoodLis.resInfoText[7].text = "營業中";
        }
        else if (d.openNow == 1)
        {
            FoodLis.resInfoText[7].text = "已打烊/休息中";
        }
        else
        {
            FoodLis.resInfoText[7].text = "無營業時段資訊";
        }
    }
Пример #10
0
    void JoinRoomCallback(TcpClient.RoomStatus status)
    {
        if (status == NetworkBehaviour.RoomStatus.Created)                          // 成功創建房間 (CreateRoom)
        //Debug.Log("創建成功");
        {
            if (curStage > 1)
            {
                return;                                         // 只能是階段 1
            }
            Ticker.StartTicker(0, () => { ButtonManager.ins.EnterOrCreateRoomOK(true); });
            myInfos.roomName = tmpRoomName;

            Ticker.StartTicker(0, () => { CheckAllSet(); });
        }
        else if (status == NetworkBehaviour.RoomStatus.RoomExists)                  // 房間已存在 (CreateRoom)
        {
            if (curStage > 1)
            {
                return;                                         // 只能是階段 1
            }
            LogUI.Show("房間已存在,請重新輸入");
        }
        else if (status == NetworkBehaviour.RoomStatus.Joined)                      // 成功加入房間 (JoinRoom)
        //Debug.Log("加入成功");
        {
            if (curStage > 1)
            {
                return;                                         // 只能是階段 1
            }
            Ticker.StartTicker(0, () => { ButtonManager.ins.EnterOrCreateRoomOK(false); });
            myInfos.roomName = tmpRoomName;
            Ticker.StartTicker(0, () => { CheckAllSet(); });
        }
        else if (status == NetworkBehaviour.RoomStatus.RoomNotExists)               // 房間不存在 (JoinRoom)
        {
            if (curStage > 1)
            {
                return;                                         // 只能是階段 1
            }
            LogUI.Show("房間不存在,請重新輸入");
        }
        else if (status == NetworkBehaviour.RoomStatus.RoomFulled)
        {
            if (curStage > 1)
            {
                return;                                         // 只能是階段 1
            }
            LogUI.Show("這個房間已滿");
        }
        else if (status == NetworkBehaviour.RoomStatus.Others)
        {
            if (curStage == 4)
            {
                return;                                          // 開始遊戲後不再接收這個指令
            }
            LogUI.Show("這個房間已經開始遊戲");
            Ticker.StartTicker(0, LeaveRoom);
        }
        //else {                                                            // 未知錯誤
        //	LogUI.Show("錯誤");
        //}
        roomWaitForServer = false;
    }
Пример #11
0
 void OnGetLocationFailed(string errorMsg)
 {
     LogUI.Show(errorMsg);
 }
Пример #12
0
 void Awake()
 {
     Instance = this;
     txt      = GetComponentInChildren <Text>();
 }
Пример #13
0
 public void SetDialog(LogUI dialog)
 {
     this.dialog = dialog;
 }