コード例 #1
0
    /// <summary>
    /// Buy Product
    /// </summary>
    /// <param name="productId">Id of IAP pack</param>
    /// <param name="callback">Buy callback, if callback is NULL, the defaut buy callback from InitializePurchasing will be use</param>
    public void BuyProductID(string productId, UnityAction <Product> callback = null)
    {
        if (IsInitialized())
        {
            Product product = m_StoreController.products.WithID(productId);

            if (product != null && product.availableToPurchase)
            {
                if (callback != null)
                {
                    // Override purchase callback
                    buyProductCallback = callback;
                }
                else
                {
                    buyProductCallback = buyProductCallbackDefault;
                }

                m_StoreController.InitiatePurchase(product);

                VKDebug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
            }
            else
            {
                VKDebug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
            }
        }
        else
        {
            VKDebug.Log("BuyProductID FAIL. Not initialized or Callback is null.");
        }
    }
コード例 #2
0
    public static void WriteBinaryToFile(string fileName, byte[] newData)
    {
        VKDebug.Log("Write Binary File To : " + fileName);
        FileStream   file = File.Create(GetPath(fileName));
        BinaryWriter bw   = new BinaryWriter(file);

        bw.Write(newData);
        bw.Close();
        file.Close();
    }
コード例 #3
0
    protected void HubUpdateJackpot(Hub hub, MethodCallMessage msg)
    {
        VKDebug.Log(msg.Arguments[0].ToString());
        jackpots = LitJson.JsonMapper.ToObject <Dictionary <string, double> >(msg.Arguments[0].ToString());

        if (OnSRSHubEvent != null)
        {
            OnSRSHubEvent.Invoke(SRSConst.UPDATE_JACKPOT, msg.Arguments);
        }
    }
コード例 #4
0
    protected void RaiseWebServiceResponse(WebServiceCode.Code code, WebServiceStatus.Status status, string data)
    {
        if (OnWebServiceResponse != null)
        {
            OnWebServiceResponse(code, status, data);
            VKDebug.Log("Reponse: " + code.ToString() + "  " + data, VKCommon.HEX_ORANGE);
        }

        onWebServiceResponseLua.Invoke(code, status, data);
    }
コード例 #5
0
 public void ClearCache()
 {
     if (Caching.ClearCache())
     {
         VKDebug.Log("Successfully cleaned the cache.");
     }
     else
     {
         VKDebug.Log("Cache is being used.");
     }
 }
コード例 #6
0
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        m_StoreController        = controller;
        m_StoreExtensionProvider = extensions;

        if (initializedCallback != null)
        {
            initializedCallback();
        }

        VKDebug.Log("On Initialized Success");
    }
コード例 #7
0
 public Product[] GetAllProducts()
 {
     if (IsInitialized())
     {
         return(m_StoreController.products.all);
     }
     else
     {
         VKDebug.Log("IAP is not Init, return null");
         return(null);
     }
 }
コード例 #8
0
        protected override void SendImpl(string json)
        {
#if UNITY_EDITOR
            if (!string.IsNullOrEmpty(json))
            {
                VKDebug.Log(json, VKCommon.HEX_ORANGE);
            }
#endif

            if (wSocket != null && wSocket.IsOpen)
            {
                wSocket.Send(json);
            }
        }
コード例 #9
0
    public void SetValueText(VipPoint vp)
    {
        try
        {
            for (int i = 0; i < vp.ListVippoint.Count; i++)
            {
                string textValue = "";

                if (vp.ListVippoint[i].Status == 0)
                {
                    textValue = "NHẬN QUÀ";
                    int rewardID = vp.ListVippoint[i].RewardID;
                    int index    = i;

                    BtnPoints[i].onClick.AddListener(() => { OnClickReward(rewardID, index); });
                    BtnPoints[i].interactable = true;
                }
                else if (vp.ListVippoint[i].Status == 1)
                {
                    textValue = "<color=white>ĐÃ NHẬN QUÀ</color>";
                }
                else
                {
                    textValue = vp.ListVippoint[i].LevelPoint.ToString();
                }

                Points[i].text     = textValue;
                Points[i + 9].text = vp.ListVippoint[i].LevelPoint.ToString();
            }

            string[] lvPoints = vp.LevelPoint.Split('/');

            curPoint.text  = lvPoints[0];
            nextPoint.text = lvPoints[1];
            sumPoint.text  = lvPoints[2];

            int idxIcon = getIndexIcon(vp.Vippoint);
            iconVip.sprite = iconVips[idxIcon];
            iconVip.gameObject.SetActive(true);

            SetValueSlider(int.Parse(lvPoints[2]));
        }
        catch (Exception ex)
        {
            VKDebug.Log(ex.Message);
        }
    }
