Пример #1
0
    public void PeripheralReceiveMessage(string UUID, byte[] bytes)
    {
        MyDebug.LogGreen("PeripheralReceiveMessage");
        BluetoothMessage msg = new BluetoothMessage(bytes);

        if (msg == null)
        {
            MyDebug.LogYellow("PeripheralReceiveMessage: Message is NULL!");
            return;
        }

        MyDebug.LogGreen("Index:" + msg.index + ", Result:" + msg.result + ", name:" + msg.name);

        if (msg.index == 0)
        {
            UnityEngine.Random.InitState(msg.result);
            CurPeripheralInstance = new PeripheralInstance("", msg.name);
            SetSendMessageFunc(false);
            BLESendMessage(msg);
            GuiController.Instance.CompetitionGUI = GuiFrameID.BluetoothFrame;
            GuiController.Instance.SwitchWrapper(GuiFrameID.BluetoothFightFrame);
        }
        else
        {
            if (BLEReceiveMessage != null)
            {
                BLEReceiveMessage(msg);
            }
        }
    }
Пример #2
0
 private void NotificationAction(string address, string characteristicUUID)
 {
     MyDebug.LogGreen("Subscribe NotificationAction!");
     MyDebug.LogGreen("Address:" + address);
     MyDebug.LogGreen("CharacteristicUUID:" + characteristicUUID);
     StartCoroutine(FirstWrite());
 }
Пример #3
0
    public void CentralReceiveMessage(string address, string characteristic, byte[] bytes)
    {
        MyDebug.LogGreen("CentralReceiveMessage");

        BluetoothMessage msg = new BluetoothMessage(bytes);

        if (msg == null)
        {
            MyDebug.LogYellow("CentralReceiveMessage: Message is NULL!");
            return;
        }

        MyDebug.LogGreen("Index:" + msg.index + ", Result:" + msg.result + ", name:" + msg.name);

        if (msg.index == 0)
        {
            UnityEngine.Random.InitState(msg.result);
            GuiController.Instance.CompetitionGUI = GuiFrameID.BluetoothFrame;
            GuiController.Instance.SwitchWrapper(GuiFrameID.BluetoothFightFrame);
        }
        else
        {
            if (BLEReceiveMessage != null)
            {
                BLEReceiveMessage(msg);
            }
        }
    }
Пример #4
0
    void OnDestroy()
    {
        MyDebug.LogGreen("ReadUUID:" + BluetoothController.Instance.ReadUUID);
        MyDebug.LogGreen("WriteUUID:" + BluetoothController.Instance.WriteUUID);
        MyDebug.LogGreen("ServiceUUID:" + BluetoothController.Instance.ServiceUUID);

        BluetoothController.Instance.OnBluetoothFightFinish();
    }
Пример #5
0
    /// <summary>
    /// 获取游客信息
    /// </summary>
    /// <returns></returns>
    private IEnumerator SilentLogin(System.Action OnSucceed, System.Action <string> OnFail)
    {
        MyDebug.LogGreen("VisitorURL: " + VisitorURL);
        WWW www = new WWW(VisitorURL);

        float responseTime = 0;

        while (!www.isDone && responseTime < TimeOut)
        {
            responseTime += Time.deltaTime;
            yield return(www);
        }

        if (www.isDone)
        {
            LoginResponse response = JsonUtility.FromJson <LoginResponse>(www.text);
            MyDebug.LogGreen("www.text: " + www.text);
            if (response != null)
            {
                if (response.code == (int)CodeID.SUCCESS)
                {
                    m_IsLogining = false;
                    IsNewPlayer  = true;
                    Token        = response.token;
                    UserID       = response.data.id;
                    if (OnSucceed != null)
                    {
                        OnSucceed();
                    }
                    yield break;
                }
                else if (response.code == (int)CodeID.GAME_VERSION_ERROR)
                {
                    MyDebug.LogYellow("Silent Login Fail:" + response.code);
                }
                else
                {
                    MyDebug.LogYellow("Silent Login Fail:" + response.code);
                }
            }
            else
            {
                MyDebug.LogYellow("Silent Login Fail: Message Is Not Response!");
            }
        }
        else
        {
            MyDebug.LogYellow("Silent Login Fail Fail: " + www.error);
        }

        m_IsLogining = false;
        string message = c_LanguageCtrl.GetLanguage("Text_20066");

        if (OnFail != null)
        {
            OnFail(message);
        }
    }
