示例#1
0
        public void Start()
        {
            configPageGroup.gameObject.SetActive(false);
            pausePageGroup.gameObject.SetActive(false);

            startTime = Time.time;

            game_ = GameScheduler.instance;
            anim_ = AnimationManager.instance;

            if (game_.backgroundTexture != null)
            {
                backgroundImage.texture = game_.backgroundTexture;
            }

            switch (game_.gameplayConfig.layoutPreset)
            {
            //case GameplayConfigProto.LAYOUT_PRESET_SCANNING_LINE: gameplayManager = scanningLineGameplayManagerV2; break;
            default: gameplayManager = oneOnlyGameplayManager; break;
            }

            hasStarted = false;

            sf2File = new Sf2File(Resources.Load <TextAsset>("sf2/GeneralUser GS v1.471").bytes);

            var audioConfig = AudioSettings.GetConfiguration();

            sampleRate = audioConfig.sampleRate;
            sf2Synth   = new Sf2Synth(sf2File, new Sf2Synth.Table(sampleRate), 128);
            sf2Synth.SetVolume(-10);

            infoText.text = string.Format("{1}\n{0}\n{2}", game_.title, game_.subtitle, ((GameplayConfigProto.DifficaultyPresetEnum)game_.gameplayConfig.difficultyPreset).ToString());

            midiFile           = game_.midiFile ?? new MidiFile(Resources.Load <TextAsset>(testMidiPath).bytes);
            sequenceCollection = game_.noteSequenceCollection ?? new NoteSequenceCollection(midiFile);

            midiFileSha256Hash = MiscHelper.GetBase64EncodedSha256Hash(midiFile.bytes);

            cacheTicks = cacheBeats * midiFile.ticksPerBeat;
            endTicks   = sequenceCollection.end + (game_.gameplayConfig.graceTime + endDelayBeats) * midiFile.ticksPerBeat;

            midiSequencer         = new MidiSequencer(midiFile, sf2Synth);
            midiSequencer.isMuted = true;

            synthConfig = MidiSynthConfigProto.LoadOrCreateDefault(game_, sequenceCollection, midiFileSha256Hash);
            foreach (var seqConfig in synthConfig.sequenceStateList)
            {
                sf2Synth.ProgramChange(seqConfig.channel, (byte)seqConfig.programOverride);
                if (seqConfig.shouldUseInGame)
                {
                    gameSequences.Add(sequenceCollection.sequences[seqConfig.sequenceIndex]);
                }
                else if (!seqConfig.isMuted)
                {
                    backgroundSequences.Add(sequenceCollection.sequences[seqConfig.sequenceIndex]);
                }
            }
            sf2Synth.ignoreProgramChange = true;

            pausePageGroup.gameObject.SetActive(false);

            if (shouldLoadGameplayConfig)
            {
                LoadGameplayConfig();
            }
            scoringManager.Init(this);
            gameplayManager.Init(this);

            backgroundTracks = new BackgroundTrack[backgroundSequences.Count];
            for (int i = 0; i < backgroundTracks.Length; i++)
            {
                backgroundTracks[i] = new BackgroundTrack();
            }
            Debug.LogFormat("background tracks: {0}, game tracks: {1}", backgroundSequences.Count, gameSequences.Count);

            ShowReadyAnimation();
        }