コード例 #10
0
    public void HandleJoinRoom(object[] data)
    {
        UILayerController.Instance.HideLoading();

        VKDebug.Log(data[0].ToString(), VKCommon.HEX_YELLOW);

        string json = LitJson.JsonMapper.ToJson(data[0]);
        SRSSlot25LineAccount account = JsonUtility.FromJson <SRSSlot25LineAccount>(json);

        _server.OnSRSEvent    = null;
        _server.OnSRSHubEvent = null;

        UILayerController.Instance.ShowLayer(UILayerKey.LGameSlot25Line, _assetBundleConfig.name, (layer) =>
        {
            ClearUI();
            ((LGameSlot25Line)layer).Init(_config, _server, account, _assetBundleConfig, roomIdSelected, moneyType);
        });
    }
コード例 #11
0
 public static string LoadTextFromFile(string fileName)
 {
     VKDebug.Log("Load Text File From : " + fileName);
     try
     {
         FileStream   file = File.OpenRead(GetPath(fileName));
         StreamReader rd   = new StreamReader(file);
         string       data = rd.ReadToEnd();
         rd.Close();
         file.Close();
         return(data);
     }
     catch (Exception ex)
     {
         VKDebug.Log("Error when read text file from " + GetPath(fileName) + " with exception : " + ex.Message);
         return(null);
     }
 }
コード例 #12
0
        void WSocket_OnMessage(WebSocket.WebSocket webSocket, string message)
        {
            if (webSocket != wSocket)
            {
                return;
            }

#if UNITY_EDITOR
            VKDebug.Log(message, VKCommon.HEX_GREEN);
#endif

            IServerMessage msg = TransportBase.Parse(Connection.JsonEncoder, message);

            if (msg != null)
            {
                Connection.OnMessage(msg);
            }
        }
コード例 #13
0
    public void RestorePurchases(UnityAction <bool> callback = null)
    {
        if (!IsInitialized())
        {
            VKDebug.Log("RestorePurchases FAIL. Not initialized.");
            return;
        }

        if (isRestoringPurchases)
        {
            VKDebug.Log("Restoring Purchases");
            return;
        }

        if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.OSXPlayer)
        {
            VKDebug.Log("RestorePurchases started ...");

            isRestoringPurchases = true;
            var apple = m_StoreExtensionProvider.GetExtension <IAppleExtensions>();

            apple.RestoreTransactions((result) =>
            {
                VKDebug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");

                isRestoringPurchases = false;

                if (callback != null)
                {
                    callback(result);
                }
            });
        }
        else
        {
            VKDebug.Log("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
        }
    }
コード例 #14
0
    public static void SaveTextureToFile(Texture2D texture, string filename)
    {
        string path = GetPath(filename);

        try
        {
            if (filename.Contains(".png"))
            {
                File.WriteAllBytes(path, texture.EncodeToPNG());
            }
            else if (filename.Contains(".jpg"))
            {
                File.WriteAllBytes(path, texture.EncodeToJPG());
            }

            VKDebug.Log("Saved Data to: " + path.Replace("/", "\\"));
        }
        catch (Exception e)
        {
            VKDebug.LogWarning("Failed To Save Data to: " + path.Replace("/", "\\"));
            VKDebug.LogWarning("Error: " + e.Message);
        }
    }
コード例 #15
0
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        bool validPurchase = true;

