unityで2Dゲームを作りました。
しかし後からになってランキング制を導入しようということになり、
iOSではGameCenterを活用しようと思っています。
参考になるサイトは見つけましたが、c#で書かれているので、javascriptに書き換えたいと思っています。
なにぶん初心者のためどう書き換えればよいか分かりません。
ぜひなんとかご協力お願いします。
以下がscriptです。
SocialExample.cs
lang
1using UnityEngine; 2using UnityEngine.SocialPlatforms; 3 4public class SocialExample : MonoBehaviour { 5 6 void Awake () { 7 // 認証を行い、ProcessAuthenticationコールバックを登録 8 // 他のソーシャルAPIの呼び出しを行う前にこの呼び出しを行う必要があります。 9 Social.localUser.Authenticate (ProcessAuthentication); 10 11 } 12 13 // この関数は認証が完了した後に呼び出しされます 14 // 処理が正常終了した場合、Social.localUserにはサーバから取得したデータを含むことに留意して下さい。 15 void ProcessAuthentication (bool success) { 16 if (success) { 17 Debug.Log ("認証完了、Achievementsをチェックしています"); 18 19 // ロードされているAchievementsをリクエストし、それを処理するためのコールバックを登録します。 20 ILeaderboard leaderboard = 21 Social.CreateLeaderboard(); 22 leaderboard.id = "string leaderboardID"; 23 leaderboard.LoadScores (result => { 24 25 Debug.Log("スコアを " + leaderboard.scores.Length + " 受信しました。"); 26 foreach (IScore score in leaderboard.scores) 27 28 Debug.Log(score); 29 }); 30 31 } 32 else 33 Debug.Log ("認証失敗"); 34 } 35 36 // LoadAchievement呼び出しが完了すると、この関数が呼び出しされます。 37 void ProcessLoadedAchievements (IAchievement[] achievements) { 38 if (achievements.Length == 0) 39 Debug.Log ("エラー:Achievementsは見つかりませんでした。"); 40 else 41 Debug.Log ("取得:" + achievements.Length + " achievements"); 42 43 // また、次のように関数を中で呼び出しすることも出来ます 44 Social.ReportProgress ("Achievement01", 100.0, result => { 45 if (result) 46 Debug.Log ("正常にAchievementの進捗をレポート"); 47 else 48 Debug.Log ("認証失敗"); 49 }); 50 } 51 52}
Test_ScoreReport.cs
lang
1using UnityEngine; 2using System.Collections; 3 4public class Test_ScoreReport : MonoBehaviour { 5 6 public int score1; 7 8 void Start(){ 9 ReportScore(score1, "leaderboardID"); // iTunes Connectで設定したleaderboardIDを入れる 10 } 11 12 void ReportScore (long score, string leaderboardID) { 13 Debug.Log ("Reporting score " + score + " on leaderboard " + leaderboardID); 14 Social.ReportScore (score, leaderboardID, success => { 15 Debug.Log(success ? "Reported score successfully" : "Failed to report score"); 16 }); 17 } 18 19}
Button_GameCenter.cs
lang
1using UnityEngine; 2using System.Collections; 3using UnityEngine.SocialPlatforms; 4 5public class Button_GameCenter : MonoBehaviour { 6 7 public Vector3 checkScale; 8 9 void OnMouseDown() { 10 audio.Play(); 11 checkScale = transform.localScale; 12 transform.localScale += new Vector3(-0.1F, -0.1F, -0.1F); 13//③ 14 Social.LoadScores("string leaderboardID", scores => { 15 if (scores.Length > 0) { 16 17 Debug.Log ("保有: " + scores.Length + " 個のスコア"); 18 string myScores = "Leaderboard:\n"; 19 foreach (IScore score in scores) 20 myScores += "\t" + score.userID + " " + score.formattedValue + " " + score.date + "\n"; 21 22 Debug.Log (myScores); 23 } 24 else 25 26 Debug.Log ("スコアはロードされませんでした。"); 27 }); 28 29 Social.ShowLeaderboardUI(); 30 31 } 32 33 void OnMouseUp() { 34 transform.localScale = checkScale; //④ 35 } 36 37}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。