public static void WaveCharge(int index) { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") //.Child("pnRD68Js9kU5O4UNvRaPcoueTsy2") .Child(PlayerInformation.auth.CurrentUser.UserId) .Child("charge") .Child("wave") .Child(index.ToString()); reference.GetValueAsync().ContinueWith(task => { if (task.IsCompleted) { DataSnapshot snapshot = task.Result; if (snapshot == null || !snapshot.Exists) // 구매하지 않은 것이라면 { PlayerInformation.waveChargeList[index] = -1; } else { PlayerInformation.waveChargeList[index] = 1; } } }); }
public static void UpdateMoney(int amount) { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") //.Child("pnRD68Js9kU5O4UNvRaPcoueTsy2") .Child(PlayerInformation.auth.CurrentUser.UserId) .Child("money"); reference.GetValueAsync().ContinueWith(task => { if (task.IsCompleted) { // Read DataSnapshot snapshot = task.Result; IDictionary data = (IDictionary)snapshot.Value; string dataMoney = data["money"].ToString(); int tmpMoney = int.Parse(dataMoney); int finalAmount = amount + tmpMoney; PlayerInformation.SoulMoney = finalAmount; // Write SoulMoney soulMoney = new SoulMoney(PlayerInformation.SoulMoney); string json = JsonUtility.ToJson(soulMoney); reference.SetRawJsonValueAsync(json); // Achievement PlayerInformation.AchievementSoul(); } }); }
public static void SetScore(int newScore, bool isHard) { if (isHard) { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") .Child(PlayerInformation.auth.CurrentUser.UserId) .Child("score"); Score score = new Score(newScore, GetTimestamp()); string jsonScore = JsonUtility.ToJson(score); reference.SetRawJsonValueAsync(jsonScore); } else { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") .Child(PlayerInformation.auth.CurrentUser.UserId); EasyScore easyScore = new EasyScore(newScore, GetTimestamp()); string jsonEasyScore = JsonUtility.ToJson(easyScore); reference.Child("easyScore").SetRawJsonValueAsync(jsonEasyScore); } }
public static void GetCurrentCustom() { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") //.Child("pnRD68Js9kU5O4UNvRaPcoueTsy2") .Child(PlayerInformation.auth.CurrentUser.UserId) .Child("custom"); reference.GetValueAsync().ContinueWith(task => { if (task.IsCompleted) { DataSnapshot snapshot = task.Result; foreach (DataSnapshot data in snapshot.Children) { if (data.Key.ToString() == "boat") { PlayerInformation.customs[0] = int.Parse(data.Value.ToString()); } else if (data.Key.ToString() == "face") { PlayerInformation.customs[1] = int.Parse(data.Value.ToString()); } else if (data.Key.ToString() == "wave") { PlayerInformation.customs[2] = int.Parse(data.Value.ToString()); } } } }); }
public static void SetPlayNum(int num) { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") .Child(PlayerInformation.auth.CurrentUser.UserId) .Child("playNum"); PlayNum playNum = new PlayNum(num, GetTimestamp()); string jsonPlayNum = JsonUtility.ToJson(playNum); reference.SetRawJsonValueAsync(jsonPlayNum); }
public static void SetCurrentCustom(int[] customs) { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") //.Child("pnRD68Js9kU5O4UNvRaPcoueTsy2") .Child(PlayerInformation.auth.CurrentUser.UserId) .Child("custom"); Custom custom = new Custom(customs[0], customs[1], customs[2]); string jsonCustom = JsonUtility.ToJson(custom); reference.SetRawJsonValueAsync(jsonCustom); }
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e) { bool success = true; // 아래 소스코드는 안드로이드(Android)에서 실행했을 때에만 정상적으로 동작합니다. CrossPlatformValidator validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier); try { // 앱 상에서 구매한 물품에 대하여 결제 처리를 진행합니다. IPurchaseReceipt[] result = validator.Validate(e.purchasedProduct.receipt); for (int i = 0; i < result.Length; i++) { Analytics.Transaction(productID, e.purchasedProduct.metadata.localizedPrice, e.purchasedProduct.metadata.isoCurrencyCode); } } catch (IAPSecurityException ex) { // 유니티 에디터에서 실행하는 경우 오류가 발생합니다. Debug.Log("오류 발생: " + ex.Message); success = false; } if (success) { Debug.Log("결제 완료"); // 데이터베이스에 접근. DatabaseReference reference = PlayerInformation.GetDatabaseReference(); // 삽입할 데이터 준비하기 DateTime now = DateTime.Now.ToLocalTime(); TimeSpan span = (now - new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime()); int timestamp = (int)span.TotalSeconds; Charge charge = new Charge(timestamp); string json = JsonUtility.ToJson(charge); // 랭킹 점수 데이터 삽입하기 reference.Child("charges").Child(musicIndex.ToString()).Child(PlayerInformation.auth.CurrentUser.UserId).SetRawJsonValueAsync(json); UpdateSong(musicIndex); } else { Debug.Log("결제 실패"); } return(PurchaseProcessingResult.Complete); }
void AddRank() { // 데이터베이스 접속 설정하기 DatabaseReference reference = PlayerInformation.GetDatabaseReference(); // 삽입할 데이터 준비하기 DateTime now = DateTime.Now.ToLocalTime(); TimeSpan span = (now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()); int timestamp = (int)span.TotalSeconds; Rank rank = new Rank(PlayerInformation.auth.CurrentUser.Email, (int)PlayerInformation.score, timestamp); string json = JsonUtility.ToJson(rank); // 랭킹 점수 데이터 삽입하기 reference.Child("ranks").Child(PlayerInformation.selectedMusic).Child(PlayerInformation.auth.CurrentUser.UserId).SetRawJsonValueAsync(json); }
public void Purchase() { // 데이터베이스 접속 설정하기 DatabaseReference reference = PlayerInformation.GetDatabaseReference(); // 삽입할 데이터 준비하기 DateTime now = DateTime.Now.ToLocalTime(); TimeSpan span = (now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()); int timestamp = (int)span.TotalSeconds; Charge charge = new Charge(timestamp); string json = JsonUtility.ToJson(charge); // 랭킹 점수 데이터 삽입하기 reference.Child("charges").Child(musicIndex.ToString()).Child(PlayerInformation.auth.CurrentUser.UserId).SetRawJsonValueAsync(json); UpdateSong(musicIndex); }
public void PurChase() { DatabaseReference reference = PlayerInformation.GetDatabaseReference(); //사입할 데이터 준비하기 DateTime now = DateTime.Now.ToLocalTime(); TimeSpan span = (now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()); int timestamp = (int)span.TotalSeconds; Charge charge = new Charge(timestamp); string json = JsonUtility.ToJson(charge); //랭킹,점수,데이터 삽입하기 reference.Child("charges").Child(musicIndex.ToString()).Child(PlayerInformation.auth.CurrentUser.UserId); //구매처리가 되고 다시 화면 불러온다. UpdateSong(musicIndex); }
public static void GetScore(bool isHard) { int score; if (isHard) { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") .Child(PlayerInformation.auth.CurrentUser.UserId) .Child("score"); reference.Child("score").GetValueAsync().ContinueWith(task => { if (task.IsCompleted) { DataSnapshot data = task.Result; string tmpScore = data.Value.ToString(); score = int.Parse(tmpScore); PlayerInformation.BestScore = score; } }); } else { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") .Child(PlayerInformation.auth.CurrentUser.UserId) .Child("easyScore"); reference.Child("easyScore").GetValueAsync().ContinueWith(task => { if (task.IsCompleted) { DataSnapshot data = task.Result; string tmpScore = data.Value.ToString(); score = int.Parse(tmpScore); PlayerInformation.EasyBestScore = score; } }); } }
public static void GetPlayNum() { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") .Child(PlayerInformation.auth.CurrentUser.UserId) .Child("playNum"); reference.Child("num").GetValueAsync().ContinueWith(task => { if (task.IsCompleted) { DataSnapshot data = task.Result; string tmpNum = data.Value.ToString(); PlayerInformation.PlayNum = int.Parse(tmpNum); } }); }
public static void SetNewUserData() { string userId = PlayerInformation.auth.CurrentUser.UserId; DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user"); reference.GetValueAsync().ContinueWith(task => { if (task.IsCompleted) { DataSnapshot snapshot = task.Result; // New User if (!snapshot.Child(userId).Exists) { Charge charge = new Charge(GetTimestamp()); string jsonCharge = JsonUtility.ToJson(charge); Custom custom = new Custom(0, 0, 0); string jsonCustom = JsonUtility.ToJson(custom); SoulMoney soulMoney = new SoulMoney(0); string jsonMoney = JsonUtility.ToJson(soulMoney); Score score = new Score(0, GetTimestamp()); string jsonScore = JsonUtility.ToJson(score); EasyScore easyScore = new EasyScore(0, GetTimestamp()); string jsonEasyScore = JsonUtility.ToJson(easyScore); PlayNum playNum = new PlayNum(0, GetTimestamp()); string jsonPlayNum = JsonUtility.ToJson(playNum); reference.Child(userId).Child("charge").Child("boat").Child("0").SetRawJsonValueAsync(jsonCharge); reference.Child(userId).Child("charge").Child("face").Child("0").SetRawJsonValueAsync(jsonCharge); reference.Child(userId).Child("charge").Child("wave").Child("0").SetRawJsonValueAsync(jsonCharge); reference.Child(userId).Child("custom").SetRawJsonValueAsync(jsonCustom); reference.Child(userId).Child("money").SetRawJsonValueAsync(jsonMoney); reference.Child(userId).Child("score").SetRawJsonValueAsync(jsonScore); reference.Child(userId).Child("easyScore").SetRawJsonValueAsync(jsonEasyScore); reference.Child(userId).Child("playNum").SetRawJsonValueAsync(jsonPlayNum); } } }); }
public static void SetChargeNewData(string name, int index) { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") //.Child("pnRD68Js9kU5O4UNvRaPcoueTsy2") .Child(PlayerInformation.auth.CurrentUser.UserId) .Child("charge"); Charge charge = new Charge(GetTimestamp()); string jsonCharge = JsonUtility.ToJson(charge); if (name == "boat") { reference.Child("boat").Child(index.ToString()).SetRawJsonValueAsync(jsonCharge); } else if (name == "face") { reference.Child("face").Child(index.ToString()).SetRawJsonValueAsync(jsonCharge); } else if (name == "wave") { reference.Child("wave").Child(index.ToString()).SetRawJsonValueAsync(jsonCharge); } }
private void UpdateSong(int musicIndex) { // 곡을 바꾸면, 일단 플레이할 수 없도록 막습니다. disabled = true; disablePanelUI.gameObject.SetActive(true); disableAlertUI.text = "데이터를 불러오는 중입니다."; purchaseButtonUI.gameObject.SetActive(false); startUI.gameObject.SetActive(false); AudioSource audioSource = GetComponent <AudioSource>(); audioSource.Stop(); // 리소스에서 비트(Beat) 텍스트 파일을 불러옵니다. TextAsset textAsset = Resources.Load <TextAsset>("Beats/" + musicIndex.ToString()); StringReader reader = new StringReader(textAsset.text); // 첫 번째 줄에 적힌 곡 이름을 읽어 UI를 업데이트합니다. musicTitleUI.text = reader.ReadLine(); // 두 번째 줄은 읽기만 하고 아무 처리도 하지 않습니다. reader.ReadLine(); // 세 번째 줄에 적힌 BPM을 읽어 UI를 업데이트합니다. bpmUI.text = "BPM: " + reader.ReadLine().Split(' ')[0]; // 리소스에서 비트(Beat) 음악 파일을 불러와 재생합니다. AudioClip audioClip = Resources.Load <AudioClip>("Beats/" + musicIndex.ToString()); audioSource.clip = audioClip; audioSource.Play(); // 리소스에서 비트(Beat) 이미지 파일을 불러옵니다. musicImageUI.sprite = Resources.Load <Sprite>("Beats/" + musicIndex.ToString()); // 파이어베이스에 접근합니다. DatabaseReference reference = PlayerInformation.GetDatabaseReference().Child("charges") .Child(musicIndex.ToString()); // 데이터 셋의 모든 데이터를 JSON 형태로 가져옵니다. reference.GetValueAsync().ContinueWith(task => { // 성공적으로 데이터를 가져온 경우 if (task.IsCompleted) { Firebase.Database.DataSnapshot snapshot = task.Result; // 해당 곡이 무료 곡인 경우 if (!snapshot.Exists) { disabled = false; disablePanelUI.gameObject.SetActive(false); disableAlertUI.text = ""; startUI.gameObject.SetActive(true); } else { // JSON 데이터의 각 원소에 접근합니다. foreach (Firebase.Database.DataSnapshot data in snapshot.Children) { // 현재 사용자가 구매한 이력이 있는 경우 곡을 플레이할 수 있습니다. if (data.Key == PlayerInformation.auth.CurrentUser.UserId) { disabled = false; disablePanelUI.gameObject.SetActive(false); disableAlertUI.text = ""; startUI.gameObject.SetActive(true); purchaseButtonUI.gameObject.SetActive(false); break; } } // 사용자가 해당 곡을 구매했는지 확인하여 처리합니다. if (disabled) { purchaseButtonUI.gameObject.SetActive(true); disableAlertUI.text = "플레이할 수 없는 곡입니다."; startUI.gameObject.SetActive(false); } } } }); }
// Start is called before the first frame update void Start() { isSucces = false; musicTitleUI.text = PlayerInformation.musicTitle; scoreUI.text = "점수: " + (int)PlayerInformation.socre; maxComboUI.text = "최대 콤보 : " + PlayerInformation.maxCombo; //리소스에서 비트 텍스트파일을 불러옵니다 TextAsset textAsset = Resources.Load <TextAsset>("Beats/" + PlayerInformation.selectedMusic); StringReader reader = new StringReader(textAsset.text); //첫번째 줄과 두번재줄을 무시한다 reader.ReadLine(); reader.ReadLine(); //세번째 줄에적힌 비트정보 (S랭크,A랭크,B랭크) 를읽는다 string beatInformation = reader.ReadLine(); int scoreS = Convert.ToInt32(beatInformation.Split(' ')[3]); int scoreA = Convert.ToInt32(beatInformation.Split(' ')[4]); int scoreB = Convert.ToInt32(beatInformation.Split(' ')[5]); if (PlayerInformation.socre >= scoreS) { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank S"); } else if (PlayerInformation.socre >= scoreA) { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank A"); } else if (PlayerInformation.socre >= scoreB) { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank B"); } else { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank C"); } rank1UI.text = "데이터를 불러오는 중입니다..."; rank2UI.text = "데이터를 불러오는 중입니다..."; rank3UI.text = "데이터를 불러오는 중입니다..."; DatabaseReference reference = PlayerInformation.GetDatabaseReference().Child("ranks") .Child(PlayerInformation.selectedMusic); //랭크스에 접속해서 선택된곡의 번호의 데이터를불러온다 Debug.Log("데이터 갖고오는중 "); //데이터 셋의 모든 데이터를 JSon 형태로 가져온다 reference.OrderByChild("score").GetValueAsync().ContinueWith(task => { //성공적으로 데이터를 자겨온경우 if (task.IsCompleted) { DataSnapshot snapshot = task.Result; //JSON 데이터의 각원소에 접근합니다 foreach (DataSnapshot data in snapshot.Children) { IDictionary rank = (IDictionary)data.Value; //Add는 들어온 순서대로 담기니간 정렬이 필요 => 데이터가 오름차순으로되어있음 emailList.Add(rank["email"].ToString()); rankList.Add(rank["score"].ToString()); } //정렬 이후 순서를 뒤집어 내림차순으로 정렬 emailList.Reverse(); rankList.Reverse(); isSucces = true; //최대 상위 3명의 순위를 차례대로 화면에 출력합니다 rank1UI.text = "플레이 한 사용자가 없습니다."; rank2UI.text = "플레이 한 사용자가 없습니다."; rank3UI.text = "플레이 한 사용자가 없습니다."; } }); }
void Start() { musicTitleUI.text = "" + PlayerInformation.musicTitle; scoreUI.text = "점수: " + (int)PlayerInformation.score; maxComboUI.text = "최대 콤보: " + PlayerInformation.maxCombo; // 리소스에서 비트(Beat) 텍스트 파일을 불러옵니다. TextAsset textAsset = Resources.Load <TextAsset>("Beats/" + PlayerInformation.selectedMusic); StringReader reader = new StringReader(textAsset.text); // 첫 번째 줄과 두 번째 줄을 무시합니다. reader.ReadLine(); reader.ReadLine(); // 세 번째 줄에 적힌 비트 정보(S 랭크 점수, A 랭크 점수, B 랭크 점수)를 읽습니다. string beatInformation = reader.ReadLine(); int scoreS = Convert.ToInt32(beatInformation.Split(' ')[3]); int scoreA = Convert.ToInt32(beatInformation.Split(' ')[4]); int scoreB = Convert.ToInt32(beatInformation.Split(' ')[5]); // 성적에 맞는 랭크 이미지를 불러옵니다. if (PlayerInformation.score >= scoreS) { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank S"); } else if (PlayerInformation.score >= scoreA) { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank A"); } else if (PlayerInformation.score >= scoreB) { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank B"); } else { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank C"); } rank1UI.text = "데이터를 불러오는 중입니다."; rank2UI.text = "데이터를 불러오는 중입니다."; rank3UI.text = "데이터를 불러오는 중입니다."; DatabaseReference reference = PlayerInformation.GetDatabaseReference().Child("ranks") .Child(PlayerInformation.selectedMusic); // 데이터 셋의 모든 데이터를 JSON 형태로 가져옵니다. reference.OrderByChild("score").GetValueAsync().ContinueWith(task => { // 성공적으로 데이터를 가져온 경우 if (task.IsCompleted) { List <string> rankList = new List <string>(); List <string> emailList = new List <string>(); Firebase.Database.DataSnapshot snapshot = task.Result; // JSON 데이터의 각 원소에 접근합니다. foreach (Firebase.Database.DataSnapshot data in snapshot.Children) { IDictionary rank = (IDictionary)data.Value; emailList.Add(rank["email"].ToString()); rankList.Add(rank["score"].ToString()); } // 정렬 이후 순서를 뒤집어 내림차순 정렬합니다. emailList.Reverse(); rankList.Reverse(); // 최대 상위 3명의 순위를 차례대로 화면에 출력합니다. rank1UI.text = "플레이 한 사용자가 없습니다."; rank2UI.text = "플레이 한 사용자가 없습니다."; rank3UI.text = "플레이 한 사용자가 없습니다."; List <Text> textList = new List <Text>(); textList.Add(rank1UI); textList.Add(rank2UI); textList.Add(rank3UI); int count = 1; for (int i = 0; i < rankList.Count && i < 3; i++) { textList[i].text = count + "위: " + emailList[i] + " (" + rankList[i] + ")"; count = count + 1; } } }); }
void Start() { maxComboUI.text = "최대 콤보: " + PlayerInformation.maxCombo.ToString(); scoreUI.text = "점수: " + (int)PlayerInformation.score; musicTitleUI.text = PlayerInformation.musicTitle; // 리소스에서 비트(beat) 텍스트 파일을 불러옵니다. TextAsset textAsset = Resources.Load <TextAsset>("Beats/" + PlayerInformation.selectedMusic); StringReader stringReader = new StringReader(textAsset.text); // 첫 번째 줄과 두 번째 줄을 무시합니다. stringReader.ReadLine(); stringReader.ReadLine(); // 세 번째 줄에 적힌 비트 정보(S, A, B)랭크 점수를 읽습니다. string beatInformation = stringReader.ReadLine(); int scoreS = Convert.ToInt32(beatInformation.Split(' ')[3]); int scoreA = Convert.ToInt32(beatInformation.Split(' ')[4]); int scoreB = Convert.ToInt32(beatInformation.Split(' ')[5]); // 성적에 맞는 랭크 이미지를 불러옵니다. if (PlayerInformation.score >= scoreS) { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank S"); } else if (PlayerInformation.score >= scoreA) { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank A"); } else if (PlayerInformation.score >= scoreB) { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank B"); } else { RankUI.sprite = Resources.Load <Sprite>("Sprites/Rank C"); } Rank1UI.text = "데이터를 불러 오는중 입니다."; Rank2UI.text = "데이터를 불러 오는중 입니다."; Rank3UI.text = "데이터를 불러 오는중 입니다."; // 데이터베이스에 접근 DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("ranks").Child(PlayerInformation.selectedMusic); // 모든 데이터를 Json형태로 가져옵니다. reference.OrderByChild("score").GetValueAsync().ContinueWith // OrderByChild로 내림차순으로 데이터를 가져온다. ( task => { // 성공적으로 데이터를 가져왔다면. if (task.IsCompleted) { List <string> rankList = new List <string>(); List <string> emailList = new List <string>(); DataSnapshot snapshot = task.Result; // Json데이터의 각 원소에 접근. foreach (DataSnapshot data in snapshot.Children) { IDictionary rank = (IDictionary)data.Value; emailList.Add(rank["email"].ToString()); rankList.Add(rank["score"].ToString()); } //내림차순으로 정렬된 데이터를 뒤집어준다. emailList.Reverse(); rankList.Reverse(); // Top 3의 데이터를 출력. Rank1UI.text = "플레이 한 사용자가 없습니다."; Rank2UI.text = "플레이 한 사용자가 없습니다."; Rank3UI.text = "플레이 한 사용자가 없습니다."; List <Text> textList = new List <Text>(); textList.Add(Rank1UI); textList.Add(Rank2UI); textList.Add(Rank3UI); for (int i = 0; i < textList.Count; ++i) { textList[i].text = (i + 1) + "위: " + emailList[i] + "님, (" + rankList[i] + "점)"; } } } ); }