예제 #1
0
 public override void OnWindowClose()
 {
     if (!_shouldSave)
     {
         return;
     }
     GameRegistry.SetValue("CUR_SONG", _fileName);
     SongEditor.instance.SaveSong(null);
 }
예제 #2
0
        //Save
        public void SaveSong(object arg)
        {
            string curPath = _dataPath + "/" + GameRegistry.GetString("CUR_SONG");

            Directory.CreateDirectory(curPath);
            if (!File.Exists(_dataPath + "/" + GameRegistry.GetString("CUR_SONG") + "/" + Path.GetFileName(_curSong.songPath)))
            {
                string newPath = GameRegistry.GetString("CUR_SONG") + "/" + Path.GetFileName(_curSong.songPath);
                File.Copy(_dataPath + "/" + _curSong.songPath, _dataPath + "/" + newPath);
                _curSong.songPath = newPath;
            }
            File.WriteAllBytes(curPath + "/Song.SongData", _curSong.getSongData());
        }
예제 #3
0
        public void CreateSong(Song song)
        {
            string curPath = _dataPath + "/" + GameRegistry.GetString("CUR_SONG");

            Directory.CreateDirectory(curPath);
            if (!File.Exists(_dataPath + "/" + GameRegistry.GetString("CUR_SONG") + "/" + Path.GetFileName(song.songPath)))
            {
                string newPath = GameRegistry.GetString("CUR_SONG") + "/" + Path.GetFileName(song.songPath);
                File.Copy(_dataPath + "/" + song.songPath, _dataPath + "/" + newPath);
                song.songPath = newPath;
            }
            File.WriteAllBytes(curPath + "/Song.SongData", song.getSongData());
            SceneManager.LoadScene("songEditor");
        }
예제 #4
0
        private void Create()
        {
            GameRegistry.SetValue("CUR_SONG", songNameField.text);
            Directory.CreateDirectory(songPath);
            string file = songPath + "/Song" + Path.GetExtension(_selectedFile);

            if (File.Exists(file))
            {
                File.Delete(file);
            }
            File.Copy(_selectedFile, file);
            Song song = new Song("/" + songNameField.text + "/Song" + Path.GetExtension(_selectedFile), 3);

            song.info.title = songNameField.text;
            _fe.CreateSong(song);
        }
예제 #5
0
 void Start()
 {
     //Set the Data path
     _dataPath = Application.dataPath + "/Songs/";
     //Cache the audio source
     _src = GetComponent <AudioSource>();
     if (GameRegistry.GetString("CUR_SONG") == null)
     {
         GameRegistry.SetValue("CUR_SONG", "SongName");
     }
     byte[] songData = File.ReadAllBytes(_dataPath + GameRegistry.GetString("CUR_SONG") + "/Song.SongData");
     _song = Song.loadSong(songData);
     EventManager.StartListening("loadSong", SongReady);
     StartCoroutine(_song.LoadAudioClip("loadSong"));
     _loadTimer = Time.time;
     //_src.clip = _song.song;
     //_songLength = _src.clip.length;
 }
예제 #6
0
 void OnEnable()
 {
     if (!_hasInit)
     {
         animationScale = GameRegistry.GetFloat("windowAnimationScale", animationScale);
         windowShadow   = GetComponent <Image>();
         if (windowWidth == 0)
         {
             windowWidth = window.rectTransform.rect.width;
         }
         CenterWindow();
         headerText.text = defaultTitle;
         if (confirmationWindow == null && closeConfirmation)
         {
             confirmationWindow = FindObjectOfType <UIConfirmationWindow>() as UIConfirmationWindow;
         }
         _hasInit = true;
     }
 }
예제 #7
0
        //Load the song and wait for completion
        void Start()
        {
            //trackConfigWindow.CloseWindow();
            _dataPath = Application.dataPath + "/Songs";
            //if (GameRegistry.GetString("CUR_SONG") == null)
            //	GameRegistry.SetValue("CUR_SONG", "SongName");
            _mode = TimelineMode.sec;
            string curPath = _dataPath + "/" + GameRegistry.GetString("CUR_SONG", "SongName");

            _curSong = Song.loadSong(File.ReadAllBytes(curPath + "/Song.SongData"));
            Debug.Log(_curSong.songPath);
            //_curSong.songPath = "/SongName/Song.wav";
            //File.WriteAllBytes(_dataPath + "/SongName/Song.SongData", _curSong.getSongData());
            _audio             = GetComponent <AudioSource>();
            _audio.playOnAwake = false;
            _audio.Stop();
            EventManager.StartListening("songLoaded", SongReady);
            _loadStartTime = Time.time;
            StartCoroutine(_curSong.LoadAudioClip("songLoaded"));
            Debug.Log("Loading Song...");
        }
예제 #8
0
 //Exit Editor
 public void ExitEditor(object arg)
 {
     GameRegistry.SetValue("isEditing", false);
     SceneManager.LoadScene(0);
 }
예제 #9
0
 //Play Song
 public void PlaySong(object arg)
 {
     SaveSong(null);
     GameRegistry.SetValue("isEditing", true);
     SceneManager.LoadScene("main");
 }
예제 #10
0
 public void LoadSong()
 {
     GameRegistry.SetValue("CUR_SONG", Path.GetFileNameWithoutExtension(_selectedFile));
     SceneManager.LoadScene("songEditor");
     CloseWindow();
 }