#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
        try
        {
            //@ToDo
            //var result = validator.Validate(args.purchasedProduct.receipt);

            //VKDebug.Log("********** Receipt is valid **********\n");
            //foreach (IPurchaseReceipt productReceipt in result)
            //{
            //    VKDebug.Log(string.Format("Product ID: {0}\nPurchased date: {1}\nReceipt: {2}", productReceipt.productID, productReceipt.purchaseDate, productReceipt));
            //}
            //VKDebug.Log("**************************************\n");
        }
        catch (IAPSecurityException e)
        {
            validPurchase = false;
            VKDebug.Log(string.Format("Invalid receipt: {0}", e.Message));
        }
#endif

        if (validPurchase)
        {
            if (buyProductCallback != null)
            {
                buyProductCallback.Invoke(args.purchasedProduct);
            }
        }

        // Return a flag indicating whether this product has completely been received, or if the application needs
        // to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
        // saving purchased products to the cloud, and when that save is delayed.
        return(PurchaseProcessingResult.Complete);
    }
コード例 #16
0
    public void OnInitCallBack()
    {
        if (FB.IsInitialized)
        {
            // Signal an app activation App Event
            FB.ActivateApp();
            // Continue with Facebook SDK
            if (FB.IsLoggedIn)
            {
                FB.LogOut();
            }

            if (OnFacebookResult != null)
            {
                OnFacebookResult(FacebookAction.Init, null, null);
            }

            Debug.Log("Init FB success");
        }
        else
        {
            VKDebug.Log("Failed to Initialize the Facebook SDK");
        }
    }
コード例 #17
0
    IEnumerator ISendRequestOther(string code, string url, Dictionary <string, string> datas, int method)
    {
        HTTPMethods httpMethod = HTTPMethods.Post;

        if (method == 1)
        {
            httpMethod = HTTPMethods.Post;
        }
        else
        {
            httpMethod = HTTPMethods.Get;
        }

        // request response
        bool   isDone       = false;
        string responseData = "";

        WebServiceStatus.Status responseStatus = WebServiceStatus.Status.INTERNET_ERROR;

        VKDebug.Log("Send Url: " + url, VKCommon.HEX_ORANGE);
        var request = new HTTPRequest(new Uri(url), httpMethod, (req, res) =>
        {
            switch (req.State)
            {
            case HTTPRequestStates.Finished:
                if (res.StatusCode == 200)     // 200 is ok
                {
                    responseData   = res.DataAsText;
                    responseStatus = CheckError(responseData);

                    switch (code)
                    {
                    case "SignUp":
                    case "SignIn":
                    case "SignInFacebook":
                    case "UpdateName":
                        _gvar = res;
                        break;
                    }
                }
                else
                {
                    responseStatus = WebServiceStatus.Status.ERROR;
                }
                break;

            case HTTPRequestStates.ConnectionTimedOut:
            case HTTPRequestStates.TimedOut:
                responseStatus = WebServiceStatus.Status.INTERNET_ERROR;
                UILayerController.Instance.HideLoading();
                if (CheckLostInternetSoFar())
                {
                    if (isActivePopupError)
                    {
                        LPopup.OpenPopupTop("ERROR", "Network Error!");
                    }
                    RaiseWebServiceResponseCodeString(code, WebServiceStatus.Status.INTERNET_ERROR, "");
                }
                break;

            default:
                responseStatus = WebServiceStatus.Status.ERROR;
                break;
            }

            isDone = true;
        });

        // add data post
        request.AddHeader("Content-Type", "application/json");
        if (httpMethod == HTTPMethods.Post && datas != null && datas.Count > 0)
        {
            foreach (var item in datas)
            {
                request.AddField(item.Key, item.Value);
            }
        }

#if !BESTHTTP_DISABLE_COOKIES && (!UNITY_WEBGL || UNITY_EDITOR)
        // add header and cookie
        request.IsCookiesEnabled = true;
        if (_gvar != null)
        {
            request.Cookies = _gvar.Cookies;
        }
#endif
        request.Timeout = new TimeSpan(0, 0, TIME_OUT);
        request.Send();

        yield return(new WaitUntil(() => isDone));

        RaiseWebServiceResponseCodeString(code, responseStatus, responseData);
    }
