public void StopMusic() { #if UNITY_EDITOR || UNITY_STANDALONE if (music.clip) { music.Stop(); } #else // ANAMusic.pause(currentMusicStreamID); // ANAMusic.seekTo(currentMusicStreamID, 0); if (currentMusicStreamID != -1) { ANAMusic.release(currentMusicStreamID); currentMusicStreamID = -1; currentMusicName = string.Empty; } #endif }
public void PlayPause() { // Check playing state if (ANAMusic.isPlaying(MusicID)) { // Pause ANAMusic.pause(MusicID); } //else //{ // // Play with completion callback // ANAMusic.play(MusicID, StoppedStrings); //} ANAMusic.setPlayInBackground(MusicID, false); ANAMusic.setLooping(MusicID, true); ANAMusic.setVolume(MusicID, GameManager.Instance.AudioVolume); }
void VolumeMute() { if (IsMute) { // Restore volume ANAMusic.setVolume(MusicID, 1.0f); VolumeMuteButton = "Mute"; VolumeString = "Volume: 1.0"; IsMute = false; } else { // Mute volume ANAMusic.setVolume(MusicID, 0.0f); VolumeMuteButton = "Volume"; VolumeString = "Volume: 0.0"; IsMute = true; } }
private void Pause() { if (CytoidApplication.CurrentLevel == null) { return; } IsPaused = true; willPause = false; UnpauseCountdown = -1; if (CytoidApplication.UseDoozyUI) { UIManager.ShowUiElement("PauseBackground", "Game", true); UIManager.ShowUiElement("PauseRoot", "Game", true); } if (!CytoidApplication.CurrentLevel.isInternal && Application.platform == RuntimePlatform.Android) { ANAMusic.pause(anaId); } else { audioSource.Pause(); } if (!CytoidApplication.CurrentLevel.isInternal && Application.platform == RuntimePlatform.Android) { pausedAt = ANAMusic.getCurrentPosition(anaId) / 1000f; } else { pausedAt = audioSource.time; } foreach (var fingerIndex in holdingNotes.Keys) { var holdNote = holdingNotes[fingerIndex]; holdNote.StopHolding(); } holdingNotes.Clear(); SetAllowPause(false); if (unpauseCoroutine != null) { StopCoroutine(unpauseCoroutine); } }
public void Pause() { if (!IsLoaded || IsCompleted || IsFailed) { return; } if (!IsPlaying) { return; } lastSynchorized = 0; IsPlaying = false; if (RankedPlayData != null) { // RankedPlayData.pauses.Add(new RankedPlayData.Pause {start = TimeExt.Millis()}); // Removed in 1.5 } if (GameOptions.Instance.UseAndroidNativeAudio) { ANAMusic.pause(NativeAudioId); PauseAt = ANAMusic.getCurrentPosition(NativeAudioId) / 1000f; } else { AudioSource.Pause(); } PauseTime = UnityEngine.Time.time; holdingNotes.Values.ToList().ForEach(note => note.StopHolding()); holdingNotes.Clear(); View.OnPause(); if (unpauseCoroutine != null) { StopCoroutine(unpauseCoroutine); unpauseCoroutine = null; } }
private IEnumerator OnAndroidPlayerLoaded() { if (Math.Abs(startAt) > 0.00001) { ANAMusic.seekTo(anaId, (int)(startAt * 1000)); } yield return(new WaitForSeconds(1)); ANAMusic.play(anaId); var userOffset = PlayerPrefs.GetFloat("user_offset", 0.12f); // Override options? if (ZPlayerPrefs.GetBool(PreferenceKeys.WillOverrideOptions(CytoidApplication.CurrentLevel))) { userOffset = ZPlayerPrefs.GetFloat(PreferenceKeys.NoteDelay(CytoidApplication.CurrentLevel)); } StartTime = Time.time + Chart.offset + userOffset; }
IEnumerator FadeInMusicCorou(float volume, float time, System.Action onEnd) { #if UNITY_EDITOR || UNITY_STANDALONE music.volume = 0; #else if (currentMusicStreamID == -1) { yield break; } else { ANAMusic.setVolume(currentMusicStreamID, 0); } #endif float t = 0; if (time > 0) { do { yield return(null); t += Time.unscaledDeltaTime / time; #if UNITY_EDITOR || UNITY_STANDALONE music.volume = Mathf.Lerp(0, volume, t); #else ANAMusic.setVolume(currentMusicStreamID, Mathf.Lerp(0, volume, t)); #endif } while (t < 1); } #if UNITY_EDITOR || UNITY_STANDALONE music.volume = volume; #else ANAMusic.setVolume(currentMusicStreamID, volume); #endif if (onEnd != null) { onEnd.Invoke(); } }
public void SetMusicVolume(float value) { //if(value <= -20) // audioSettings[(int)AudioGroups.Music].SetExposedParam(-80); //else // audioSettings[(int)AudioGroups.Music].SetExposedParam(value); #if UNITY_EDITOR || UNITY_STANDALONE audioSettings[(int)AudioGroups.Music].SetExposedParam(value); #endif musicVolume = value; #if UNITY_EDITOR || UNITY_STANDALONE music.volume = musicVolume; #else if (currentMusicStreamID != -1) { ANAMusic.setVolume(currentMusicStreamID, musicVolume); } #endif PlayerPrefs.SetFloat(audioSettings[(int)AudioGroups.Music].exposedParam, value); }
protected void StartGame() { IsPlaying = true; lastNoteId = Chart.Root.note_list.Last().id; if (Mod.HideScanline.IsEnabled()) { Scanline.GetComponent <LineRenderer>().enabled = false; } Scanline.PlayEnter(); Play.MaxHp = Level.GetDifficulty(CytoidApplication.CurrentChartType) * 75; if (Play.MaxHp <= 0) { Play.MaxHp = 1000; } Play.Hp = Play.MaxHp; if (GameOptions.Instance.UseAndroidNativeAudio) { if (GameOptions.Instance.StartAt > 0.00001) { ANAMusic.seekTo(NativeAudioId, (int)(GameOptions.Instance.StartAt * 1000f)); } ANAMusic.play(NativeAudioId); } else { AudioSource.time = GameOptions.Instance.StartAt; AudioSource.Play(); } StartTime = UnityEngine.Time.time; }
private IEnumerator UnpauseCoroutine() { // TODO: I actually love this shit code UnpauseCountdown = 3; yield return(new WaitForSeconds(1f)); UnpauseCountdown = 2; yield return(new WaitForSeconds(1f)); UnpauseCountdown = 1; yield return(new WaitForSeconds(1f)); IsPaused = false; if (!CytoidApplication.CurrentLevel.isInternal && Application.platform == RuntimePlatform.Android) { ANAMusic.play(anaId); } else { audioSource.UnPause(); } SetAllowPause(true); pausedAt = 0; }
public void PauseMusic() { ANAMusic.pause(musicID); }
private IEnumerator Start() { if (PlayerPrefs.GetInt("autoplay") == 1) { autoPlay = true; } CytoidApplication.SetAutoRotation(false); SetAllowPause(false); OnScreenChainNotes = new List <NoteView>(); OnScreenHoldNotes = new List <NoteView>(); OnScreenRegularAndHoldNotes = new List <NoteView>(); #if UNITY_EDITOR autoPlay = true; if (!string.IsNullOrEmpty(editorLevelOverride)) { CytoidApplication.CurrentLevel = CytoidApplication.Levels.Find(it => string.Equals(it.title, editorLevelOverride, StringComparison.OrdinalIgnoreCase)); CytoidApplication.CurrentChartType = editorChartTypeOverride; } // Still null? Fallback if (CytoidApplication.CurrentLevel == null) { CytoidApplication.CurrentLevel = CytoidApplication.Levels.Find(it => string.Equals(it.title, editorLevelFallback, StringComparison.OrdinalIgnoreCase)); CytoidApplication.CurrentChartType = editorChartTypeFallback; } if (Math.Abs(editorStartAtOverride - startAt) > 0.00001f) { startAt = editorStartAtOverride; } #endif var level = CytoidApplication.CurrentLevel; ThemeController.Instance.Init(level); DisplayDifficultyView.Instance.SetDifficulty(CytoidApplication.CurrentChartType, level.GetDifficulty(CytoidApplication.CurrentChartType)); titleText.text = level.title; isInversed = PlayerPrefsExt.GetBool("inverse"); // Override options? if (ZPlayerPrefs.GetBool(PreferenceKeys.WillOverrideOptions(level))) { isInversed = ZPlayerPrefs.GetBool(PreferenceKeys.WillInverse(level)); } // Chart and background are already loaded Chart = level.charts.Find(it => it.type == CytoidApplication.CurrentChartType).chart; PlayData = new PlayData(Chart); CytoidApplication.CurrentPlayData = PlayData; // Load audio clip if (level.isInternal || Application.platform != RuntimePlatform.Android) { var www = new WWW((level.isInternal && Application.platform == RuntimePlatform.Android ? "" : "file://") + level.basePath + level.GetMusicPath(CytoidApplication.CurrentChartType)); yield return(www); clip = CytoidApplication.ReadAudioClipFromWWW(www); audioSource.clip = clip; } // Don't continue until faded in backgroundOverlayMask.willFadeIn = true; while (backgroundOverlayMask.IsFading) { yield return(null); } yield return(null); // Init notes NoteViews = new OrderedDictionary(); foreach (var id in Chart.chronologicalIds) { var note = Chart.notes[id]; // if (note.time <= startAt) continue; var prefab = singleNotePrefab; switch (note.type) { case NoteType.Hold: prefab = holdNotePrefab; break; case NoteType.Chain: prefab = chainNotePrefab; break; } var noteView = Instantiate(prefab, transform).GetComponent <NoteView>(); noteView.Init(Chart, note); NoteViews.Add(id, noteView); } foreach (NoteView note in NoteViews.Values) { note.OnAllNotesInitialized(); } // Register handlers LeanTouch.OnFingerDown += OnFingerDown; LeanTouch.OnFingerSet += OnFingerSet; LeanTouch.OnFingerUp += OnFingerUp; // Release unused assets Resources.UnloadUnusedAssets(); // Init scanner Instantiate(scannerPrefab, transform); if (level.isInternal || Application.platform != RuntimePlatform.Android) { audioSource.time = startAt; var userOffset = PlayerPrefs.GetFloat("user_offset", 0.2f); // Override options? if (ZPlayerPrefs.GetBool(PreferenceKeys.WillOverrideOptions(level))) { userOffset = ZPlayerPrefs.GetFloat(PreferenceKeys.NoteDelay(level)); } const float delay = 1f; audioSource.PlayDelayed(delay); StartTime = Time.time + Chart.offset + userOffset + delay; } else { anaId = ANAMusic.load(level.basePath + level.GetMusicPath(CytoidApplication.CurrentChartType), true, true, id => { StartCoroutine(OnAndroidPlayerLoaded()); }); } }
private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { NotifyWillPause(); if (CytoidApplication.UseDoozyUI) { UIManager.ShowUiElement("PauseBackground", "Game", false); UIManager.ShowUiElement("PauseRoot", "Game", false); } } TimeElapsed = IsLoaded ? Time.time - StartTime + startAt : 0; UpdateNoteViews(); if (!IsLoaded && audioSource != null && ((!CytoidApplication.CurrentLevel.isInternal && Application.platform == RuntimePlatform.Android && anaId != -1 && ANAMusic.isPlaying(anaId)) || audioSource.time > 0.001f)) { IsLoaded = true; SetAllowPause(true); // Enable pausing } if (willPause) { Pause(); } /*if (IsLoaded && !IsPaused && (audioSource.clip.length <= audioSource.time || audioSource.clip.length - audioSource.time < 0.001f)) * { * print("Mark end"); * End(); * }*/ if (PlayData.NoteCleared == Chart.notes.Count) { End(); } }
public void Skip() { currTime = skipTime; ANAMusic.seekTo(musicID, Mathf.RoundToInt(skipTime * 1000f)); touchRing.SeekTo(currTime); }
void LoadMusic(string path) { musicID = ANAMusic.load(path, true); ANAMusic.play(musicID); touchRing.SetStart(); }
void Seek() { // Seek to near end of music ANAMusic.seekTo(MusicID, 73070); }
public void OnMusicLoadedPlay(int ID) { ANAMusic.setVolume(ID, musicVolume); ANAMusic.setLooping(ID, true); ANAMusic.play(ID); }
private void Start() { musicID = ANAMusic.load("Android Native Audio/Music Native.ogg"); PlayBackgroundMusic(); }
string GetPositionLabel() { // Get current position return("Position: " + ANAMusic.getCurrentPosition(MusicID)); }
protected virtual void Update() { // UI Opacity Workaround if (!StoryboardController.Instance.ControllingUiCanvasGroup) { foreach (var canvasGroup in StoryboardController.Instance.UiCanvasGroup.gameObject .GetComponentsInChildren <CanvasGroup>()) { if (canvasGroup.name == "PauseHintText") { continue; } canvasGroup.alpha = StoryboardController.Instance.UiCanvasGroup.alpha; } } if (Input.GetKeyDown(KeyCode.Escape) && !(this is StoryboardGame)) { Pause(); return; } if (IsCompleted) { Time += UnityEngine.Time.deltaTime; return; } if (IsFailed) { AudioSource.volume -= 1f / 120f; } if (IsPlaying) { if (Play.NoteCleared >= Chart.Root.note_list.Count) { Complete(); } UpdateOnScreenNotes(); if (this is StoryboardGame) { Time = AudioSource.timeSamples * 1.0f / AudioSource.clip.frequency - GameOptions.Instance.ChartOffset + Chart.MusicOffset; } else { if (synchorizedCount < 5 && UnityEngine.Time.time - lastSynchorized > 0.1) { lastSynchorized = UnityEngine.Time.time; synchorizedCount++; if (GameOptions.Instance.UseAndroidNativeAudio) { Time = ANAMusic.getCurrentPosition(NativeAudioId) / 1000f - GameOptions.Instance.ChartOffset + Chart.MusicOffset; } else { Time = AudioSource.timeSamples * 1.0f / AudioSource.clip.frequency - GameOptions.Instance.ChartOffset + Chart.MusicOffset; } } else { if (truePlayTime == -1f) { if (GameOptions.Instance.UseAndroidNativeAudio) { audioPlayTime = ANAMusic.getCurrentPosition(NativeAudioId) / 1000f; } else { audioPlayTime = AudioSource.timeSamples * 1.0f / AudioSource.clip.frequency; } truePlayTime = UnityEngine.Time.time; } Time = audioPlayTime + UnityEngine.Time.time - truePlayTime - GameOptions.Instance.ChartOffset + Chart.MusicOffset; } } AudioPercentage = Time / Length; var chart = Chart.Root; var notes = chart.note_list; if (Scanline.PosOverride != float.MinValue) { Scanline.transform.SetY(Chart.GetScanlinePosition01(Scanline.PosOverride)); } else { Scanline.transform.DOMoveY(Chart.GetScanlinePosition(Time), UnityEngine.Time.deltaTime) .SetEase(Ease.Linear); } // Scanline.transform.position = new Vector3(0, Chart.GetScannerPosition(Time)); Scanline.Direction = Chart.CurrentPageId < chart.page_list.Count ? chart.page_list[Chart.CurrentPageId].scan_line_direction : -chart.page_list[Chart.CurrentPageId - 1].scan_line_direction; if (Chart.CurrentPageId < chart.page_list.Count) { boundaryTopAnimator.speed = chart.tempo_list[0].value / 1000000f / (chart.page_list[Chart.CurrentPageId].end_time - chart.page_list[Chart.CurrentPageId].start_time); boundaryBottomAnimator.speed = boundaryTopAnimator.speed; } else { boundaryTopAnimator.speed = 1; boundaryBottomAnimator.speed = boundaryTopAnimator.speed; } BoundaryTop.transform.position = new Vector3(0, Chart.GetEdgePosition(false), 0); BoundaryBottom.transform.position = new Vector3(0, Chart.GetEdgePosition(true), 0); while (currentEventId < chart.event_order_list.Count && chart.event_order_list[currentEventId].time < Time) { // TODO: Speed up text if (chart.event_order_list[currentEventId].event_list[0].type == 0) { Scanline.PlaySpeedUp(); } else { Scanline.PlaySpeedDown(); } currentEventId++; } while (currentAnimId < chart.animation_list.Count && chart.animation_list[currentAnimId].time < Time) { // TODO: Subtitle animation currentAnimId++; } while (currentPageId < chart.page_list.Count && chart.page_list[currentPageId].end_time <= Time) { if (chart.page_list[currentPageId].scan_line_direction == 1) { boundaryTopAnimator.Play("Boundary_Bound"); } else { boundaryBottomAnimator.Play("Boundary_Bound"); } currentPageId++; } while (currentNoteId < notes.Count && notes[currentNoteId].start_time - 2.0f < Time) { switch (notes[currentNoteId].type) { case NoteType.DragHead: var id = currentNoteId; while (notes[id].next_id > 0) { SpawnDragLine(notes[id], notes[notes[id].next_id]); id = notes[id].next_id; } SpawnNote(notes[currentNoteId]); currentNoteId++; break; default: SpawnNote(notes[currentNoteId]); currentNoteId++; break; } } } }
private void OnDestroy() { ANAMusic.release(musicID); }
void OnMusicLoaded(int ID) { currentMusicStreamID = ID; ANAMusic.setVolume(ID, musicVolume); ANAMusic.setLooping(ID, true); }
protected virtual IEnumerator Start() { // Load level if (CytoidApplication.CurrentLevel != null) { Level = CytoidApplication.CurrentLevel; } else { Level = JsonConvert.DeserializeObject <Level>( File.ReadAllText(Application.persistentDataPath + "/player/level.json")); Level.BasePath = Application.persistentDataPath + "/player/"; CytoidApplication.CurrentChartType = Level.charts[0].type; var www = new WWW("file://" + Level.BasePath + Level.background.path); yield return(www); yield return(null); // Wait an extra frame www.LoadImageIntoTexture(CytoidApplication.BackgroundTexture); var backgroundSprite = Sprite.Create(CytoidApplication.BackgroundTexture, new Rect(0, 0, CytoidApplication.BackgroundTexture.width, CytoidApplication.BackgroundTexture.height), new Vector2(0, 0)); var background = GameObject.FindGameObjectWithTag("Background"); if (background != null) { background.GetComponent <Image>().sprite = backgroundSprite; // Fill the screen by adapting to the aspect ratio background.GetComponent <AspectRatioFitter>().aspectRatio = (float)CytoidApplication.BackgroundTexture.width / CytoidApplication.BackgroundTexture.height; yield return(null); // Wait an extra frame } www.Dispose(); Resources.UnloadUnusedAssets(); CytoidApplication.CurrentLevel = Level; } // System settings CytoidApplication.SetAutoRotation(false); if (Application.platform == RuntimePlatform.Android && !Level.IsInternal) { print("Using Android Native Audio"); GameOptions.Instance.UseAndroidNativeAudio = true; } // Load chart print("Loading chart"); if (CytoidApplication.CurrentChartType == null) { CytoidApplication.CurrentChartType = Level.charts[0].type; } var chartSection = Level.charts.Find(it => it.type == CytoidApplication.CurrentChartType); string chartText; if (Application.platform == RuntimePlatform.Android && Level.IsInternal) { var chartWww = new WWW(Level.BasePath + chartSection.path); yield return(chartWww); chartText = Encoding.UTF8.GetString(chartWww.bytes); } else { chartText = File.ReadAllText(Level.BasePath + chartSection.path, Encoding.UTF8); } Chart = new Chart( chartText, 0.8f + (5 - (int)PlayerPrefs.GetFloat("horizontal margin", 3) - 1) * 0.025f, (5.5f + (5 - (int)PlayerPrefs.GetFloat("vertical margin", 3)) * 0.5f) / 9.0f ); // Load audio print("Loading audio"); var audioPath = Level.BasePath + Level.GetMusicPath(CytoidApplication.CurrentChartType); if (GameOptions.Instance.UseAndroidNativeAudio) { NativeAudioId = ANAMusic.load(audioPath, true); Length = ANAMusic.getDuration(NativeAudioId); } else { var www = new WWW( (Level.IsInternal && Application.platform == RuntimePlatform.Android ? "" : "file://") + audioPath); yield return(www); AudioSource.clip = www.GetAudioClip(); Length = AudioSource.clip.length; www.Dispose(); } // Game options var options = GameOptions.Instance; options.HitboxMultiplier = PlayerPrefsExt.GetBool("larger_hitboxes") ? 1.5555f : 1.3333f; options.ShowEarlyLateIndicator = PlayerPrefsExt.GetBool("early_late_indicator"); options.ChartOffset = PlayerPrefs.GetFloat("main offset", 0); options.ChartOffset += ZPlayerPrefs.GetFloat(PreferenceKeys.ChartRelativeOffset(Level.id), 0); if (Application.platform != RuntimePlatform.Android && Headset.Detect()) { options.ChartOffset += ZPlayerPrefs.GetFloat("headset offset"); } if (CytoidApplication.CurrentHitSound.Name != "None") { #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR options.HitSound = NativeAudio.Load("Hits/" + CytoidApplication.CurrentHitSound.Name + ".wav"); #endif } Play.Init(Chart); print("Chart checksum: " + Chart.Checksum); // Rank data if (Play.IsRanked) { RankedPlayData = new RankedPlayData(); RankedPlayData.user = OnlinePlayer.Name; RankedPlayData.password = OnlinePlayer.Password; RankedPlayData.start = TimeExt.Millis(); RankedPlayData.id = Level.id; RankedPlayData.type = CytoidApplication.CurrentChartType; RankedPlayData.mods = string.Join(",", Array.ConvertAll(Play.Mods.ToArray(), mod => mod.ToString())); RankedPlayData.version = Level.version; RankedPlayData.chart_checksum = Chart.Checksum; RankedPlayData.device.width = Screen.width; RankedPlayData.device.height = Screen.height; RankedPlayData.device.dpi = (int)Screen.dpi; RankedPlayData.device.model = SystemInfo.deviceModel; CytoidApplication.CurrentRankedPlayData = RankedPlayData; CytoidApplication.CurrentUnrankedPlayData = null; } else { UnrankedPlayData = new UnrankedPlayData(); UnrankedPlayData.user = OnlinePlayer.Authenticated ? OnlinePlayer.Name : "local"; UnrankedPlayData.password = OnlinePlayer.Authenticated ? OnlinePlayer.Password : ""; UnrankedPlayData.id = Level.id; UnrankedPlayData.type = CytoidApplication.CurrentChartType; UnrankedPlayData.version = Level.version; UnrankedPlayData.chart_checksum = Chart.Checksum; CytoidApplication.CurrentRankedPlayData = null; CytoidApplication.CurrentUnrankedPlayData = UnrankedPlayData; } // Touch handlers if (!Mod.Auto.IsEnabled()) { LeanTouch.OnFingerDown += OnFingerDown; LeanTouch.OnFingerSet += OnFingerSet; LeanTouch.OnFingerUp += OnFingerUp; } yield return(new WaitForSeconds(0.2f)); View.OnStart(); IsLoaded = true; EventKit.Broadcast("game loaded"); // Wait for Storyboard while (!StoryboardController.Instance.Loaded) { yield return(null); } yield return(new WaitForSeconds(0.3f)); StartGame(); }
void OnApplicationPause(bool isPaused) { ANAMusic.OnApplicationPause(isPaused); }
void OnApplicationQuit() { // Clean up when done ANAMusic.release(MusicID); }
private IEnumerator Start() { IsRanked = PlayerPrefsExt.GetBool(PreferenceKeys.RankedMode()); if (!LocalProfile.Exists()) { IsRanked = false; } if (!IsRanked) { levelInfoIndicator.transform.SetLocalX(rankedIndicator.transform.localPosition.x); rankedIndicator.SetActive(false); } if (PlayerPrefs.GetInt("autoplay") == 1 && !IsRanked) { autoPlay = true; } if (PlayerPrefsExt.GetBool("larger_hitboxes")) { hitboxMultiplier = 1.33f; } showEarlyLateIndicator = PlayerPrefsExt.GetBool("early_late_indicator"); CytoidApplication.SetAutoRotation(false); SetAllowPause(false); OnScreenChainNotes = new List <NoteView>(); OnScreenHoldNotes = new List <NoteView>(); OnScreenRegularAndHoldNotes = new List <NoteView>(); #if UNITY_EDITOR autoPlay = true; if (!string.IsNullOrEmpty(editorLevelOverride)) { CytoidApplication.CurrentLevel = CytoidApplication.Levels.Find(it => string.Equals(it.title, editorLevelOverride, StringComparison.OrdinalIgnoreCase)); CytoidApplication.CurrentChartType = editorChartTypeOverride; } // Still null? Fallback if (CytoidApplication.CurrentLevel == null) { CytoidApplication.CurrentLevel = CytoidApplication.Levels.Find(it => string.Equals(it.title, editorLevelFallback, StringComparison.OrdinalIgnoreCase)); CytoidApplication.CurrentChartType = editorChartTypeFallback; } if (Math.Abs(editorStartAtOverride - startAt) > 0.00001f) { startAt = editorStartAtOverride; } #endif var level = CytoidApplication.CurrentLevel; if (!level.ChartsLoaded) { level.LoadCharts(); } ThemeController.Instance.Init(level); DisplayDifficultyView.Instance.SetDifficulty(CytoidApplication.CurrentChartType, level.GetDifficulty(CytoidApplication.CurrentChartType)); titleText.text = level.title; isInversed = PlayerPrefsExt.GetBool("inverse"); // Override options? if (ZPlayerPrefs.GetBool(PreferenceKeys.WillOverrideOptions(level))) { isInversed = ZPlayerPrefs.GetBool(PreferenceKeys.WillInverse(level)); } // Chart and background are already loaded if (CytoidApplication.CurrentChartType == null) { CytoidApplication.CurrentChartType = level.charts[0].type; } Chart = level.charts.Find(it => it.type == CytoidApplication.CurrentChartType).chart; PlayData = new PlayData(Chart, IsRanked); CytoidApplication.CurrentPlayData = PlayData; if (IsRanked) { CytoidApplication.CurrentRankedPlayData = RankedPlayData; } // Load audio clip if (level.is_internal || Application.platform != RuntimePlatform.Android) { var www = new WWW((level.is_internal && Application.platform == RuntimePlatform.Android ? "" : "file://") + level.basePath + level.GetMusicPath(CytoidApplication.CurrentChartType)); yield return(www); clip = CytoidApplication.ReadAudioClipFromWWW(www); audioSource.clip = clip; } // Don't continue until faded in backgroundOverlayMask.willFadeIn = true; while (backgroundOverlayMask.IsFading) { yield return(null); } yield return(null); // Init notes NoteViews = new OrderedDictionary(); foreach (var id in Chart.chronologicalIds) { var note = Chart.notes[id]; // if (note.time <= startAt) continue; var prefab = singleNotePrefab; switch (note.type) { case NoteType.Hold: prefab = holdNotePrefab; break; case NoteType.Chain: prefab = chainNotePrefab; break; } var noteView = Instantiate(prefab, transform).GetComponent <NoteView>(); noteView.Init(Chart, note); NoteViews.Add(id, noteView); } foreach (NoteView note in NoteViews.Values) { note.OnAllNotesInitialized(); } // Register handlers LeanTouch.OnFingerDown += OnFingerDown; LeanTouch.OnFingerSet += OnFingerSet; LeanTouch.OnFingerUp += OnFingerUp; // Release unused assets Resources.UnloadUnusedAssets(); // Init scanner Instantiate(scannerPrefab, transform); if (level.is_internal || Application.platform != RuntimePlatform.Android) { audioSource.time = startAt; var userOffset = PlayerPrefs.GetFloat("user_offset", 0.2f); // Override options? if (ZPlayerPrefs.GetBool(PreferenceKeys.WillOverrideOptions(level))) { userOffset = ZPlayerPrefs.GetFloat(PreferenceKeys.NoteDelay(level)); } const float delay = 1f; audioSource.PlayDelayed(delay); StartTime = Time.time + Chart.offset + userOffset + delay; } else { anaId = ANAMusic.load(level.basePath + level.GetMusicPath(CytoidApplication.CurrentChartType), true, true, id => { StartCoroutine(OnAndroidPlayerLoaded()); }); } // Ranked if (!LocalProfile.Exists()) { RankedPlayData.user = "******"; RankedPlayData.password = ""; } else { RankedPlayData.user = LocalProfile.Instance.username; RankedPlayData.password = LocalProfile.Instance.password; } RankedPlayData.start = TimeExt.Millis(); RankedPlayData.id = level.id; RankedPlayData.type = CytoidApplication.CurrentChartType; RankedPlayData.mods = ""; RankedPlayData.version = level.version; RankedPlayData.chart_checksum = Chart.checksum; RankedPlayData.device.width = Screen.width; RankedPlayData.device.height = Screen.height; RankedPlayData.device.dpi = (int)Screen.dpi; RankedPlayData.device.model = SystemInfo.deviceModel; // Ranked /*#if UNITY_EDITOR * StartCoroutine(EndGame()); #endif*/ }
void Load() { // Load the music with callback MusicID = ANAMusic.load("Android Native Audio/Music Native.ogg", false, true, Loaded); }
public static void PlayBackgroundMusic() { ANAMusic.setLooping(musicID, true); ANAMusic.setVolume(musicID, 0.5f); ANAMusic.play(musicID); }