Пример #6
0
 private void PeripheralSendMessage(BluetoothMessage message)
 {
     MyDebug.LogGreen("PeripheralSendMessage");
     MyDebug.LogGreen("index:" + message.index);
     MyDebug.LogGreen("result:" + message.result);
     MyDebug.LogGreen("name:" + message.name);
     MyDebug.LogGreen("Length:" + message.data.Length);
     BluetoothLEHardwareInterface.UpdateCharacteristicValue(ReadUUID, message.data, message.data.Length);
 }
Пример #7
0
    /// <summary>
    /// 获取排行榜详情
    /// </summary>
    /// <param name="form"></param>
    /// <param name="OnSucceed"></param>
    /// <param name="OnFail"></param>
    /// <returns></returns>
    public IEnumerator GetRankDetail(WWWForm form, Action <string> OnSucceed, Action <string> OnFail)
    {
        WWW www = new WWW(DetailURL, form);

        float responseTime = 0;

        while (!www.isDone && responseTime < TimeOut)
        {
            responseTime += Time.deltaTime;
            yield return(www);
        }

        string message = "";

        if (www.isDone)
        {
            GetDetailResponse response = JsonUtility.FromJson <GetDetailResponse>(www.text);
            if (response != null)
            {
                if (response.code == (int)CodeID.SUCCESS)
                {
                    MyDebug.LogGreen("Get Rank Detail Succeed!");
                    if (OnSucceed != null)
                    {
                        OnSucceed(response.data);
                    }
                    yield break;
                }
                else if (response.code == (int)CodeID.GAME_VERSION_ERROR)
                {
                    MyDebug.LogYellow("Get Rank Detail Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20079");
                }
                else
                {
                    MyDebug.LogYellow("Get Rank Detail Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20066");
                }
            }
            else
            {
                MyDebug.LogYellow("Get Rank Detail Fail: Message Is Not Response!");
                message = LanguageController.Instance.GetLanguage("Text_20066");
            }
        }
        else
        {
            MyDebug.LogYellow("Get Rank Detail Fail: Long Time!");
            message = LanguageController.Instance.GetLanguage("Text_20067");
        }

        if (OnFail != null)
        {
            OnFail(message);
        }
    }
Пример #8
0
    private IEnumerator SubscribeCharacteristic()
    {
        MyDebug.LogGreen("Subscribe Characteristic!");
        yield return(new WaitForSeconds(1f));

        BluetoothLEHardwareInterface.SubscribeCharacteristicWithDeviceAddress(BluetoothController.Instance.CurPeripheralInstance.address,
                                                                              BluetoothController.Instance.ServiceUUID,
                                                                              BluetoothController.Instance.ReadUUID, NotificationAction,
                                                                              BluetoothController.Instance.CentralReceiveMessage);
    }
Пример #9
0
    private IEnumerator FirstWrite()
    {
        MyDebug.LogGreen("First Write!");
        yield return(new WaitForSeconds(1f));

        int seed = UnityEngine.Random.Range(1, int.MaxValue);
        BluetoothMessage message = new BluetoothMessage(0, seed, GameManager.Instance.UserName);

        BluetoothController.Instance.SetSendMessageFunc(true);
        BluetoothController.Instance.BLESendMessage(message);
    }
