// Start is called before the first frame update void Start() { //共通ゲームキャンバスオブジェクト&インスタンス取得 CommonGameCanvasManager = GameObject.Find("CommonGameCanvasManager"); InstanceCommonGameCanvasManagerScript = CommonGameCanvasManager.GetComponent <CommonGameCanvasManagerScript>(); DebugText.text = ">Start"; /*test * ES3.Save<int>("ES3Test1", 100); * DebugText.text += ">Save"; * int ES3Test = ES3.Load<int>("ES3Test1"); * DebugText.text += ">Load"; * DebugStr += ES3Test.ToString(); * DebugText.text += DebugStr; */ //ゲームタイトルをランキングにセット InstanceCommonGameCanvasManagerScript.SetThisGameTitleText(GameTitleString); //ゲーム説明をセット InstanceCommonGameCanvasManagerScript.SetGameDescriptionText(GameDescription); //過去データのロードと過去データによるランキング初期化 LoadSavedScoreToMakeRankAndNewScoreIndex(); DebugText.text += ">NewScoreDataIndex Added"; //スタート時のボタン生成 CreateButtons(); }
//空文字を出す // // Start is called before the first frame update // void Start() void Start() { //共通ゲームキャンバスオブジェクト&インスタンス取得 CommonGameCanvasManager = GameObject.Find("CommonGameCanvasManager"); InstanceCommonGameCanvasManagerScript = CommonGameCanvasManager.GetComponent <CommonGameCanvasManagerScript>(); DebugText.text = ">Start"; /*test * ES3.Save<int>("ES3Test1", 100); * DebugText.text += ">Save"; * int ES3Test = ES3.Load<int>("ES3Test1"); * DebugText.text += ">Load"; * DebugStr += ES3Test.ToString(); * DebugText.text += DebugStr; */ //ゲームタイトルをランキングにセット InstanceCommonGameCanvasManagerScript.SetThisGameTitleText(GameTitleString); //ゲーム説明をセット InstanceCommonGameCanvasManagerScript.SetGameDescriptionText(GameDescription); //ダミー過去セーブスコアリスト // List<int> SaveScoreList = new List<int> { 300, 500, 600 }; // List<int> SaveScoreList = new List<int> { }; // List<int> SaveScoreList = new List<int> { 300, 400, 100, 200, 800, 700 }; bool existsKey = ES3.KeyExists(ScoreKeyName); Debug.Log("existsKey: " + existsKey); if (existsKey == true) { DebugText.text += ">Exists:True"; Debug.Log(DebugText.text); SaveScoreList = ES3.Load <List <int> >(ScoreKeyName); } else { DebugText.text += ">Exists:false"; Debug.Log(DebugText.text); SaveScoreList = new List <int> { }; } Debug.Log("ScoreList = SaveScoreList"); DebugText.text += ">ScoreList = SaveScoreList"; //セーブスコアを呼出し ScoreList = SaveScoreList; Debug.Log("ScoreList.Sort()"); DebugText.text += ">ScoreList.Sort()"; //セーブスコアを昇順にソートしておく ScoreList.Sort(); //セーブスコアを得点の高い順に逆ソートしておく ScoreList.Reverse(); //セーブスコアトップ5をランキングしておく(データない場合は-1) if (ScoreList.Count > 4) { OldScoreRanking[0] = ScoreList[0]; OldScoreRanking[1] = ScoreList[1]; OldScoreRanking[2] = ScoreList[2]; OldScoreRanking[3] = ScoreList[3]; OldScoreRanking[4] = ScoreList[4]; } else if (ScoreList.Count == 4) { OldScoreRanking[0] = ScoreList[0]; OldScoreRanking[1] = ScoreList[1]; OldScoreRanking[2] = ScoreList[2]; OldScoreRanking[3] = ScoreList[3]; OldScoreRanking[4] = -1; } else if (ScoreList.Count == 3) { OldScoreRanking[0] = ScoreList[0]; OldScoreRanking[1] = ScoreList[1]; OldScoreRanking[2] = ScoreList[2]; OldScoreRanking[3] = -1; OldScoreRanking[4] = -1; } else if (ScoreList.Count == 2) { OldScoreRanking[0] = ScoreList[0]; OldScoreRanking[1] = ScoreList[1]; OldScoreRanking[2] = -1; OldScoreRanking[3] = -1; OldScoreRanking[4] = -1; } else if (ScoreList.Count == 1) { OldScoreRanking[0] = ScoreList[0]; OldScoreRanking[1] = -1; OldScoreRanking[2] = -1; OldScoreRanking[3] = -1; OldScoreRanking[4] = -1; } else if (ScoreList.Count == 0) { OldScoreRanking[0] = -1; OldScoreRanking[1] = -1; OldScoreRanking[2] = -1; OldScoreRanking[3] = -1; OldScoreRanking[4] = -1; } //新規スコア追加用の要素を用意する ScoreList.Add(99999); NewScoreDataIndex = ScoreList.IndexOf(99999); ScoreList[NewScoreDataIndex] = 0; DebugText.text += ">NewScoreDataIndex Added"; //スタート時のボタン生成 CreateButtons(); DebugText.text += ">CreateButtns()"; }
// Start is called before the first frame update void Start() { //スマホデバック用 DebugText.text = ">Start"; //共通ゲームキャンバスオブジェクト&インスタンス取得 CommonGameCanvasManager = GameObject.Find("CommonGameCanvasManager"); InstanceCommonGameCanvasManagerScript = CommonGameCanvasManager.GetComponent <CommonGameCanvasManagerScript>(); //共通サウンドオブジェクト&インスタンス取得 CommonSFXControllerObject = GameObject.Find("CommonSFXController"); InstanceCommonSFXControllerScript = CommonSFXControllerObject.GetComponent <CommonSFXControllerScript>(); //ゲームタイトルをランキングにセット InstanceCommonGameCanvasManagerScript.SetThisGameTitleText(GameTitleString); //ゲーム説明をセット InstanceCommonGameCanvasManagerScript.SetGameDescriptionText(GameDescription); bool existsKey = ES3.KeyExists(ScoreKeyName); Debug.Log("existsKey: " + existsKey); if (existsKey == true) { DebugText.text += ">Exists:True"; Debug.Log(DebugText.text); SaveScoreList = ES3.Load <List <int> >(ScoreKeyName); } else { DebugText.text += ">Exists:false"; Debug.Log(DebugText.text); SaveScoreList = new List <int> { }; } //セーブスコアリストをカレントスコアリストにロード ScoreList = SaveScoreList; Debug.Log("ScoreList = SaveScoreList"); DebugText.text += ">ScoreList = SaveScoreList"; //セーブスコアを昇順にソートしておく ScoreList.Sort(); Debug.Log("ScoreList.Sort()"); DebugText.text += ">ScoreList.Sort()"; //セーブスコアを得点の高い順に逆ソートしておく ScoreList.Reverse(); Debug.Log("ScoreList.Reverse()"); DebugText.text += ">ScoreList.Reverse()"; //セーブスコアトップ5をランキングしておく(データない場合は-1) if (ScoreList.Count > 4) { OldScoreRanking[0] = ScoreList[0]; OldScoreRanking[1] = ScoreList[1]; OldScoreRanking[2] = ScoreList[2]; OldScoreRanking[3] = ScoreList[3]; OldScoreRanking[4] = ScoreList[4]; } else if (ScoreList.Count == 4) { OldScoreRanking[0] = ScoreList[0]; OldScoreRanking[1] = ScoreList[1]; OldScoreRanking[2] = ScoreList[2]; OldScoreRanking[3] = ScoreList[3]; OldScoreRanking[4] = -1; } else if (ScoreList.Count == 3) { OldScoreRanking[0] = ScoreList[0]; OldScoreRanking[1] = ScoreList[1]; OldScoreRanking[2] = ScoreList[2]; OldScoreRanking[3] = -1; OldScoreRanking[4] = -1; } else if (ScoreList.Count == 2) { OldScoreRanking[0] = ScoreList[0]; OldScoreRanking[1] = ScoreList[1]; OldScoreRanking[2] = -1; OldScoreRanking[3] = -1; OldScoreRanking[4] = -1; } else if (ScoreList.Count == 1) { OldScoreRanking[0] = ScoreList[0]; OldScoreRanking[1] = -1; OldScoreRanking[2] = -1; OldScoreRanking[3] = -1; OldScoreRanking[4] = -1; } else if (ScoreList.Count == 0) { OldScoreRanking[0] = -1; OldScoreRanking[1] = -1; OldScoreRanking[2] = -1; OldScoreRanking[3] = -1; OldScoreRanking[4] = -1; } //新規スコア追加用の要素を用意する ScoreList.Add(99999); NewScoreDataIndex = ScoreList.IndexOf(99999); ScoreList[NewScoreDataIndex] = 0; DebugText.text += ">NewScoreDataIndex Added"; //ゲームスタート時の音 // InstanceCommonSFXControllerScript.DoSoundSetQuestions(); //本ゲームスタート時のボタン生成 MakeQuestion(); Debug.Log("CreateButtons()"); DebugText.text += ">CreateButtns()"; }
// Start is called before the first frame update void Start() { //画面遷移用にオブジェクト //共通ゲームキャンバスオブジェクト&インスタンス取得 CommonGameCanvasManager = GameObject.Find("CommonGameCanvasManager"); InstanceCommonGameCanvasManagerScript = CommonGameCanvasManager.GetComponent <CommonGameCanvasManagerScript>(); //ゲームタイトルをランキングにセット InstanceCommonGameCanvasManagerScript.SetThisGameTitleText(GameTitleString); //ゲーム説明をセット InstanceCommonGameCanvasManagerScript.SetGameDescriptionText(GameDescription); //デバッグ用に画面にログを出す InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("Start"); //スコアリストをロードする //過去データをあるだけ抽出してリストに保存するループ while (true) { //デバッグ用に画面にログを出す InstanceCommonGameCanvasManagerScript.SetGameDescriptionText(ScoreDataCount.ToString()); //ScoreKeyNameはグローバル変数でスコア番号サフィックス(scoreDataCount)をつけて配列管理 string keyname = ScoreKeyName + ScoreDataCount; //デバッグ用に画面にログを出す InstanceCommonGameCanvasManagerScript.SetGameDescriptionText(keyname); //存在チェック関数KeyExists bool existsKeyFlg = ES3.KeyExists(keyname); int existsKey = ES3.Load <int>(keyname, defaultValue: 404); // existsKey = ScoreRankingList.Add(PlayerPrefs.GetInt(keyname, 404)); //デバッグ用に画面にログを出す InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("nothing"); //存在なし=falseでデータ抜出しループブレイク if (existsKey == 404) { break; } if (existsKeyFlg == false) { break; } //存在ありでリストに保存 ScoreRankingList.Add(ES3.Load <int>(keyname)); // ScoreRankingList.Add(PlayerPrefs.GetInt(keyname, 404)); //デバッグ用に画面にログを出す //InstanceCommonGameCanvasManagerScript.SetGameDescriptionText(ES3.Load<int>(keyname).ToString()); //次のデータ抽出のためカウントアップ値=データ件数 ScoreDataCount++; } //デバッグ用に画面にログを出す InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("過去データ抽出完了"); //得られた過去データを昇順にソートしておく ScoreRankingList.Sort(); //過去データリストを配列順に得点の高い順に逆ソートしておく ScoreRankingList.Reverse(); //ダミーデータを追加して新規スコア追加用の要素を用意する ScoreRankingList.Add(99999); NewScoreDataIndex = ScoreRankingList.IndexOf(99999); ScoreRankingList[NewScoreDataIndex] = 0; //新規スコア追加用のセーブキーを用意しておく NewScoreDataKey = ScoreKeyName + NewScoreDataIndex; Debug.Log("NewScoreDataKey: " + NewScoreDataKey); //デバッグ用に画面にログを出す InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("新規スコア追加用キー完了"); //何もボタンを押さなかった場合の処理として過去データをランキングに入れておく //過去データは昇順に並べているので最後の要素が最大値=ランキング1 if (ScoreRankingList.Count > 5) { InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(ScoreRankingList[0]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(ScoreRankingList[1]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(ScoreRankingList[2]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(ScoreRankingList[3]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(ScoreRankingList[4]); } else if (ScoreRankingList.Count == 4) { InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(ScoreRankingList[0]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(ScoreRankingList[1]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(ScoreRankingList[2]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(ScoreRankingList[3]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(0); } else if (ScoreRankingList.Count == 3) { InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(ScoreRankingList[0]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(ScoreRankingList[1]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(ScoreRankingList[2]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(0); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(0); } else if (ScoreRankingList.Count == 2) { InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(ScoreRankingList[0]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(ScoreRankingList[1]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(0); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(0); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(0); } else if (ScoreRankingList.Count == 1) { InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(ScoreRankingList[0]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(0); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(0); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(0); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(0); } else if (ScoreRankingList.Count == 0) { InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(0); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(0); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(0); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(0); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(0); } //スタート時のボタン生成 CreateButtons(); }
public bool TouchButton(string id) { //デバッグ用に画面にログを出す InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("TouchButtonIn"); //タッチした時刻の記録 TouchButtonTime[CountButtonTouch] = DateTime.Now; //回答数カウントアップ CountButtonTouch++; //正否判定 if (TargetId.ToString() == id) { //あっていたら //デバッグ用に画面にログを出す InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("TouchButtonCorrect"); //正解音を出す InstanceCommonGameCanvasManagerScript.DoSoundCorrectAnswer(); //正答時刻の記録 CorrectTouchButtonTime[CountButtonTouch] = DateTime.Now; //平均正答時間の更新 //ゲーム終了時に時間をタッチボタン数で割ってやれば良いので //ここでは記載しない //正解カウントアップ CorrectAnswerCount++; //連続正答数カウントアップ ConsectiveCorrectAnswers++; //スコア加算1(単純累積) ScoreInt += 200; InstanceCommonGameCanvasManagerScript.SetRealTimeScore(ScoreInt.ToString()); InstanceCommonGameCanvasManagerScript.SetAddRealTimeScore(200); InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("スコア1加算済み"); //スコア加算2(ボーナス1:10連続ミスなし) if (ConsectiveCorrectAnswers == 10) { ScoreInt += 400; ConsectiveCorrectAnswers = 0; BonusPointCount++; InstanceCommonGameCanvasManagerScript.SetRealTimeScore(ScoreInt.ToString()); InstanceCommonGameCanvasManagerScript.SetAddRealTimeBonusScore(400); } InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("ボーナス1設定済み"); //スコア加算3(ボーナス2:即反応0.5秒以内) TimeSpan ElapsedTime = CorrectTouchButtonTime[CountButtonTouch] - CorrectTouchButtonTime[CountButtonTouch - 1]; Debug.Log("ElapsedTime.Milliseconds: " + ElapsedTime.Milliseconds); if (ElapsedTime.Milliseconds < 300) { ScoreInt += 300; ConsectiveCorrectAnswers = 0; BonusPointCount++; InstanceCommonGameCanvasManagerScript.SetRealTimeScore(ScoreInt.ToString()); InstanceCommonGameCanvasManagerScript.SetAddRealTimeBonusScore(300); } InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("ボーナス2設定済み"); //コメントプレフィックス1 string comment1 = "Great Responce!"; //コメントサフィックス2 string comment2 = "You Can Do Better Next Time!"; //リザルトをテキストに変換 string ScoreText = ScoreInt.ToString() + "pt!"; string ResultText = comment1 + "\n" + ScoreText + "\n" + comment2; //リザルトへ書込み InstanceCommonGameCanvasManagerScript.SetResultText(ResultText); InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("リザルト書込み済み"); //過去スコアリストに今回スコアを追加するため過去スコア要素数+1のインデックスを //Start()で準備して使う ScoreRankingList[NewScoreDataIndex] = ScoreInt; //スコアリストに今回スコアを入れてもすぐにソートはしない //本クラスで終了判定を行っていないため //どの時点のスコアが最終スコアとなるか不明なため //ただし今回スコアは得点が伸びるたびに当該変数を //過去スコアと比較してランキングに反映する //ソートは次回呼出し時に行う InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("ランキング設定前"); //ランキングへの書込み if (ScoreInt < ScoreRankingList[4]) { Debug.Log("5位以下"); InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(ScoreRankingList[0]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(ScoreRankingList[1]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(ScoreRankingList[2]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(ScoreRankingList[3]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(ScoreRankingList[4]); } if (ScoreInt > ScoreRankingList[4]) { Debug.Log("5位"); RankInt = 5; InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(ScoreRankingList[0]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(ScoreRankingList[1]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(ScoreRankingList[2]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(ScoreRankingList[3]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(ScoreInt); } if (ScoreInt > ScoreRankingList[3]) { Debug.Log("4位"); RankInt = 4; InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(ScoreRankingList[0]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(ScoreRankingList[1]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(ScoreRankingList[2]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(ScoreInt); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(ScoreRankingList[3]); } if (ScoreInt > ScoreRankingList[2]) { Debug.Log("3位"); RankInt = 3; InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(ScoreRankingList[0]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(ScoreRankingList[1]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(ScoreInt); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(ScoreRankingList[2]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(ScoreRankingList[3]); } if (ScoreInt > ScoreRankingList[1]) { Debug.Log("2位"); RankInt = 2; InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(ScoreRankingList[0]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(ScoreInt); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(ScoreRankingList[1]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(ScoreRankingList[2]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(ScoreRankingList[3]); } if (ScoreInt > ScoreRankingList[0]) { Debug.Log("1位"); RankInt = 1; InstanceCommonGameCanvasManagerScript.SetGameScoreRank1(ScoreInt); InstanceCommonGameCanvasManagerScript.SetGameScoreRank2(ScoreRankingList[0]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank3(ScoreRankingList[1]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank4(ScoreRankingList[2]); InstanceCommonGameCanvasManagerScript.SetGameScoreRank5(ScoreRankingList[3]); } InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("ランキング設定済み"); //ランクに入っていればハイライト InstanceCommonGameCanvasManagerScript.SetHighlightRank(RankInt); // Debug.Log("ハイライト済み"); //今回スコアをランキング画面にセット InstanceCommonGameCanvasManagerScript.SetThisTimeScoreText(ScoreInt.ToString()); // Debug.Log("スコアセット済み"); //今回スコアに資したアクションをセット InstanceCommonGameCanvasManagerScript.SetThisTimeScoreMainActionText(CorrectAnswerCount.ToString()); // Debug.Log("アクションセット済み"); //ボーナスポイント回数をセット InstanceCommonGameCanvasManagerScript.SetThisTimeBonusCountText(BonusPointCount.ToString()); // Debug.Log("ボーナスポイントセット済み"); //ボタン再生成管理カウントアップ CountForReCreateButtons++; //正答ボタン番号更新(+1) TargetId++; //デバッグ用に画面にログを出す InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("TouchButtonOut"); //Trueを返却して呼び出し元でボタン消す return(true); } else { //デバッグ用に画面にログを出す InstanceCommonGameCanvasManagerScript.SetGameDescriptionText("MisTouchButtonIn"); //間違っていたら //不正解音を出す InstanceCommonGameCanvasManagerScript.DoSoundWrongAnswer(); //誤答時間の記録 WrongTouchButtonTime[CountButtonTouch] = DateTime.Now; //不正解カウントアップ WrongAnswerCount++; //連続正答数リセット ConsectiveCorrectAnswers = 0; //Falseを返却して呼び出し元では何もしない return(false); } }