//bool isPlaying; // Use this for initialization void Start() { /* this part used to load seleted song */ /* { "Tags": [], // 标签 "Creator": "", // 制作者 "GameObject": { // 游戏物件,如落键,转盘 "Hard": [], "Easy": [[0, 10000, 1, 1], // [类型, 时间, 位置, 速度] [0, 10000, 2, 1], [0, 15000, 1, 1], [0, 16000, 2, 1]], "Normal": [] }, "Artist": "", // 艺术家 "Difficulty": { // 难度设定 "Speed": 1 }, "Source": "", // 来源 "Version": "", // 版本 "Title": "", // 谱面标题 "Audio": { // 音频文件信息 "Length": 0, "Name": "" } "Background": { // 背景信息 "Enable": false, // 是否启用 "Type": "", // 类型 0-图片 1-视频 "Name": "" // 文件名 } "SoundEffect": { "Enable": false, "SE": [] } } */ /*******/ PlayerPrefs.SetInt ("GameStarted", 1); enableSE = PlayerPrefs.GetInt ("enableSE") != 0; enableBG = PlayerPrefs.GetInt ("enableBG") != 0; this.beatmapName = PlayerPrefs.GetString ("song"); Debug.Log (" Play " + this.beatmapName); this.difficulty = PlayerPrefs.GetInt ("Difficulty"); /*******/ //beatmapName = "Nya"; //difficulty = 0; //beatmapName = "MirrorNight"; //difficulty = 2; //beatmapName = "LetItGo"; //difficulty = 2; loadFail = true; // Asume load fail // Get beatmap from file TextAsset f = Resources.Load ("Music/" + beatmapName + "/beatmap") as TextAsset; if (f == null) // load fail return; Debug.Log ("Beatmap load success"); string s = f.ToString (); //Debug.Log (s); Beatmap = JSON.Parse (s); if (Beatmap == null) // load fail return; Debug.Log ("Beatmap parse success"); music = GetComponent<AudioSource> (); music.clip = Resources.Load ("Music/" + beatmapName + "/" + Beatmap ["Audio"] ["Name"]) as AudioClip; // No name-extension if (music.clip == null) // load fail return; Debug.Log ("audio load success"); if (Beatmap ["SoundEffect"] ["Enable"].AsBool) { defaultSE = false; SEname = Beatmap ["SoundEffect"] ["Name"]; Debug.Log ("use custom SE"); } else { defaultSE = true; Debug.Log ("use default SE"); } //defaultBG = true; useMovBG = false; usePicBG = false; if (enableBG) { if (Beatmap ["Background"] ["Enable"].AsBool) { Destroy (GameObject.Find ("SpaceGenetator")); //defaultBG = false; switch (Beatmap ["Background"] ["Type"].AsInt) { case 0: // use Picture as background usePicBG = true; Debug.Log ("use custom pic BG"); break; case 1: // use video as background mov = Resources.Load ("Music/" + beatmapName + "/" + Beatmap ["Background"] ["Name"]) as MovieTexture; if (mov == null) // load fail return; (GameObject.Find ("Backgound").GetComponent ("VideoPlayer") as VideoPlayer).movTexture = mov; useMovBG = true; Debug.Log ("use custom mov BG"); break; default: break; } } else { // use default space background Destroy (GameObject.Find ("Backgound")); Debug.Log ("use default BG"); } } else { Destroy (GameObject.Find ("Backgound")); Destroy (GameObject.Find ("SpaceGenetator")); Debug.Log ("not use BG"); } Debug.Log ("background load success"); switch (difficulty) { case 0: HitObjects = Beatmap ["GameObject"] ["Easy"].AsArray; break; case 1: HitObjects = Beatmap ["GameObject"] ["Normal"].AsArray; break; case 2: HitObjects = Beatmap ["GameObject"] ["Hard"].AsArray; break; default: return; } if (HitObjects == null) return; Debug.Log ("hitObjects load success"); CoverMesh = GameObject.Find ("Cover").GetComponent<TextMesh> (); CoverColor = new Color (CoverMesh.color.r, CoverMesh.color.g, CoverMesh.color.b, 1); CoverTimer = 0.5f; CoverDone = false; loadFail = false; // load success Debug.Log ("load success"); NGDL = GameObject.Find ("NoteGeneratorDL").GetComponent ("NoteGenerator") as NoteGenerator; NGDR = GameObject.Find ("NoteGeneratorDR").GetComponent ("NoteGenerator") as NoteGenerator; //NGRU = GameObject.Find ("NoteGeneratorRU").GetComponent ("NoteGenerator") as NoteGenerator; NGRD = GameObject.Find ("NoteGeneratorRD").GetComponent ("NoteGenerator") as NoteGenerator; //NGLU = GameObject.Find ("NoteGeneratorLU").GetComponent ("NoteGenerator") as NoteGenerator; NGLD = GameObject.Find ("NoteGeneratorLD").GetComponent ("NoteGenerator") as NoteGenerator; SG = GameObject.Find ("SpinnerGenerator").GetComponent ("SpinnerGenerator") as SpinnerGenerator; TD = GameObject.Find ("TapDetector").GetComponent ("TapDetector") as TapDetector; // Init i = 0; now = HitObjects [0].AsArray; pause = gameover = false; ScoreCounter = ComboCounter = MaxCombo = PerfectCount = GoodCount = BadCount = MissCount = 0; ScoreNow = 0; ScoreText.text = "Score: " + ScoreCounter.ToString (); ComboText.text = "Combo: " + ComboCounter.ToString (); ScoreText.fontSize = ComboText.fontSize = (int)(Screen.width * 0.03f); PauseButton.onClick.AddListener (PauseResume); StopButton.onClick.AddListener (StopGame); Timer = 0f; NotesBeforeDone = false; if (now [1].AsFloat - 7 / now [3].AsFloat < 0) { Timer = Mathf.Abs (now [1].AsFloat - 7 / now [3].AsFloat); NotesBeforeDone = false; } else { StartGame (); } }
//bool isPlaying; // Use this for initialization void Start() { /* * this part used to load seleted song */ /* * { * "Tags": [], // 标签 * "Creator": "", // 制作者 * "GameObject": { // 游戏物件,如落键,转盘 * "Hard": [], * "Easy": [[0, 10000, 1, 1], // [类型, 时间, 位置, 速度] * [0, 10000, 2, 1], * [0, 15000, 1, 1], * [0, 16000, 2, 1]], * "Normal": [] * }, * "Artist": "", // 艺术家 * "Difficulty": { // 难度设定 * "Speed": 1 * }, * "Source": "", // 来源 * "Version": "", // 版本 * "Title": "", // 谱面标题 * "Audio": { // 音频文件信息 * "Length": 0, * "Name": "" * } * "Background": { // 背景信息 * "Enable": false, // 是否启用 * "Type": "", // 类型 0-图片 1-视频 * "Name": "" // 文件名 * } * "SoundEffect": { * "Enable": false, * "SE": [] * } * } */ /*******/ PlayerPrefs.SetInt("GameStarted", 1); enableSE = PlayerPrefs.GetInt("enableSE") != 0; enableBG = PlayerPrefs.GetInt("enableBG") != 0; this.beatmapName = PlayerPrefs.GetString("song"); Debug.Log(" Play " + this.beatmapName); this.difficulty = PlayerPrefs.GetInt("Difficulty"); /*******/ //beatmapName = "Nya"; //difficulty = 0; //beatmapName = "MirrorNight"; //difficulty = 2; //beatmapName = "LetItGo"; //difficulty = 2; loadFail = true; // Asume load fail // Get beatmap from file TextAsset f = Resources.Load("Music/" + beatmapName + "/beatmap") as TextAsset; if (f == null) // load fail { return; } Debug.Log("Beatmap load success"); string s = f.ToString(); //Debug.Log (s); Beatmap = JSON.Parse(s); if (Beatmap == null) // load fail { return; } Debug.Log("Beatmap parse success"); music = GetComponent <AudioSource> (); music.clip = Resources.Load("Music/" + beatmapName + "/" + Beatmap ["Audio"] ["Name"]) as AudioClip; // No name-extension if (music.clip == null) // load fail { return; } Debug.Log("audio load success"); if (Beatmap ["SoundEffect"] ["Enable"].AsBool) { defaultSE = false; SEname = Beatmap ["SoundEffect"] ["Name"]; Debug.Log("use custom SE"); } else { defaultSE = true; Debug.Log("use default SE"); } //defaultBG = true; useMovBG = false; if (enableBG) { if (Beatmap ["Background"] ["Enable"].AsBool) { Destroy(GameObject.Find("SpaceGenetator")); //defaultBG = false; switch (Beatmap ["Background"] ["Type"].AsInt) { case 0: // use Picture as background // TODO: Load picture background Debug.Log("use custom pic BG"); break; case 1: // use video as background mov = Resources.Load("Music/" + beatmapName + "/" + Beatmap ["Background"] ["Name"]) as MovieTexture; if (mov == null) // load fail { return; } (GameObject.Find("Backgound").GetComponent("VideoPlayer") as VideoPlayer).movTexture = mov; useMovBG = true; Debug.Log("use custom mov BG"); break; default: break; } } else { // use default space background Destroy(GameObject.Find("Backgound")); Debug.Log("use default BG"); } } else { Destroy(GameObject.Find("Backgound")); Destroy(GameObject.Find("SpaceGenetator")); Debug.Log("not use BG"); } Debug.Log("background load success"); switch (difficulty) { case 0: HitObjects = Beatmap ["GameObject"] ["Easy"].AsArray; break; case 1: HitObjects = Beatmap ["GameObject"] ["Normal"].AsArray; break; case 2: HitObjects = Beatmap ["GameObject"] ["Hard"].AsArray; break; default: return; } if (HitObjects == null) { return; } Debug.Log("hitObjects load success"); CoverMesh = GameObject.Find("Cover").GetComponent <TextMesh> (); CoverColor = new Color(CoverMesh.color.r, CoverMesh.color.g, CoverMesh.color.b, 1); CoverTimer = 0.5f; CoverDone = false; loadFail = false; // load success Debug.Log("load success"); NGDL = GameObject.Find("NoteGeneratorDL").GetComponent("NoteGenerator") as NoteGenerator; NGDR = GameObject.Find("NoteGeneratorDR").GetComponent("NoteGenerator") as NoteGenerator; //NGRU = GameObject.Find ("NoteGeneratorRU").GetComponent ("NoteGenerator") as NoteGenerator; NGRD = GameObject.Find("NoteGeneratorRD").GetComponent("NoteGenerator") as NoteGenerator; //NGLU = GameObject.Find ("NoteGeneratorLU").GetComponent ("NoteGenerator") as NoteGenerator; NGLD = GameObject.Find("NoteGeneratorLD").GetComponent("NoteGenerator") as NoteGenerator; SG = GameObject.Find("SpinnerGenerator").GetComponent("SpinnerGenerator") as SpinnerGenerator; TD = GameObject.Find("TapDetector").GetComponent("TapDetector") as TapDetector; // Init i = 0; now = HitObjects [0].AsArray; pause = gameover = false; ScoreCounter = ComboCounter = MaxCombo = PerfectCount = GoodCount = BadCount = MissCount = 0; ScoreNow = 0; ScoreText.text = "Score: " + ScoreCounter.ToString(); ComboText.text = "Combo: " + ComboCounter.ToString(); ScoreText.fontSize = ComboText.fontSize = (int)(Screen.width * 0.03f); PauseButton.onClick.AddListener(PauseResume); StopButton.onClick.AddListener(StopGame); Timer = 0f; NotesBeforeDone = false; if (now [1].AsFloat - 7 / now [3].AsFloat < 0) { Timer = Mathf.Abs(now [1].AsFloat - 7 / now [3].AsFloat); NotesBeforeDone = false; } else { StartGame(); } }