Пример #10
0
    protected override void OnButtonClick(Button btn)
    {
        base.OnButtonClick(btn);

        switch (btn.name)
        {
        case "Bluetooth2StartFrameBtn":
            GuiController.Instance.SwitchWrapperWithScale(GuiFrameID.StartFrame, false);
            break;

        case "BluetoothCentralBtn":
            InitializeBluetooth(true);
            break;

        case "BluetoothPeripheralBtn":
            InitializeBluetooth(false);
            break;

        case "BackFromContentBtn":
            scaning = false;
            BluetoothLEHardwareInterface.RemoveCharacteristics();
            BluetoothLEHardwareInterface.RemoveServices();
            BluetoothLEHardwareInterface.DeInitialize(() =>
            {
                MyDebug.LogGreen("DeInitialize Success!");
            });
            CommonTool.GuiHorizontalMove(bluetoothCategoryContent, Screen.width, MoveID.RightOrUp, canvasGroup, false);
            break;

        case "BackFromScanResultBtn":
        case "BluetoothAdvertisingStopBtn":
            bluetoothPeripheralDetailBg.SetActive(false);
            bluetoothConnectWaiting.SetActive(false);
            bluetoothAdvertisingStopBtn.SetActive(false);
            StopScan();
            break;

        case "BluetoothScanBtn":
            StartScan();
            break;

        case "ConnectCancelBtn":
            bluetoothPeripheralDetailBg.SetActive(false);
            break;

        case "BluetoothReScanBtn":
            ReScan();
            break;

        default:
            MyDebug.LogYellow("Can not find Button: " + btn.name);
            break;
        }
    }
