/// <summary>
    /// Returns an available object from the pool
    /// OR null in case the pool does not have any object available & can grow size is false.
    /// </summary>
    /// <param name="poolName"></param>
    /// <returns></returns>
    public GameObject GetObjectFromPool(string poolName, bool autoActive = true, int autoCreate = 0)
    {
        GameObject result = null;

        if (!poolDict.ContainsKey(poolName) && autoCreate > 0)
        {
            InitPool(poolName, autoCreate, PoolInflationType.INCREMENT);
        }

        if (poolDict.ContainsKey(poolName))
        {
            Pool pool = poolDict[poolName];
            result = pool.NextAvailableObject(autoActive);
            //scenario when no available object is found in pool
#if UNITY_EDITOR
            if (result == null)
            {
                VKDebug.LogWarning("[ResourceManager]:No object available in " + poolName);
            }
#endif
        }
#if UNITY_EDITOR
        else
        {
            VKDebug.LogError("[ResourceManager]:Invalid pool name specified: " + poolName);
        }
#endif
        return(result);
    }
Example #2
0
    private IEnumerator GetLinkDownload()
    {
        UnityWebRequest request = UnityWebRequest.Post(LinkGetCheck, "");

        yield return(request.SendWebRequest());

        if (request.isNetworkError || request.isHttpError)
        {
            VKDebug.LogError(request.error);
            popupStart.SetNotice("Kiểm tra kết nối. Kết nối server thật bại!");
        }
        else
        {
            if (keyUpdate != request.downloadHandler.text)
            {
                evn = Environment.review;
            }
            else
            {
            }
        }

        string uri = linkResource + GetEnvironment() + AssetBundleSetting.GetPlatform() + "gameconfig.txt";

        StartCoroutine(VKCommon.DownloadTextFromURL(uri, (string strConfig) =>
        {
            popupStart.SetNotice("Cập nhật dữ liệu...!");
            Database.Instance.LoadGameConfig(strConfig);
            AssetbundlesManager.Instance.assetSetting = Database.Instance.serverConfig.assetbundle;
            StartCoroutine(LoadYourAsyncScene());
        }));
    }
Example #3
0
    public void OnLoginReadCallBack(ILoginResult result)
    {
        string aToken = "";

        Debug.Log("error nay___________ " + result.Error);

        try
        {
            aToken = AccessToken.CurrentAccessToken.TokenString;
        }
        catch
        {
            VKDebug.LogError("Can't load token");
        }

        if (OnFacebookResult != null)
        {
            OnFacebookResult(FacebookAction.Login, result, aToken);
        }

        if (onFaceBookResultLua != null)
        {
            onFaceBookResultLua.Invoke(FacebookAction.Login, result, aToken);
        }
    }
Example #4
0
    public void InitLayer(string layerKey, float screenRatio)
    {
        // If Exist xlua when run Xlua
        xlua = gameObject.GetComponent <XLuaBehaviour>();
        if (xlua != null)
        {
            xlua.InvokeXLua("InitLayer", layerKey.ToString(), screenRatio);
        }

        isLayerAnimOpenDone = false;

        this.layerKey    = layerKey;
        canvas           = GetComponent <Canvas>();
        anim             = GetComponent <Animator>();
        graphicRaycaster = GetComponent <GraphicRaycaster>();

#if UNITY_EDITOR
        if (canvas == null)
        {
            VKDebug.LogError("Layer need a Canvas");
        }
        if (graphicRaycaster == null)
        {
            VKDebug.LogError("Layer need a GraphicRaycaster");
        }
#endif
    }
        protected override void Awake()
        {
            base.Awake();
            directionSign = 1;

            GridLayoutGroup layout = content.GetComponent <GridLayoutGroup>();

            if (layout != null && layout.constraint != GridLayoutGroup.Constraint.FixedRowCount)
            {
                VKDebug.LogError("[LoopHorizontalScrollRect] unsupported GridLayoutGroup constraint");
            }
        }
    /// <summary>
    /// Return obj to the pool
    /// </summary>
    /// <param name="t"></param>
    public void ReturnTransformToPool(Transform t)
    {
        if (t == null)
        {
#if UNITY_EDITOR
            VKDebug.LogError("[ResourceManager] try to return a null transform to pool!");
#endif
            return;
        }
        //set gameobject active flase to avoid a onEnable call when set parent
        t.gameObject.SetActive(false);
        t.SetParent(null, false);
        ReturnObjectToPool(t.gameObject);
    }
    public void InitPool(string poolName, int size, PoolInflationType type = PoolInflationType.DOUBLE)
    {
        if (poolDict.ContainsKey(poolName))
        {
            return;
        }
        else
        {
//            GameObject pb = Resources.Load<GameObject>(poolName);
            GameObject pb = Resources.Load(path + poolName) as GameObject;
            if (pb == null)
            {
                VKDebug.LogError("[ResourceManager] Invalide prefab name for pooling :" + poolName);
                return;
            }
            poolDict[poolName] = new Pool(poolName, pb, gameObject, size, type);
        }
    }
