Ejemplo n.º 1
0
    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
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
 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;
     }
 }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
    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;
    }
Ejemplo n.º 7
0
    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();
        }
    }
Ejemplo n.º 8
0
    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);
    }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
    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;
    }
Ejemplo n.º 11
0
 public void PauseMusic()
 {
     ANAMusic.pause(musicID);
 }
Ejemplo n.º 12
0
    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());
            });
        }
    }
Ejemplo n.º 13
0
    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();
        }
    }
Ejemplo n.º 14
0
 public void Skip()
 {
     currTime = skipTime;
     ANAMusic.seekTo(musicID, Mathf.RoundToInt(skipTime * 1000f));
     touchRing.SeekTo(currTime);
 }
Ejemplo n.º 15
0
 void LoadMusic(string path)
 {
     musicID = ANAMusic.load(path, true);
     ANAMusic.play(musicID);
     touchRing.SetStart();
 }
Ejemplo n.º 16
0
 void Seek()
 {
     // Seek to near end of music
     ANAMusic.seekTo(MusicID, 73070);
 }
Ejemplo n.º 17
0
 public void OnMusicLoadedPlay(int ID)
 {
     ANAMusic.setVolume(ID, musicVolume);
     ANAMusic.setLooping(ID, true);
     ANAMusic.play(ID);
 }
Ejemplo n.º 18
0
 private void Start()
 {
     musicID = ANAMusic.load("Android Native Audio/Music Native.ogg");
     PlayBackgroundMusic();
 }
Ejemplo n.º 19
0
 string GetPositionLabel()
 {
     // Get current position
     return("Position: " + ANAMusic.getCurrentPosition(MusicID));
 }
Ejemplo n.º 20
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 21
0
 private void OnDestroy()
 {
     ANAMusic.release(musicID);
 }
Ejemplo n.º 22
0
 void OnMusicLoaded(int ID)
 {
     currentMusicStreamID = ID;
     ANAMusic.setVolume(ID, musicVolume);
     ANAMusic.setLooping(ID, true);
 }
Ejemplo n.º 23
0
        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();
        }
Ejemplo n.º 24
0
 void OnApplicationPause(bool isPaused)
 {
     ANAMusic.OnApplicationPause(isPaused);
 }
Ejemplo n.º 25
0
 void OnApplicationQuit()
 {
     // Clean up when done
     ANAMusic.release(MusicID);
 }
Ejemplo n.º 26
0
    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*/
    }
Ejemplo n.º 27
0
 void Load()
 {
     // Load the music with callback
     MusicID = ANAMusic.load("Android Native Audio/Music Native.ogg", false, true, Loaded);
 }
Ejemplo n.º 28
0
 public static void PlayBackgroundMusic()
 {
     ANAMusic.setLooping(musicID, true);
     ANAMusic.setVolume(musicID, 0.5f);
     ANAMusic.play(musicID);
 }