// === 코드(플레이 데이터·저장, 불러오기) =================== // SaveGamePlay() --saveDataHeader(playerName) -세이브시에 자동으로 playerName이 header로 저장 // -현재State가 LoadLevel이 저장 public static bool SaveGamePlay() { try { //Debug.Log("SaveData.SaveGamePlay : Start"); // SaveDataInfo "SDG_GamePlay" SaveDataHeader("SDG_GUEST"); { // PlayerData------------------------------------------------------------ zFoxDataPackString playerData = new zFoxDataPackString(); //GameData.,,GoldAmount 프로퍼티로 호출과 동시에 json에 저장된다. //같이 플레이어의 로컬 playerfabs에 저장시킨다. playerData.Add("Player_COIN", GameData.Instance.players[1].coin); //현재 코인 playerData.Add("Player_EXP", GameData.Instance.players[1].exp); //경험치레벨 playerData.Add("Player_EXPCOUNT", GameData.Instance.players[1].expCount); //경험치 카운트 playerData.Add("Player_CARDHAS", GameData.Instance.players[1].cardHas); //찾은 카드의 수량 playerData.Add("Player_TROPHY", GameData.Instance.players[1].trophy); playerData.PlayerPrefsSetStringUTF8("PlayerData", playerData.EncodeDataPackString()); Debug.Log(playerData.EncodeDataPackString()); } PlayerPrefs.Save(); //json에 카드및 카드덱 정보를 저장한다. // FileDataManager.Instance.SaveJsonData(); return(true); } catch (System.Exception e) { Debug.LogWarning("SaveData.SaveGamePlay : Failed (" + e.Message + ")"); } return(false); }
public static bool SaveGamePlay() { try { Debug.Log("SaveData.SaveGamePlay : Start"); // SaveDataInfo SaveDataHeader("PunchOut_GamePlay"); { // PlayerData zFoxDataPackString playerData = new zFoxDataPackString(); playerData.Add("Player_PunchOutCnt", punchOutCnt); /* * playerData.Add("Player_HP", PlayerController.nowHp); * playerData.Add("Player_Score", PlayerController.score); * playerData.Add("Player_checkPointSceneName", PlayerController.checkPointSceneName); * playerData.Add("Player_checkPointLabelName", PlayerController.checkPointLabelName); * playerData.PlayerPrefsSetStringUTF8("PlayerData", playerData.EncodeDataPackString()); */ Debug.Log(playerData.EncodeDataPackString()); } { // StageData //zFoxDataPackString stageData = new zFoxDataPackString(); /* * zFoxUID[] uidList = GameObject.Find("Stage").GetComponentsInChildren<zFoxUID>(); * foreach (zFoxUID uidItem in uidList) * { * if (uidItem.uid != null && uidItem.uid != "(non)") * { * stageData.Add(uidItem.uid, true); * } * } * stageData.PlayerPrefsSetStringUTF8("StageData_" + Application.loadedLevelName, stageData.EncodeDataPackString()); */ //Debug.Log(stageData.EncodeDataPackString ()); } { // EventData /* * zFoxDataPackString eventData = new zFoxDataPackString(); * eventData.Add("Event_KeyItem_A", PlayerController.itemKeyA); * eventData.Add("Event_KeyItem_B", PlayerController.itemKeyB); * eventData.Add("Event_KeyItem_C", PlayerController.itemKeyC); * eventData.PlayerPrefsSetStringUTF8("EventData", eventData.EncodeDataPackString()); */ //Debug.Log(playerData.EncodeDataPackString ()); } // Save PlayerPrefs.Save(); Debug.Log("SaveData.SaveGamePlay : End"); return(true); } catch (System.Exception e) { Debug.LogWarning("SaveData.SaveGamePlay : Failed (" + e.Message + ")"); } return(false); }
public static bool SaveGamePlay() { try { Debug.Log("SaveData.SaveGamePlay : Start"); SaveDataHeader("SDG_GamePlay"); { zFoxDataPackString playerData = new zFoxDataPackString(); playerData.Add("Player_HPMax", PlayerController.nowHpMax); playerData.Add("Player_HP", PlayerController.nowHp); playerData.Add("Player_Score", PlayerController.score); playerData.Add("Player_checkPointEnabled", PlayerController.checkPointEnabled); playerData.Add("Player_checkPointSceneName", PlayerController.checkPointSceneName); playerData.Add("Player_checkPointLabelName", PlayerController.checkPointLabelName); playerData.PlayerPrefsSetStringUTF8("PlayerData", playerData.EncodeDataPackString()); } { zFoxDataPackString stageData = new zFoxDataPackString(); zFoxUID[] uidList = GameObject.Find("Stage").GetComponentsInChildren <zFoxUID>(); foreach (zFoxUID uidItem in uidList) { if (uidItem.uid != null && uidItem.uid != "(non)") { stageData.Add(uidItem.uid, true); } } stageData.PlayerPrefsSetStringUTF8("StageData_" + Application.loadedLevelName, stageData.EncodeDataPackString()); } { zFoxDataPackString eventData = new zFoxDataPackString(); eventData.Add("Event_KeyItem_A", PlayerController.itemKeyA); eventData.Add("Event_KeyItem_B", PlayerController.itemKeyB); eventData.Add("Event_KeyItem_C", PlayerController.itemKeyC); eventData.PlayerPrefsSetStringUTF8("EventData", eventData.EncodeDataPackString()); } PlayerPrefs.Save(); return(true); } catch (System.Exception e) { Debug.LogWarning("SaveData.SaveGamePlay : Failed(" + e.Message + ")"); } return(false); }
public static bool SaveHiScore(int playerScore) { LoadHiScore(); try { Debug.Log("SaveData.SaveHiScore : Start"); newRecord = 0; PlayerPrefs.Save(); int[] scoreList = new int[11]; //없어도 될 듯 HiScore.CopyTo(scoreList, 0); scoreList[10] = playerScore; System.Array.Sort(scoreList); System.Array.Reverse(scoreList); for (int i = 0; i < 10; i++) { HiScore[i] = scoreList[i]; if (playerScore == HiScore[i]) { newRecord = i + 1; } } SaveDataHeader("SDG_HiScore"); zFoxDataPackString hiScoreData = new zFoxDataPackString(); for (int i = 0; i < 10; i++) { hiScoreData.Add("Rank" + (i + 1), HiScore[i]); } hiScoreData.PlayerPrefsSetStringUTF8("HiScoreData", hiScoreData.EncodeDataPackString()); PlayerPrefs.Save(); Debug.Log("SaveData.SaveHiScore : End"); return(true); } catch (System.Exception e) { Debug.LogWarning("SaveData.SaveHiScore : Failed(" + e.Message + ")"); } return(false); }
// === 코드(플레이 데이터·저장, 불러오기) =================== public static bool SaveGamePlay() { try { Debug.Log("SaveData.SaveGamePlay : Start"); // SaveDataInfo SaveDataHeader("SDG_GamePlay"); { // PlayerData zFoxDataPackString playerData = new zFoxDataPackString(); playerData.Add ("Player_HPMax", PlayerController.nowHpMax); playerData.Add ("Player_HP" , PlayerController.nowHp); playerData.Add ("Player_Score", PlayerController.score); playerData.Add ("Player_checkPointEnabled" , PlayerController.checkPointEnabled); playerData.Add ("Player_checkPointSceneName", PlayerController.checkPointSceneName); playerData.Add ("Player_checkPointLabelName", PlayerController.checkPointLabelName); playerData.PlayerPrefsSetStringUTF8 ("PlayerData", playerData.EncodeDataPackString ()); //Debug.Log(playerData.EncodeDataPackString ()); } { // StageData zFoxDataPackString stageData = new zFoxDataPackString(); zFoxUID[] uidList = GameObject.Find ("Stage").GetComponentsInChildren<zFoxUID> (); foreach(zFoxUID uidItem in uidList) { if (uidItem.uid != null && uidItem.uid != "(non)") { stageData.Add (uidItem.uid,true); } } stageData.PlayerPrefsSetStringUTF8 ("StageData_" + Application.loadedLevelName, stageData.EncodeDataPackString ()); //Debug.Log(stageData.EncodeDataPackString ()); } { // EventData zFoxDataPackString eventData = new zFoxDataPackString(); eventData.Add ("Event_KeyItem_A", PlayerController.itemKeyA); eventData.Add ("Event_KeyItem_B", PlayerController.itemKeyB); eventData.Add ("Event_KeyItem_C", PlayerController.itemKeyC); eventData.PlayerPrefsSetStringUTF8 ("EventData", eventData.EncodeDataPackString ()); //Debug.Log(playerData.EncodeDataPackString ()); } // Save PlayerPrefs.Save (); Debug.Log("SaveData.SaveGamePlay : End"); return true; } catch(System.Exception e) { Debug.LogWarning("SaveData.SaveGamePlay : Failed (" + e.Message + ")"); } return false; }
// === コード(ハイスコアデータ・セーブロード) ================ public static bool SaveHiScore(int playerScore) { LoadHiScore (); try { Debug.Log("SaveData.SaveHiScore : Start"); // Hiscore Set & Sort newRecord = 0; int[] scoreList = new int [11]; HiScore.CopyTo (scoreList, 0); scoreList[10] = playerScore; System.Array.Sort(scoreList); System.Array.Reverse(scoreList); for(int i = 0;i < 10;i ++) { HiScore[i] = scoreList[i]; if (playerScore == HiScore[i]) { newRecord = i + 1; } } // Hiscore Save SaveDataHeader("SDG_HiScore"); zFoxDataPackString hiscoreData = new zFoxDataPackString(); for(int i = 0;i < 10;i ++) { hiscoreData.Add ("Rank" + (i + 1), HiScore[i]); } hiscoreData.PlayerPrefsSetStringUTF8 ("HiScoreData", hiscoreData.EncodeDataPackString ()); PlayerPrefs.Save (); Debug.Log("SaveData.SaveHiScore : End"); return true; } catch(System.Exception e) { Debug.LogWarning("SaveData.SaveHiScore : Failed (" + e.Message + ")"); } return false; }
// punchoutcnt - playerControl에 있음. // playerSocre - Timer 에 있음. public static bool SaveHiScore(string punchOutCnt, string playerScore) { Debug.Log("SaveDataClass come?"); Debug.Log("playerScore : " + playerScore + " punchOutCnt : " + punchOutCnt); Debug.Log("HiScore[0,0]" + HiScore[0, 0]); LoadHiScore(); //i기존 기록 3등 안에 들었을 경우 넣어주기! // int ranking = 0 ; // 갱신된 순위 알려주는 거 bool flag = false; Debug.Log("HiScore.GetLength(0)" + HiScore.GetLength(0)); for (int i = 1; i < HiScore.GetLength(0); i++) { Debug.Log("for(int i = 1; i<HiScore.GetLength(0); i++) -> " + i); if (Convert.ToInt32(HiScore[i, 1]) > Convert.ToInt32(playerScore)) { flag = true; } } Debug.Log("flag : " + flag); // 기존 기록보다 좋지 않은 경우엔 아래 코드들을 실행시키지 않고 리턴 시켜준다. if (flag == false) { Debug.Log("flag : " + flag); return(false); } try { Debug.Log("SaveData.SaveHiScore : Start"); // Hiscore Set & Sort newRecord = 0; Debug.Log("Before HiScore.Length"); string[,] scoreList = new string[4, 2] { { "0", "9998" }, { "0", "9998" }, { "0", "9998" }, { "0", "9998" } };; Debug.Log("After HiScore.Length"); //HiScore.CopyTo(scoreList, 0); for (int i = 0; i < HiScore.GetLength(0); i++) { Debug.Log("before : scoreList[i] : " + scoreList[i, 1].ToString()); scoreList[i, 0] = HiScore[i, 0]; scoreList[i, 1] = HiScore[i, 1]; Debug.Log("after : scoreList[i] : " + scoreList[i, 1].ToString()); } Debug.Log("After HiScore.CopyTo(scoreList,0)"); scoreList[scoreList.GetLength(0) - 1, 0] = punchOutCnt; scoreList[scoreList.GetLength(0) - 1, 1] = playerScore; Debug.Log("Before Sort ScoreList"); for (int i = 0; i < scoreList.GetLength(0); i++) { Debug.Log("scoreList[i,1] : " + scoreList[i, 1]); } //Sort ScoreList for (int i = 0; i < scoreList.GetLength(0) - 1; i++) { for (int j = 1; j < scoreList.GetLength(0) - i; j++) { if (Convert.ToInt32(scoreList[j - 1, 1]) > Convert.ToInt32(scoreList[j, 1])) { swap(scoreList, j); } } } Debug.Log("After Sort ScoreList"); for (int i = 0; i < scoreList.GetLength(0); i++) { Debug.Log("scoreList[i,1] : " + scoreList[i, 1]); } for (int i = 0; i < HiScore.GetLength(0); i++) { Debug.Log("before : HiScore[i] : " + HiScore[i, 1].ToString()); HiScore[i, 0] = scoreList[i, 0]; HiScore[i, 1] = scoreList[i, 1]; Debug.Log("after : HiScore[i] : " + HiScore[i, 1].ToString()); } // Hiscore Save SaveDataHeader("SDG_HiScore"); zFoxDataPackString hiscoreData = new zFoxDataPackString(); for (int i = 0; i < HiScore.GetLength(0); i++) { hiscoreData.Add("PunchOutCntforRank" + (i + 1), HiScore[i, 0]); hiscoreData.Add("HiScoreforRank" + (i + 1), HiScore[i, 1]); } hiscoreData.PlayerPrefsSetStringUTF8("HiScoreData", hiscoreData.EncodeDataPackString()); PlayerPrefs.Save(); LoadHiScore(); for (int i = 0; i < HiScore.GetLength(0); i++) { Debug.Log("HiScore[i,1] : " + HiScore[i, 1]); } Debug.Log("SaveData.SaveHiScore : End"); //Debug.Log("After Clearing stage cnt : "+SaveData.punchOutCnt); return(true); } catch (System.Exception e) { Debug.LogWarning("SaveData.SaveHiScore : Failed (" + e.Message + ")"); } return(false); }