Example #8
0
    public void ShowLayerCallBack(string key, GameObject obj)
    {
#if USE_XLUA
        InvokeXLua("ShowLayerCallBack", key, obj);
#else
        HideLoading();
        if (obj == null)
        {
            VKDebug.LogError("Layer not found from bundle");
            return;
        }
        UILayer layer = ShowLayer(CreateLayer(key, obj));

        if (ShowLayerFromBundleCallBack != null)
        {
            ShowLayerFromBundleCallBack.Invoke(layer);
        }
#endif
    }
Example #9
0
    private IEnumerator GetLinkResource()
    {
        UnityWebRequest www = UnityWebRequest.Get(strGetLink);

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            VKDebug.LogError(www.error);
            popupStart.SetNotice("Vui lòng kiểm tra kết nối mạng Internet. Kết nối thật bại!");
        }
        else
        {
            var response = (www.downloadHandler.text);

            mLinkResource = JsonUtility.FromJson <MLink>(response);
            linkResource  = mLinkResource.linkResource;
            LinkGetCheck  = mLinkResource.linkCheck;

            StartCoroutine(GetMaintain());
        }
    }
    // Download , save, load
    public IEnumerator DownloadImageFromURL(string url)
    {
        var www = new WWW(url);

        yield return(www);

        try
        {
            if (string.IsNullOrEmpty(www.text) || !string.IsNullOrEmpty(www.error))
            {
                VKDebug.LogError("Download image failed " + www.error);
            }
            else
            {
                Texture2D texture = new Texture2D(1, 1);
                www.LoadImageIntoTexture(texture);
                DownloadSuccess(texture);
            }
        }
        catch (Exception e)
        {
            VKDebug.LogError("Download image failed: " + e.Message);
        }
    }
Example #11
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);
    }