コード例 #18
0
    IEnumerator ISendRequest(WebServiceCode.Code code, BaseRequest data, HTTPMethods httpMethod)
    {
        string url = GetUrl(code);

        // add data get
        if (data != null && httpMethod == HTTPMethods.Get)
        {
            url += data.GetData();
        }

        // request response
        bool   isDone       = false;
        string responseData = "";

        WebServiceStatus.Status responseStatus = WebServiceStatus.Status.INTERNET_ERROR;

        VKDebug.Log("Send Url: " + url, VKCommon.HEX_ORANGE);
        var request = new HTTPRequest(new Uri(url), httpMethod, (req, res) =>
        {
            switch (req.State)
            {
            case HTTPRequestStates.Finished:
                if (res.StatusCode == 200)     // 200 is ok
                {
                    VKDebug.LogColorRed("Status true");

                    responseData   = res.DataAsText;
                    responseStatus = CheckError(responseData);

                    switch (code)
                    {
                    case WebServiceCode.Code.SignUp:
                    case WebServiceCode.Code.SignIn:
                    case WebServiceCode.Code.SignInFacebook:
                    case WebServiceCode.Code.UpdateName:
                        _gvar = res;
                        break;
                    }
                }
                else
                {
                    responseStatus = WebServiceStatus.Status.ERROR;
                }
                break;

            case HTTPRequestStates.ConnectionTimedOut:
            case HTTPRequestStates.TimedOut:
                responseStatus = WebServiceStatus.Status.INTERNET_ERROR;
                UILayerController.Instance.HideLoading();
                if (CheckLostInternetSoFar())
                {
                    VKDebug.LogError(code + "Offcode TimeOUt");
                    if (isActivePopupError)
                    {
                        LPopup.OpenPopupTop("ERROR", "Network Error!");
                    }
                    RaiseWebServiceResponse(code, WebServiceStatus.Status.INTERNET_ERROR, "");
                }
                break;

            default:
                responseStatus = WebServiceStatus.Status.ERROR;
                break;
            }

            isDone = true;
        });

        // add data post
        request.AddHeader("Content-Type", "application/json");
        if (data != null && httpMethod == HTTPMethods.Post)
        {
            data.AddData(request);
        }

#if !BESTHTTP_DISABLE_COOKIES && (!UNITY_WEBGL || UNITY_EDITOR)
        // add header and cookie
        request.IsCookiesEnabled = true;
        if (_gvar != null)
        {
            request.Cookies = _gvar.Cookies;
        }
#endif
        request.Timeout = new TimeSpan(0, 0, TIME_OUT);
        request.Send();

        yield return(new WaitUntil(() => isDone));

        //switch(code)
        //{
        //    // Event Game
        //    case WebServiceCode.Code.GetAllJackpot:
        //    case WebServiceCode.Code.GetBigWinPlayers:
        //    case WebServiceCode.Code.GetBigJackpotInfoFarm:
        //    case WebServiceCode.Code.GetBigJackpotHistoryFarm:
        //    case WebServiceCode.Code.GetBigJackpotInfoMafia:
        //    case WebServiceCode.Code.GetBigJackpotHistoryMafia:
        //    case WebServiceCode.Code.GetBigJackpotInfo25Line:
        //    case WebServiceCode.Code.GetBigJackpotHistory25Line:
        //        break;
        //    default:
        //        VKDebug.Log("Response Data: " + responseData, VKCommon.HEX_GREEN);
        //        break;
        //}
        RaiseWebServiceResponse(code, responseStatus, responseData);
    }
コード例 #19
0
 public void OnInitializeFailed(InitializationFailureReason error)
 {
     VKDebug.Log("OnInitializeFailed " + error);
 }
