Exemplo n.º 1
0
        void Start()
        {
            if (Instance == null)
            {
                Instance = this;
                DontDestroyOnLoad(this.gameObject);
            }
            else if (Instance != this)
            {
                Destroy(this.gameObject);
            }

            DataManager.Instance.CurrentPlayerData = new PlayerData();

            //int statusCode = int.Parse(BackEnd.Backend.BMember.LoginWithTheBackendToken().GetStatusCode());

            //switch (statusCode)
            //{
            //    case 410:
            //        Debug.Log("1년 뒤 refresh토큰이 만료됨");
            //        break;

            //    case 401:
            //        Debug.Log("다른 기기로 로그인하여 refresh토큰이 만료됨");
            //        break;

            //    case 403:
            //        Debug.Log("차단된 유저");
            //        break;

            //    default:
            //        Debug.Log("로그인 성공");
            //        NotFirstTimeFunc();
            //        break;
            //}



            if (Backend.BMember.IsAccessTokenAlive().GetStatusCode().ToString() == "204")
            {
                Debug.Log(Backend.BMember.IsAccessTokenAlive().GetStatusCode());
                NotFirstTimeFunc();
            }
            else
            {
                Debug.Log(Backend.BMember.IsAccessTokenAlive().GetStatusCode());
                FirstTimeFunc();
            }
        }
        void Start()
        {
            if (Instance == null)
            {
                Instance = this;
                DontDestroyOnLoad(this.gameObject);

                //GameObject.Instantiate(Tutorial_Prefab);
            }
            else if (Instance != this)
            {
                Destroy(this.gameObject);
            }

            DataManager.Instance.CurrentPlayerData = new PlayerData();

            try
            {
                using (StreamReader sr = new StreamReader(string.Format("{0}/ID.json", Application.persistentDataPath)))
                {
                    using (JsonReader reader = new JsonTextReader(sr))
                    {
                        JsonSerializer serializer = new JsonSerializer();
                        Data.DataManager.Instance.CurrentPlayerData.player_id = serializer.Deserialize(reader).ToString();
                    }
                }
            }
            catch (Exception e)
            {
                Data.DataManager.Instance.CurrentPlayerData.player_id = GenerateRandomId();

                using (StreamWriter sw = new StreamWriter(string.Format("{0}/ID.json", Application.persistentDataPath)))
                {
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        string         user_id    = Data.DataManager.Instance.CurrentPlayerData.player_id;
                        JsonSerializer serializer = new JsonSerializer();
                        serializer.Serialize(writer, user_id);
                    }
                }
            }

            try
            {
                WebSocketManager.Instance.SendFindName("1", DataManager.Instance.CurrentPlayerData.player_id);
            }
            catch (InvalidOperationException)
            {
                AlertManager.Instance.InstantiateAlertWithReturn("서버에 접속할 수 없습니다.").onClick.AddListener(() => Application.Quit());
            }

            /*
             * //처음으로 접속했을 경우 데이터를 디폴트로 세팅한다
             * if (!PlayerPrefs.HasKey(SAVE_NAME))
             * {
             *  PlayerPrefs.SetString(SAVE_NAME, DataManager.Instance.PlayerDataToString(new PlayerData()));
             * }
             */
            PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
                                                  .EnableSavedGames().Build();

            PlayGamesPlatform.InitializeInstance(config);
            PlayGamesPlatform.Activate();

            SignIn();
        }