Example #12
0
    private void OnWebServiceResponse(WebServiceCode.Code code, WebServiceStatus.Status status, string data)
    {
        switch (code)
        {
        case WebServiceCode.Code.SignIn:
        case WebServiceCode.Code.SignInFacebook:
            UILayerController.Instance.HideLoading();
            if (status == WebServiceStatus.Status.OK)
            {
                MSignUpResponse mSignUp = JsonUtility.FromJson <MSignUpResponse>(data);

                if (mSignUp.Code == 1 || mSignUp.Code == 2)
                {
                    Database.Instance.SetAccountInfo(mSignUp.Account);
                    LoginSuccess(mSignUp.OTPToken);

                    if (!mSignUp.Account.IsUpdateAccountName)
                    {
                        UILayerController.Instance.ShowLayer(UILayerKey.LCreateNewName, DataResourceLobby.instance.listObjLayer[(int)IndexSourceGate.LCREATE_NEW_NAME]);
                    }
                }
                else
                {
                    Helper.CheckResponseSuccess(mSignUp.Code);
                }
            }
            else
            {
                LPopup.OpenPopupTop("Thống Báo!", "Kiem tra kết nối");
            }
            break;

        case WebServiceCode.Code.LoginOTP:

            if (status == WebServiceStatus.Status.OK)
            {
                UILayerController.Instance.HideLayer(UILayerKey.LLogInWithOTP);
                LoginSuccessWithOTP(true);
            }
            break;

        case WebServiceCode.Code.GetBigWinPlayers:
        {
            if (status == WebServiceStatus.Status.OK)
            {
                var dataBigWinPlayer = LitJson.JsonMapper.ToObject <List <MEventGetGateBigWinPlayers> >(data);
                ShowNoticeRun(dataBigWinPlayer);
            }
            break;
        }

        case WebServiceCode.Code.GetMailUnreal:
        {
            if (status == WebServiceStatus.Status.OK)
            {
                var quantityMailUnread = int.Parse(data);

                VKDebug.LogError(quantityMailUnread + "Number Mail Unread");

                viewLobby.SetNoticeMail(quantityMailUnread);
            }
            break;
        }
        }
    }
Example #13
0
 public void HubCallSellGate(int gate)
 {
     VKDebug.LogError("SellGate " + gate);
     _hub.Call("SellGate", gate);
 }
Example #14
0
    private UILayer CreateLayer(string key, GameObject obj = null)
    {
#if USE_XLUA
        return(InvokeXLua("CreateLayer", new object[] { key, obj })[0] as UILayer);
#else
        UILayer sLayer    = null;
        string  nameLayer = key.ToString();

        // get exists
        bool isCreate = true;
        if (layerCaches.ContainsKey(key) && layerCaches[key].Count > 0)
        {
            isCreate = false;

            sLayer = layerCaches[key][0];
            sLayer.gameObject.SetActive(true);

            layerCaches[key].RemoveAt(0);
        }
        else
        {
            if (obj == null)
            {
                try
                {
                    obj = Resources.Load(path + "/" + nameLayer) as GameObject;
                }
                catch (Exception e)
                {
                    VKDebug.LogError("Layer not found from local");
                    return(null);
                }
            }

            if ((isLandscape && screenRatio > 1.9f) || (!isLandscape && screenRatio > 0.74f))
            {
                if (!obj.GetComponent <UILayer>().lockCanvasScale)
                {
                    CanvasScaler canvasScaler = obj.GetComponent <CanvasScaler>();
                    canvasScaler.matchWidthOrHeight = 1f;
                }
            }
            else
            {
                if (!obj.GetComponent <UILayer>().lockCanvasScale)
                {
                    CanvasScaler canvasScaler = obj.GetComponent <CanvasScaler>();
                    canvasScaler.matchWidthOrHeight = 0f;
                }
            }
            obj    = Instantiate(obj) as GameObject;
            sLayer = obj.GetComponent <UILayer>();

            // seting init
            sLayer.InitLayer(key, screenRatio);

            sLayer.canvas.renderMode  = RenderMode.ScreenSpaceCamera;
            sLayer.canvas.worldCamera = uiCamera;
        }

        List <UILayer> uiLayerTemps = layers[sLayer.position];
        int            countLayer   = uiLayerTemps.Count;

        // set position
        int   sorting  = countLayer == 0 ? deepOrderStarts[(int)sLayer.position] : (uiLayerTemps[countLayer - 1].canvas.sortingOrder + deepOrder);
        float distance = countLayer == 0 ? planeDistanceStarts[(int)sLayer.position] : (uiLayerTemps[countLayer - 1].canvas.planeDistance - deepPlaneDistance);

        sLayer.transform.SetAsLastSibling();
        sLayer.name = nameLayer + "_" + (countLayer + 1);

        sLayer.SetSortOrder(sorting);
        sLayer.canvas.planeDistance = distance;

        // action
        if (isCreate)
        {
            sLayer.StartLayer();
        }
        sLayer.ShowLayer();

        return(sLayer);
#endif
    }