コード例 #20
0
    IEnumerator DownloadAsset(AssetBundleSettingItem assetConfig, GameObject gDownload, Text txtProgress, Image imgProgress, bool showDownload, Action callback)
    {
        // Show UI download
        if (showDownload)
        {
            gDownload.SetActive(true);
            if (txtProgress != null)
            {
                txtProgress.text = "0%";
            }

            if (imgProgress != null)
            {
                imgProgress.fillAmount = 0;
            }
        }

        while (!Caching.ready)
        {
            yield return(null);
        }


        string url = assetSetting.GetLink() + assetConfig.name;

        WWW www = WWW.LoadFromCacheOrDownload(url, Hash128.Parse(assetConfig.hash));

        while (!www.isDone)
        {
            if (showDownload)
            {
                if (imgProgress != null)
                {
                    imgProgress.fillAmount = www.progress;
                }
                if (txtProgress != null)
                {
                    txtProgress.text = (www.progress * 100).ToString("F1") + "%";
                }
            }

            yield return(new WaitForEndOfFrame());
        }

        // Show download done
        if (imgProgress)
        {
            if (imgProgress != null)
            {
                imgProgress.fillAmount = 1;
            }
            if (txtProgress != null)
            {
                txtProgress.text = "100%";
            }
        }

        if (!string.IsNullOrEmpty(www.error))
        {
            VKDebug.Log("Error while Downloading Data: " + url + " msg: " + www.error);
            LPopup.OpenPopupTop("Lỗi", "Không tải được game xin vui lòng thử lại!");
            yield return(null);
        }
        else
        {
            VKDebug.Log("Download Asset Success");
            AssetBundle assetBundle = www.assetBundle;

            if (assetBundle == null)
            {
                VKDebug.Log("Game được tải không đúng" + www.error);
                LPopup.OpenPopupTop("Lỗi", "Không tải được game xin vui lòng thử lại!");
            }
            else
            {
                // load game object
                if (asset.ContainsKey(assetConfig.name))
                {
                    asset[assetConfig.name] = assetBundle;
                }
                else
                {
                    asset.Add(assetConfig.name, assetBundle);
                }

                //Database.Instance.localData.UpdateBundle(assetConfig);
                Database.Instance.SaveLocalData();

                callback.Invoke();
            }
        }

        gDownload.SetActive(false);
        downloading.Remove(assetConfig.name);
    }
コード例 #21
0
 public void OnPurchaseFailed(Product i, PurchaseFailureReason p)
 {
     VKDebug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", i.definition.storeSpecificId, p));
 }
コード例 #22
0
    IEnumerator ISendRequestOther(string code, string url, Dictionary <string, string> datas, int method, Action <string> callback)
    {
        HTTPMethods httpMethod = HTTPMethods.Get;

        // request response
        bool   isDone       = false;
        string responseData = "";

        WebServiceStatus.Status responseStatus = WebServiceStatus.Status.INTERNET_ERROR;

        VKDebug.Log("Send Url: " + url, VKCommon.HEX_ORANGE);
        var request = new HTTPRequest(new Uri(url), httpMethod, (req, res) =>
        {
            switch (req.State)
            {
            case HTTPRequestStates.Finished:
                if (res.StatusCode == 200)     // 200 is ok
                {
                    responseData   = res.DataAsText;
                    responseStatus = CheckError(responseData);

                    callback.Invoke(responseData);
                }
                else
                {
                    responseStatus = WebServiceStatus.Status.ERROR;
                }
                break;

            case HTTPRequestStates.ConnectionTimedOut:
            case HTTPRequestStates.TimedOut:
                responseStatus = WebServiceStatus.Status.INTERNET_ERROR;
                LPopup.OpenPopupTop("Thông báo", "Đã xảy ra lỗi vui lòng thử lại!");

                UILayerController.Instance.HideLoading();
                break;

            default:
                responseStatus = WebServiceStatus.Status.ERROR;
                break;
            }

            isDone = true;
        });

        // add data post
        request.AddHeader("Content-Type", "application/json");
        if (httpMethod == HTTPMethods.Post && datas != null && datas.Count > 0)
        {
            foreach (var item in datas)
            {
                request.AddField(item.Key, item.Value);
            }
        }

#if !BESTHTTP_DISABLE_COOKIES && (!UNITY_WEBGL || UNITY_EDITOR)
        // add header and cookie
        request.IsCookiesEnabled = true;
        if (_gvar != null)
        {
            request.Cookies = _gvar.Cookies;
        }
#endif
        request.Timeout = new TimeSpan(0, 0, TIME_OUT);
        request.Send();

        yield return(new WaitUntil(() => isDone));

        Debug.Log("Request Done");
    }
コード例 #23
0
 public static void DeleteFile(string fileName)
 {
     VKDebug.Log("Delete File : " + fileName);
     File.Delete(GetPath(fileName));
 }