Пример #11
0
 private void CentralSendMessage(BluetoothMessage message)
 {
     MyDebug.LogGreen("CentralSendMessage");
     MyDebug.LogGreen("index:" + message.index);
     MyDebug.LogGreen("result:" + message.result);
     MyDebug.LogGreen("name:" + message.name);
     MyDebug.LogGreen("Length:" + message.data.Length);
     BluetoothLEHardwareInterface.WriteCharacteristic(CurPeripheralInstance.address, ServiceUUID, WriteUUID, message.data, message.data.Length, true, (characteristicUUID) =>
     {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
 }
Пример #12
0
 private void OnReceiveMessage(BluetoothMessage message)
 {
     MyDebug.LogGreen("index: " + message.index + ", result: " + message.result);
     isReceiving = true;
     if (message.index == index)
     {
         int resultInt = 0;
         if (!int.TryParse(result.ToString(), out resultInt))
         {
             resultInt = 0; //被抢答的情况
         }
         lock (curInstance) //倒数第一个是自己的答案,倒数第二个是正确答案,倒数第三个是对方的答案
         {
             curInstance.Insert(curInstance.Count - 1, message.result);
             curInstance.Add(resultInt);
         }
         lock (resultList)
         {
             resultList.Add(curInstance);
         }
         if (resultList.Count == amount)
         {
             if (!message.name.Equals(end))
             {
                 isSending = true;
                 BluetoothController.Instance.BLESendMessage(new BluetoothMessage(index, resultInt, end));
             }
             FightOver();
         }
         else
         {
             if (isSending)
             {
                 StartCoroutine(ShowNextQuestion());
             }
             else
             {
                 isSending = true;
                 BluetoothController.Instance.BLESendMessage(new BluetoothMessage(index, resultInt));
                 StartCoroutine(ShowNextQuestion());
             }
         }
         isSending   = false;
         isReceiving = false;
     }
     else
     {
         string tip = "Index Wrong:" + message.index;
         GuiController.Instance.CurCommonTipInstance = new CommonTipInstance(CommonTipID.Single, tip);
         GuiController.Instance.SwitchWrapper(GuiFrameID.CommonTipFrame, true);
     }
 }
Пример #13
0
 private void ReScan()
 {
     if (isCentral)
     {
         BluetoothLEHardwareInterface.StopScan();
         RemovePeripherals();
         MyDebug.LogGreen("Start ReScaning!");
         BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(new string[] { BluetoothController.Instance.ServiceUUID },
                                                                     (address, name) =>
         {
             AddPeripheral(address, name);
         });
     }
 }
Пример #14
0
 private void InitializeBluetooth(bool isCentral)
 {
     this.isCentral = isCentral;
     BluetoothLEHardwareInterface.Initialize(isCentral, !isCentral,
                                             () =>
     {
         MyDebug.LogGreen("Initialize Success!");
         BluetoothLEHardwareInterface.RemoveCharacteristics();
         BluetoothLEHardwareInterface.RemoveServices();
         bluetoothCategoryContent.SetActive(true);
         RefreshCategoryContent();
         CommonTool.GuiHorizontalMove(bluetoothCategoryContent, Screen.width, MoveID.RightOrUp, canvasGroup, true);
     },
                                             (error) =>
     {
         string message = "";
         if (error.Contains("Not Supported"))
         {
             MyDebug.LogYellow("Not Supported");
             message = LanguageController.Instance.GetLanguage("Text_80009");
         }
         else if (error.Contains("Not Authorized"))
         {
             MyDebug.LogYellow("Not Authorized");
             message = LanguageController.Instance.GetLanguage("Text_80010");
         }
         else if (error.Contains("Powered Off"))
         {
             MyDebug.LogYellow("Powered Off");
             message = LanguageController.Instance.GetLanguage("Text_80011");
         }
         else if (error.Contains("Not Enabled"))
         {
             MyDebug.LogYellow("Not Enabled");
             message = LanguageController.Instance.GetLanguage("Text_80012");
         }
         else
         {
             MyDebug.LogYellow("Central Initialize Fail: " + error);
             message = LanguageController.Instance.GetLanguage("Text_80021");
         }
         GuiController.Instance.CurCommonTipInstance = new CommonTipInstance(CommonTipID.Single, message);
         GuiController.Instance.SwitchWrapper(GuiFrameID.CommonTipFrame, true);
     });
 }
Пример #15
0
    public void DeleteRecord(string fileName, bool withAction = false)
    {
        string fullName = string.Format(fileFullName, fileName);

        if (File.Exists(fullName))
        {
            File.Delete(fullName);
            MyDebug.LogGreen("Delete:" + fileName);

            if (withAction && OnRecordDeleted != null)
            {
                OnRecordDeleted();
            }
        }
        else
        {
            MyDebug.LogYellow("The file does not exist!!!");
        }
    }
Пример #16
0
    public static void RecoverImageIndex()
    {
        return;

        int num = 0;
        Dictionary <string, string> imageDict = InitImageData();

        for (int i = 0; i < Selection.gameObjects.Length; i++)
        {
            Image[] imageArray = Selection.gameObjects[i].GetComponentsInChildren <Image>(true);
            for (int j = 0; j < imageArray.Length; j++)
            {
                if (imageDict.ContainsKey(imageArray[j].name))
                {
                    imageArray[j].index = imageDict[imageArray[j].name];
                    num++;
                }
            }
        }
        MyDebug.LogGreen("num:" + num);
    }
Пример #17
0
    public void OnBluetoothFightFinish()
    {
        MyDebug.LogGreen("OnBluetoothFightFinish");
        if (isCentral)
        {
            MyDebug.LogGreen("OnBluetoothFightFinish:Central");
            BluetoothLEHardwareInterface.UnSubscribeCharacteristic(CurPeripheralInstance.address,
                                                                   ServiceUUID,
                                                                   ReadUUID,
                                                                   (characteristic) =>
            {
                MyDebug.LogGreen("UnSubscribeCharacteristic Success :" + characteristic);
            });

            BluetoothLEHardwareInterface.DisconnectPeripheral(CurPeripheralInstance.address,
                                                              (disconnectAddress) =>
            {
                MyDebug.LogGreen("DisconnectPeripheral Success:" + disconnectAddress);
            });
        }
        else
        {
            MyDebug.LogGreen("OnBluetoothFightFinish:Peripheral");
            BluetoothLEHardwareInterface.StopAdvertising(() =>
            {
                MyDebug.LogGreen("Stop Advertising!");
            });
        }

        BluetoothLEHardwareInterface.RemoveCharacteristics();
        BluetoothLEHardwareInterface.RemoveServices();

        BluetoothLEHardwareInterface.DeInitialize(() =>
        {
            MyDebug.LogGreen("DeInitialize Success!");
        });
        BluetoothLEHardwareInterface.BluetoothEnable(false);
    }
Пример #18
0
    private IEnumerator CreateUserName(string name)
    {
        WWWForm form = new WWWForm();

        form.AddField("userId", GameManager.Instance.UserID);
        form.AddField("jwttoken", GameManager.Instance.Token);
        form.AddField("userName", name);
        WWW www = new WWW(NameURL, form);

        float responseTime = 0;

        while (!www.isDone && responseTime < TimeOut)
        {
            responseTime += Time.deltaTime;
            yield return(www);
        }

        string message = "";

        if (www.isDone)
        {
            CreateNameResponse response = JsonUtility.FromJson <CreateNameResponse>(www.text);
            if (response != null)
            {
                if (response.code == (int)CodeID.SUCCESS)
                {
                    MyDebug.LogGreen("Create User Name Succeed:" + name);
                    isCreating = false;
                    GameManager.Instance.IsNewPlayer = false;
                    GameManager.Instance.UserName    = name;
                    GuiController.Instance.SwitchWrapper(GuiFrameID.None);
                    yield break;
                }
                else if (response.code == (int)CodeID.GAME_VERSION_ERROR)
                {
                    MyDebug.LogYellow("Create User Name Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20079");
                }
                else if (response.code == (int)CodeID.NAME_FILTER_ERROR)
                {
                    MyDebug.LogYellow("Create User Name Fail: Illegal");
                    message = LanguageController.Instance.GetLanguage("Text_20073");
                }
                else if (response.code == (int)CodeID.NAME_REPEAT_ERROR)
                {
                    MyDebug.LogYellow("Create User Name Fail: Repeat");
                    message = LanguageController.Instance.GetLanguage("Text_20074");
                }
                else
                {
                    MyDebug.LogYellow("Create User Name Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20066");
                }
            }
            else
            {
                MyDebug.LogYellow("Create User Name: Message Is Not Response!");
                message = LanguageController.Instance.GetLanguage("Text_20066");
            }
        }
        else
        {
            MyDebug.LogYellow("Create User Name Fail: Long Time!");
            message = LanguageController.Instance.GetLanguage("Text_20067");
        }
        isCreating = false;
        GuiController.Instance.CurCommonTipInstance = new CommonTipInstance(CommonTipID.Splash, message);
        GuiController.Instance.SwitchWrapper(GuiFrameID.CommonTipFrame, true);
    }
Пример #19
0
    /// <summary>
    /// 上传排行榜信息
    /// </summary>
    /// <returns></returns>
    public IEnumerator UploadRecord(WWWForm form, Action <string> OnSuccees, Action <string> OnFail)
    {
        WWW www = new WWW(UploadURL, form);

        float responseTime = 0;

        while (!www.isDone && responseTime < TimeOut)
        {
            responseTime += Time.deltaTime;
            yield return(www);
        }

        string message = "";

        if (www.isDone)
        {
            UploadDataResponse response = JsonUtility.FromJson <UploadDataResponse>(www.text);
            if (response != null)
            {
                if (response.code == (int)CodeID.SUCCESS)
                {
                    MyDebug.LogGreen("Upload Rank Data Succeed!");
                    if (response.data.rank > 0)
                    {
                        message = LanguageController.Instance.GetLanguage("Text_20068");
                        message = string.Format(message, response.data.rank);
                    }
                    else
                    {
                        MyDebug.LogYellow("Upload Rank Data Fail:" + response.code);
                        message = LanguageController.Instance.GetLanguage("Text_20070");
                    }

                    if (OnSuccees != null)
                    {
                        OnSuccees(message);
                    }
                    yield break;
                }
                else if (response.code == (int)CodeID.GAME_VERSION_ERROR)
                {
                    MyDebug.LogYellow("Upload Rank Data Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20079");
                }
                else
                {
                    MyDebug.LogYellow("Upload Rank Data Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20066");
                }
            }
            else
            {
                MyDebug.LogYellow("Upload Rank Data Fail: Message Is Not Response!");
                message = LanguageController.Instance.GetLanguage("Text_20066");
            }
        }
        else
        {
            MyDebug.LogYellow("Upload Rank Data Fail: Long Time!");
            message = LanguageController.Instance.GetLanguage("Text_20067");
        }

        if (OnFail != null)
        {
            OnFail(message);
        }
    }
Пример #20
0
    private void StartScan()
    {
        if (scaning)
        {
            MyDebug.LogYellow("Scaning!!!");
            return;
        }
        scaning = true;

        BluetoothLEHardwareInterface.RemoveCharacteristics();
        BluetoothLEHardwareInterface.RemoveServices();

        CategoryInstance curCategoryInstance = new CategoryInstance(curPatternID, curAmountID, curSymbolID, curDigitID, curOperandID);

        FightController.Instance.CurCategoryInstance = curCategoryInstance;

        string serviceUUID = (int)curAmountID + "" + (int)curSymbolID + "" + (int)curDigitID + "0";
        string readUUID    = (int)curAmountID + "" + (int)curSymbolID + "" + (int)curDigitID + "1";
        string writeUUID   = (int)curAmountID + "" + (int)curSymbolID + "" + (int)curDigitID + "2";

        BluetoothController.Instance.ServiceUUID = BluetoothLEHardwareInterface.FullUUID(serviceUUID);
        BluetoothController.Instance.ReadUUID    = BluetoothLEHardwareInterface.FullUUID(readUUID);
        BluetoothController.Instance.WriteUUID   = BluetoothLEHardwareInterface.FullUUID(writeUUID);

        MyDebug.LogGreen("ServiceUUID:" + BluetoothController.Instance.ServiceUUID);
        MyDebug.LogGreen("ReadUUID:" + BluetoothController.Instance.ReadUUID);
        MyDebug.LogGreen("WriteUUID:" + BluetoothController.Instance.WriteUUID);

        if (isCentral)
        {
            MyDebug.LogGreen("Central Start Scaning!");
            bluetoothScanResultContent.SetActive(true);
            RefreshScanResultContent();
            CommonTool.GuiHorizontalMove(bluetoothScanResultContent, Screen.width, MoveID.RightOrUp, canvasGroup, true);
            BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(new string[] { BluetoothController.Instance.ServiceUUID },
                                                                        (address, name) =>
            {
                AddPeripheral(address, name);
            });
        }
        else
        {
            MyDebug.LogGreen("Peripheral Start Scaning!");
            BluetoothLEHardwareInterface.PeripheralName(GameManager.Instance.UserName);
            MyDebug.LogGreen("PeripheralName:" + GameManager.Instance.UserName);

            BluetoothLEHardwareInterface.CreateCharacteristic(BluetoothController.Instance.ReadUUID,
                                                              BluetoothLEHardwareInterface.CBCharacteristicProperties.CBCharacteristicPropertyRead |
                                                              BluetoothLEHardwareInterface.CBCharacteristicProperties.CBCharacteristicPropertyNotify,
                                                              BluetoothLEHardwareInterface.CBAttributePermissions.CBAttributePermissionsReadable, null, 0, null);
            MyDebug.LogGreen("CreateCharacteristic:Read!");

            BluetoothLEHardwareInterface.CreateCharacteristic(BluetoothController.Instance.WriteUUID,
                                                              BluetoothLEHardwareInterface.CBCharacteristicProperties.CBCharacteristicPropertyWrite,
                                                              BluetoothLEHardwareInterface.CBAttributePermissions.CBAttributePermissionsWriteable, null, 0,
                                                              BluetoothController.Instance.PeripheralReceiveMessage);
            MyDebug.LogGreen("CreateCharacteristic:Write!");

            BluetoothLEHardwareInterface.CreateService(BluetoothController.Instance.ServiceUUID, true, (message) =>
            {
                MyDebug.LogGreen("Create Service Success:" + message);
            });
            MyDebug.LogGreen("CreateService!");

            BluetoothLEHardwareInterface.StartAdvertising(() =>
            {
                MyDebug.LogGreen("Start Advertising!");
                bluetoothScanResultContent.SetActive(true);
                RefreshScanResultContent();
                StartCoroutine(AdvertisingCountDown());
                CommonTool.GuiHorizontalMove(bluetoothScanResultContent, Screen.width, MoveID.RightOrUp, canvasGroup, true);
            });
        }
    }
Пример #21
0
    /// <summary>
    /// 活动报名
    /// </summary>
    /// <param name="form"></param>
    /// <param name="OnSuccees"></param>
    /// <param name="OnFail"></param>
    /// <returns></returns>
    public IEnumerator EnrollActivity(WWWForm form, Action <CategoryInstance> OnSuccees, Action <string> OnFail)
    {
        WWW www = new WWW(EnrollURL, form);

        float responseTime = 0;

        while (!www.isDone && responseTime < TimeOut)
        {
            responseTime += Time.deltaTime;
            yield return(www);
        }

        string message = "";

        if (www.isDone)
        {
            EnrollActivityResponse response = JsonUtility.FromJson <EnrollActivityResponse>(www.text);
            if (response != null)
            {
                if (response.code == (int)CodeID.SUCCESS)
                {
                    MyDebug.LogGreen("Enroll Activity Succeed!");

                    if (OnSuccees != null)
                    {
                        CategoryInstance instance = ConvertToCategory(response.data);
                        OnSuccees(instance);
                    }
                    yield break;
                }
                else if (response.code == (int)CodeID.JOIN_TIME_ERROR)
                {
                    MyDebug.LogYellow("Enroll Activity Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20081");
                }
                else if (response.code == (int)CodeID.GAME_VERSION_ERROR)
                {
                    MyDebug.LogYellow("Enroll Activity Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20079");
                }
                else
                {
                    MyDebug.LogYellow("Enroll Activity Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20066");
                }
            }
            else
            {
                MyDebug.LogYellow("Enroll Activity Fail: Message Is Not Response!");
                message = LanguageController.Instance.GetLanguage("Text_20066");
            }
        }
        else
        {
            MyDebug.LogYellow("Enroll Activity Fail: Long Time!");
            message = LanguageController.Instance.GetLanguage("Text_20067");
        }

        if (OnFail != null)
        {
            OnFail(message);
        }
    }
Пример #22
0
    /// <summary>
    /// 拉取排行榜信息
    /// </summary>
    /// <param name="form"></param>
    /// <param name="OnSucceed"></param>
    /// <returns></returns>
    public IEnumerator DownloadRecord(CategoryInstance instance, Action <ArrayList> OnSucceed, Action <string> OnFail)
    {
        if (!CanRefreshRankData(instance))
        {
            List <RankInstance> instances;
            rankDataDict.TryGetValue(instance, out instances);
            if (instances != null && instances.Count > 0)
            {
                if (OnSucceed != null)
                {
                    ArrayList dataList = new ArrayList(instances);
                    OnSucceed(dataList);
                }
            }
            else
            {
                if (OnFail != null)
                {
                    string msg = LanguageController.Instance.GetLanguage("Text_20071");
                    OnFail(msg);
                }
            }
            yield break;
        }

        WWWForm form = new WWWForm();

        form.AddField("userId", GameManager.Instance.UserID);
        form.AddField("jwttoken", GameManager.Instance.Token);
        form.AddField("model", (int)instance.patternID + 1);
        form.AddField("num", (int)instance.amountID + 1);
        form.AddField("calcu", (int)instance.symbolID + 1);
        form.AddField("digit", (int)instance.digitID + 2);
        form.AddField("operate", (int)instance.operandID + 2);

        WWW www = new WWW(DownloadURL, form);

        float responseTime = 0;

        while (!www.isDone && responseTime < TimeOut)
        {
            responseTime += Time.deltaTime;
            yield return(www);
        }

        string message = "";

        if (www.isDone)
        {
            DownloadDataResponse response = JsonUtility.FromJson <DownloadDataResponse>(www.text);
            if (response != null)
            {
                if (response.code == (int)CodeID.SUCCESS)
                {
                    MyDebug.LogGreen("Download Rank Data Succeed!");
                    lastRefreshTimeDict[instance] = DateTime.Now;
                    if (response.data != null && response.data.Count > 0)
                    {
                        rankDataDict[instance] = response.data;
                        if (OnSucceed != null)
                        {
                            ArrayList dataList = new ArrayList(response.data);
                            OnSucceed(dataList);
                        }
                        yield break;
                    }
                    else
                    {
                        message = LanguageController.Instance.GetLanguage("Text_20071");
                    }
                }
                else if (response.code == (int)CodeID.GAME_VERSION_ERROR)
                {
                    MyDebug.LogYellow("Download Rank Data Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20079");
                }
                else
                {
                    MyDebug.LogYellow("Download Rank Data Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20066");
                }
            }
            else
            {
                MyDebug.LogYellow("Download Rank Data Fail: Message Is Not Response!");
                message = LanguageController.Instance.GetLanguage("Text_20066");
            }
        }
        else
        {
            MyDebug.LogYellow("Download Rank Data Fail: Long Time!");
            message = LanguageController.Instance.GetLanguage("Text_20067");
        }

        if (OnFail != null)
        {
            OnFail(message);
        }
    }
Пример #23
0
    private void ConnectToPeripheral(BaseEventData evenData)
    {
        MyDebug.LogGreen("ConnectToPeripheral");
        BluetoothLEHardwareInterface.StopScan();
        BluetoothController.Instance.CurPeripheralInstance = content;
        bluetoothConnectWaiting.SetActive(true);
        StartCoroutine(ConnectCountDown());
        BluetoothLEHardwareInterface.ConnectToPeripheral(BluetoothController.Instance.CurPeripheralInstance.address, null, null,
                                                         (address, serviceUUID, characteristicUUID) =>
        {
            MyDebug.LogGreen("_Address:" + address);
            MyDebug.LogGreen("_ServiceUUID:" + serviceUUID);
            MyDebug.LogGreen("_CharacteristicUUID:" + characteristicUUID);

            if (BluetoothController.Instance.IsEqualUUID(serviceUUID, BluetoothController.Instance.ServiceUUID))
            {
                MyDebug.LogGreen("Address:" + address);
                MyDebug.LogGreen("ServiceUUID:" + serviceUUID);

                if (BluetoothController.Instance.IsEqualUUID(characteristicUUID, BluetoothController.Instance.ReadUUID))
                {
                    MyDebug.LogGreen("CharacteristicUUID:" + characteristicUUID);
                    receiveReadID = true;
                    if (receiveWriteID)
                    {
                        receiveReadID  = false;
                        receiveWriteID = false;
                        StartCoroutine(SubscribeCharacteristic());
                    }
                }
                else if (BluetoothController.Instance.IsEqualUUID(characteristicUUID, BluetoothController.Instance.WriteUUID))
                {
                    MyDebug.LogGreen("CharacteristicUUID:" + characteristicUUID);
                    receiveWriteID = true;
                    if (receiveReadID)
                    {
                        receiveReadID  = false;
                        receiveWriteID = false;
                        StartCoroutine(SubscribeCharacteristic());
                    }
                }
            }
        },
                                                         (address) =>
        {
            // this will get called when the device disconnects
            // be aware that this will also get called when the disconnect
            // is called above. both methods get call for the same action
            // this is for backwards compatibility
            if (GuiController.Instance.CurGUI == GuiFrameID.BluetoothFrame || GuiController.Instance.CurGUI == GuiFrameID.BluetoothFightFrame)
            {
                MyDebug.LogWhite("Peripheral Disconnect!");
                string tip = LanguageController.Instance.GetLanguage("Text_80019");
                GuiController.Instance.CurCommonTipInstance = new CommonTipInstance(CommonTipID.Single, tip);
                GuiController.Instance.SwitchWrapper(GuiFrameID.CommonTipFrame, true);
                if (GuiController.Instance.CurGUI == GuiFrameID.BluetoothFrame)
                {
                    StopAllCoroutines();
                    detailWin.SetActive(false);
                }
            }
        });
    }