Beispiel #1
0
    IEnumerator Login(string userID, string pletformID = "", LoginType loginType = LoginType.GuestLogin)
    {
        Debug.Log("로그인 시작");
        loginPanel.SetActive(false);


        //로그인 시 유저 데이터 구성부분
        WWWForm form = new WWWForm();

        form.AddField("userID", userID, System.Text.Encoding.UTF8); //테스트 아이디로 로그인한다.

        string googleID = "";

        if (PlayerPrefs.HasKey("google"))
        {
            googleID = PlayerPrefs.GetString("google");
        }
        else
        {
            if (loginType == LoginType.GoogleLogin)
            {
                googleID = pletformID;
            }
        }

        string facebookID = "";

        if (PlayerPrefs.HasKey("facebook"))
        {
            facebookID = PlayerPrefs.GetString("facebook");
        }
        else
        {
            if (loginType == LoginType.FacebookLogin)
            {
                facebookID = pletformID;
            }
        }

        tipMessageText.text = "로그인 정보를 내려받는 중..";
        form.AddField("google", googleID, System.Text.Encoding.UTF8);
        form.AddField("facebook", facebookID, System.Text.Encoding.UTF8);
        form.AddField("deviceModel", SystemInfo.deviceModel);
        form.AddField("deviceID", SystemInfo.deviceUniqueIdentifier);

        form.AddField("type", (int)loginType);

        string result = "";
        string php    = "Login.php";

        yield return(StartCoroutine(WebServerConnectManager.Instance.WWWCoroutine(php, form, x => result = x)));

        JsonData jsonData = ParseCheckDodge(result);


        PlayerPrefs.SetString("userID", JsonParser.ToString(jsonData["id"].ToString()));

        if (loginType == LoginType.GoogleLogin)
        {
            PlayerPrefs.SetString("google", JsonParser.ToString(jsonData["google"].ToString()));
        }

        if (loginType == LoginType.FacebookLogin)
        {
            PlayerPrefs.SetString("facebook", JsonParser.ToString(jsonData["facebook"].ToString()));
        }

        // 아틀라스 캐싱
        string atlasName = "Atlas_Product";
        AssetBundleLoadAssetOperation r = AssetBundleManager.LoadAssetAsync("sprite/product", atlasName, typeof(UnityEngine.U2D.SpriteAtlas));

        yield return(StartCoroutine(r));

        UnityEngine.U2D.SpriteAtlas atlas = r.GetAsset <UnityEngine.U2D.SpriteAtlas>();

        if (atlas != null)
        {
            if (!AssetLoader.cachedAtlasDic.ContainsKey(atlasName))
            {
                AssetLoader.cachedAtlasDic.Add(atlasName, atlas);
            }
        }
        string atlasName2 = "Atlas_Material";
        AssetBundleLoadAssetOperation r2 = AssetBundleManager.LoadAssetAsync("sprite/material", atlasName2, typeof(UnityEngine.U2D.SpriteAtlas));

        yield return(StartCoroutine(r2));

        UnityEngine.U2D.SpriteAtlas atlas2 = r2.GetAsset <UnityEngine.U2D.SpriteAtlas>();

        if (atlas2 != null)
        {
            if (!AssetLoader.cachedAtlasDic.ContainsKey(atlasName2))
            {
                AssetLoader.cachedAtlasDic.Add(atlasName2, atlas2);
            }
        }


        //// 게임 데이타 초기화 끝날 때 까지 대기
        //while (!GameDataManager.isInitialized)
        //    yield return null;


        if (User.Instance)
        {
            User.Instance.InitUserData(jsonData);
        }

        Debug.Log("유저 데이터 초기화");

        while (!User.isInitialized)
        {
            yield return(null);
        }

        Debug.Log("완료");
        // 유저 데이터 초기화 시작
        StartCoroutine(UserDataManager.Instance.Init());



        // 유저 데이터 초기화 완료 했는가 체크
        while (!UserDataManager.isInitialized)
        {
            yield return(null);
        }
        tipMessageText.text = "왕국으로 진입중..";
        Debug.Log("Login UserID : " + JsonParser.ToString(jsonData["id"]));

        //enterButton.SetActive(true);



        //if (onFadeOutStart != null)
        //    onFadeOutStart();

        ////페이드아웃 기다리는 시간
        //yield return new WaitForSeconds(1.5f);

        yield return(StartCoroutine(LoadingManager.FadeOutScreen()));

        string nextSceneBundleName         = "scene/lobby";
        string nextSceneName               = "Lobby";
        AssetBundleLoadOperation operation = AssetBundleManager.LoadLevelAsync(nextSceneBundleName, nextSceneName, true);



        //// 몬스터 풀 초기화 끝났는가 체크
        //while (!MonsterPool.Instance)
        //    yield return null;

        //while (!MonsterPool.Instance.isInitialization)
        //    yield return null;

        //while (!Battle.Instance || !Battle.Instance.isInitialized)
        //    yield return null;


        while (!operation.IsDone())
        {
            yield return(null);
        }


        versionText.gameObject.SetActive(false);
        messagePanel.SetActive(false);
        StopCoroutine(messageCoroutine());


        //while (!UILoginManager.isFinished)
        //    yield return null;


        Scene lobby    = SceneManager.GetSceneByName("Lobby");
        Scene login    = SceneManager.GetSceneByName("Login");
        Scene preLogin = SceneManager.GetSceneByName("PreLogin");

        SceneManager.SetActiveScene(lobby);
        SceneManager.UnloadSceneAsync(login);
        SceneManager.UnloadSceneAsync(preLogin);
    }