예제 #11
0
파일: Song.cs 프로젝트: Amatsugu/MikuSecret
 public Song(string songPath, int trackCount)
 {
     this.info       = new SongInfo("no title", "no artist", "no album", "no year", "normal", GameRegistry.GetString("UserName"));
     this.songPath   = songPath;
     this.trackCount = trackCount;
     FillTracks(trackCount);
 }
예제 #12
0
        void Update()
        {
            if (_song.song.loadState != AudioDataLoadState.Loaded)
            {
                return;
            }
            if (GameRegistry.GetBool("isEditing"))
            {
                if (Input.GetKeyUp(KeyCode.Escape))
                {
                    SceneManager.LoadScene("songEditor");
                }
            }
            //Render Time
            _curProgress = _src.time;
            int m = (int)(_curProgress / 60);
            int s = (int)_curProgress - m * 60;

            timeText.text = m + ":" + s;
            //Render Progress Bar
            progressBar.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, (_curProgress / _songLength) * Screen.width);
            //Render beat tracks
            for (int i = 0; i < _trackCount; i++)
            {
                List <Beat> track = _song.tracks[i].beats;
                foreach (Beat b in track)
                {
                    //Skips beats that are already hit
                    if (b.hit)
                    {
                        continue;
                    }
                    //Skips beats that aren't within the lead time
                    if (b.time - leadTime > _curProgress)
                    {
                        continue;
                    }
                    //Move the beats towards the hitzone based on th ecurrent progress of the audio track
                    Vector3 p = b.GetPosition();
                    p.y = Mathf.Lerp(b.startPosition, hitZoneOffset, 1 - ((b.time - _curProgress) / leadTime));
                    if (b.duration <= 0)
                    {
                        b.UpdatePosition(p);
                    }
                    else
                    {
                        //Calculate the trail length
                        float pos = b.duration + b.time;
                        pos -= _curProgress;
                        pos /= leadTime;
                        float trailHeight = Mathf.Lerp(hitZoneOffset, _basePositions[i].y, pos);
                        trailHeight -= b.GetPosition().y;
                        b.UpdatePosition(p, trailHeight);
                    }

                    //Marks missed beats for removal
                    if (_curProgress - b.time - b.duration > hitRange + hitZoneSize)
                    {
                        _beatsToRemove.Add(b);
                        _targetRemovalTrack.Add(i);
                    }
                    //Checks the accuary of an attempted hit
                    KeyCode key = _controls.GetKey(i, _trackCount);
                    if (b.duration <= 0)
                    {
                        if (Input.GetKeyDown(key))
                        {
                            //Checks if there was a hit
                            if (Mathf.Abs(_curProgress - b.time) <= hitRange)
                            {
                                combo++;
                                //Marks a beat as being hit
                                b.hit = true;
                                //Calculates the hit accuracy
                                float hitValue = CalculateAcc(b.time);
                                //Adds scire
                                score         += hitValue * beatValue;
                                scoreText.text = score.ToString();
                                //Creates a particle burst proportional to the point value of the hit
                                SpawnParticles((int)(hitValue * hitParticleCount), b.GetPosition(), hitValue, _song.tracks[i].color);
                                //Marks the beat for removal
                                _beatsToRemove.Add(b);
                                _targetRemovalTrack.Add(i);
                            }
                            //Checks for a miss
                            else if (Mathf.Abs(_curProgress - b.time) <= hitRange + hitZoneSize)
                            {
                                combo = 0;
                            }
                        }
                    }
                    else
                    {
                        //Start the long beat
                        if (float.IsNegativeInfinity(b.hitStart) && !b.hit)
                        {
                            if (Mathf.Abs(_curProgress - b.time) <= hitRange)
                            {
                                if (Input.GetKeyDown(key))
                                {
                                    combo++;
                                    b.startAcc = CalculateAcc(b.time);
                                    b.hitStart = _curProgress;
                                    SpawnParticles((int)(b.startAcc * hitParticleCount), b.GetPosition(), b.startAcc, _song.tracks[i].color);
                                }
                            }
                        }
                        else
                        {
                            //Sustain the long beat
                            if (Input.GetKey(key))
                            {
                                if (_curProgress <= b.time + b.duration)
                                {
                                    score += Mathf.Round(beatValue * Time.deltaTime * combo);
                                    SpawnParticles((int)Mathf.Round(hitParticleCount * Time.deltaTime * b.startAcc), b.GetPosition(), b.startAcc, _song.tracks[i].color);
                                    scoreText.text = score.ToString();
                                }
                            }
                            //End the long beat
                            if (Input.GetKeyUp(key))
                            {
                                b.hit = true;
                                if (Mathf.Abs(_curProgress - b.time - b.duration) <= hitRange)
                                {
                                    //Calculates hit accuracy
                                    float hitValue = CalculateAcc(b.time - b.duration);
                                    //Adds scire
                                    score         += hitValue * beatValue * combo;
                                    scoreText.text = score.ToString();
                                }
                                else
                                {
                                    combo = 0;
                                    Debug.Log("Miss, Long");
                                }
                                //Marks the beat for removal
                                _beatsToRemove.Add(b);
                                _targetRemovalTrack.Add(i);
                            }
                        }
                    }
                }
            }

            //Remove used and missed beats
            for (int i = 0; i < _beatsToRemove.Count; i++)
            {
                Beat b = _beatsToRemove[i];
                b.Destroy();
                _song.tracks[_targetRemovalTrack[i]].RemoveBeat(b);
            }
            _beatsToRemove.Clear();
            _targetRemovalTrack.Clear();
        }