public void OnSubmit() { var PlayerData = new RankingPlayerData(); PlayerData.PlayerName = PlayerNameField.text; PlayerData.Score = 100; var ScoreSystem = GameObject.FindGameObjectWithTag("ScoreSystem"); var ScoreSystemClient = ScoreSystem.GetComponent <OnlineScoreSystemClient>(); ScoreSystemClient.SendScore(PlayerData); ScoreSystemClient.UpdateRanking(); }
/// <summary> /// スコアを送信します。 /// </summary> /// <param name="Data">送信するデータ</param> public void SendScore(RankingPlayerData Data) { WebClient HttpClient = new WebClient(); NameValueCollection PostValues = new NameValueCollection(); PostValues.Add("PlayerName", Data.PlayerName); PostValues.Add("Score", Data.Score.ToString()); try { var Response = HttpClient.UploadValues(URL, PostValues); var ResponseStringOffset = 3; var ResponseString = Encoding.UTF8.GetString(Response, ResponseStringOffset, Response.Length - ResponseStringOffset); Debug.Log(ResponseString); } catch (WebException e) { Debug.Log("スコア送信に失敗しました。ネットワークへの接続状況を確認してください。\n Details : " + e.Message); } }
/// <summary> /// ノードにプレイヤーのランキング情報を書き込みます。 /// </summary> /// <param name="Data">書き込むプレイヤーの情報</param> public void SetPlayerData(int Rank, RankingPlayerData Data) { RankingText.text = string.Format(RankingTextFormat, Rank); PlayerNameText.text = Data.PlayerName; ScoreText.text = string.Format(ScoreTextFormat, Data.Score); }