Ejemplo n.º 1
0
    private STOPS GetStop(NotesInfo info, bool isLN = false)
    {
        STOPS stop = null;

        float pos = info.bar + ((float)info.th / info.barOriginTh);

        if (isLN)
        {
            pos = info.LNend_bar + (info.LNend_th / info.LNend_barOriginTh);
        }

        for (int i = 0; i < data_STOP.Count; i++)
        {
            if (pos <= data_STOP[i].stopTiming)
            {
                if (i == 0)
                {
                    stop = data_STOP[i];
                }
                else
                {
                    stop = data_STOP[i /* - 1*/];
                }
                break;
            }
            stop = data_STOP[i];
        }
        if (stop == null)
        {
            stop = data_STOP[data_STOP.Count - 1];
        }

        return(stop);
    }
Ejemplo n.º 2
0
    private BPMS GetBPM(NotesInfo info, bool isLN = false)
    {
        BPMS bpm = null;

        float pos = info.bar + ((float)info.th / info.barOriginTh);

        if (isLN)
        {
            pos = info.LNend_bar + (info.LNend_th / info.LNend_barOriginTh);
        }

        for (int i = 0; i < data_BPM.Count; i++)
        {
            if (pos < data_BPM[i].changeTiming)
            {
                if (i == 0)
                {
                    bpm = data_BPM[i];
                }
                else
                {
                    bpm = data_BPM[i - 1];
                }
                break;
            }
        }
        if (bpm == null)
        {
            bpm = data_BPM[data_BPM.Count - 1];
        }

        return(bpm);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// 譜面を生成するよ
    /// </summary>
    private void GenerateScore()
    {
        if (data_BPM.Count == 0)
        {
            Debug.LogWarning("BPM情報が見つかりませんでした");
            return;
        }

        Init_noteObjects();

        float offset = data_OFFSET;

        float[] xPos = { -7.0f, -5.0f, -3.0f, -1.0f };
        for (int x = 0; x < data_MusicScore.Length; x++)
        {
            for (int y = 0; y < data_MusicScore[x].Count; y++)
            {
                NotesInfo info = data_MusicScore[x][y];
                BPMS      bpm  = GetBPM(info);
                STOPS     stop = GetStop(info);

                GameObject obj        = Instantiate(notesPrefab);
                float      noteBarPos = (float)info.bar + (float)info.th / (float)info.barOriginTh;

                NotesScript note = obj.AddComponent <NotesScript>();
                note.stopdata = stop;

                note.notesTiming = bpm.currentTime + 240f / bpm.BPM * (noteBarPos - bpm.changeTiming);
                note.type        = info.type;
                obj.transform.SetParent(parentObj.transform);

                float yPos = bpm.currentLength_Total + (noteBarPos - bpm.changeTiming) * bpm.scoreLengthPerBar * bpm.correctionNum;

                obj.transform.localPosition = new Vector3(xPos[x], yPos * multi, 0f);

                if (info.type == ScoreIndex.LONG)
                {
                    GameObject obj2 = Instantiate(notesPrefab);
                    noteBarPos = (float)info.LNend_bar + (float)info.LNend_th / (float)info.LNend_barOriginTh;

                    note.LNendObj = obj2;
                    note.lr       = obj.AddComponent <LineRenderer>();
                    note          = obj2.AddComponent <NotesScript>();

                    note.type        = ScoreIndex.LONG_END;
                    note.notesTiming = bpm.currentTime + 240f / bpm.BPM * (noteBarPos - bpm.changeTiming);
                    obj2.transform.SetParent(parentObj.transform);
                    yPos = bpm.currentLength_Total + (noteBarPos - bpm.changeTiming) * bpm.scoreLengthPerBar * bpm.correctionNum;

                    obj2.transform.localPosition = new Vector3(xPos[x], yPos * multi, 0f);
                    obj2.transform.SetParent(obj.transform);
                }

                noteObjects[x].Enqueue(obj);
            }
        }
    }
Ejemplo n.º 4
0
    private void STOPData_Add(List <int> data)
    {
        for (int i = 0; i < data_STOP.Count; i++)
        {
            data_STOP[i].stopTiming_OriginTh = data[data_STOP[i].stopTiming_Bar];
            data_STOP[i].stopTiming          = data_STOP[i].stopTiming_Bar +
                                               ((float)data_STOP[i].stopTiming_Th / data_STOP[i].stopTiming_OriginTh);

            NotesInfo info = new NotesInfo();

            info.bar         = data_STOP[i].stopTiming_Bar;
            info.th          = data_STOP[i].stopTiming_Th;
            info.barOriginTh = data_STOP[i].stopTiming_OriginTh;

            BPMS bpm = GetBPM(info);

            float afterPos  = data_STOP[i].stopTiming;
            float beforePos = bpm.changeTiming;

            data_STOP[i].stopTiming_Time = bpm.currentTime +
                                           240f / bpm.BPM * (afterPos - beforePos);

            data_STOP[i].stopTiming_AfterTime = data_STOP[i].stopTiming_Time + data_STOP[i].stopTime;

            if (i == 0)
            {
                continue;
            }

            data_STOP[i].totalStopTime         = data_STOP[i - 1].stopTime + data_STOP[i - 1].totalStopTime;
            data_STOP[i].stopTiming_Time      += data_STOP[i].totalStopTime;
            data_STOP[i].stopTiming_AfterTime += data_STOP[i].totalStopTime;
        }

        STOPS addData = new STOPS();

        addData.stopTiming_Time = float.MaxValue;
        if (data_STOP.Count == 0)
        {
            data_STOP.Add(addData);
            return;
        }
        STOPS basestop = data_STOP[data_STOP.Count - 1];

        addData.totalStopTime = basestop.totalStopTime + basestop.stopTime;
        data_STOP.Add(addData);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// 譜面を作るんじゃい
    /// </summary>
    /// <param name="sr">StringReader</param>
    private void MakeMusic(StringReader sr, LoadMode mode = LoadMode.Normal)
    {
        //初期化
        Init_data_MusicScore();
        //元のデータね
        string data = sr.ReadToEnd();
        //1小節ごとに分けたデータ
        List <string> score_String = new List <string>();
        //これを入れていくよ
        string score_Bar    = null;
        bool   isCommentOut = false;

        for (int i = 0; i < data.Length; i++)
        {
            string str = data.Substring(i, 1);

            if (str == "\n" || str == "\r")
            {
                isCommentOut = false;
                continue;
            }

            if (isCommentOut)
            {
                continue;
            }

            if (str == " ")
            {
                continue;
            }

            if (str == "/")
            {
                if (data.Substring(i + 1, 1) == "/")
                {
                    isCommentOut = true;
                }
                continue;
            }

            if (str == "," || str == ";")
            {
                if (score_Bar != null)
                {
                    score_String.Add(score_Bar);
                    score_Bar = null;
                }
                continue;
            }

            score_Bar += str;
        }

        //譜面入れてくよ
        for (int bar = 0; bar < score_String.Count; bar++)
        {
            //--1小節ごと
            string barStr      = score_String[bar];
            int    barOriginTh = barStr.Length / data_KEY;
            originThs.Add(barOriginTh);

            Debug.Log(bar + ":" + bar * 4 + "-" + (bar * 4 + 3) + "=" + barOriginTh + "th");

            for (int num = 0; num < barStr.Length; num++)
            {
                //--1文字ごと
                string score = barStr.Substring(num, 1);
                int    key   = num % data_KEY;
                int    th    = (num - key) / data_KEY;
                foreach (KeyValuePair <ScoreIndex, string> pair in NotesDictionary)
                {
                    if (score == pair.Value)
                    {
                        ScoreIndex index = pair.Key;

                        //----- 無視処理 -----//
                        if (index == ScoreIndex.none)
                        {
                            break;
                        }

                        if (index == ScoreIndex.MINE)
                        {
                            notesData.MineNote++;
                            break;
                        }

                        //----- サブ処理 -----//

                        if (index == ScoreIndex.SIMPLE)
                        {
                            notesData.SimpleNote++;
                        }
                        else if (index == ScoreIndex.LONG_START)
                        {
                            notesData.LongNote++;
                        }

                        //----- 分岐 -----//

                        if (mode != LoadMode.Normal)
                        {
                            break;
                        }

                        //----- メイン処理 -----//

                        if (index == ScoreIndex.LONG_END)
                        {
                            data_MusicScore[key][data_MusicScore[key].Count - 1].type              = ScoreIndex.LONG;
                            data_MusicScore[key][data_MusicScore[key].Count - 1].LNend_bar         = bar;
                            data_MusicScore[key][data_MusicScore[key].Count - 1].LNend_th          = th;
                            data_MusicScore[key][data_MusicScore[key].Count - 1].LNend_barOriginTh = barOriginTh;
                            break;
                        }

                        NotesInfo note = new NotesInfo();

                        note.bar         = bar;
                        note.th          = th;
                        note.barOriginTh = barOriginTh;
                        note.type        = index;

                        data_MusicScore[key].Add(note);

                        //Debug.Log(note.type.ToString() + ":" + (note.bar + 1) + "小節目:" + (note.th + 1) + "分目");
                        break;
                    }
                }
            }
        }
    }
Ejemplo n.º 6
0
    public void Convert(TextAsset textAsset, DataType type)
    {
        obj = new GameObject();
        MusicManager manager = obj.AddComponent <MusicManager>();

        manager.MusicLoad(textAsset, LoadMode.PreLoad);
        if (manager.data_DataType == type)
        {
            Debug.LogError("変換元と変換先のDataTypeが一致しています");
            EditorApplication.delayCall += DestroyObj;
            return;
        }

        string filePath   = AssetDatabase.GetAssetPath(textAsset);
        string folderPath = Path.GetDirectoryName(filePath);
        string path       = Directory.GetParent(UnityEngine.Application.dataPath) + "/" + folderPath + "/converted.txt";

        using (File.Create(path)) { };
        StreamWriter sw = new StreamWriter(path);

        bool cont = true;

        int[] laneIndex = new int[manager.data_MusicScore.Length];
        while (cont)
        {
            cont = false;
            NotesInfo info = null;
            int       tgt  = 0;

            for (int lane = 0; lane < manager.data_MusicScore.Length; lane++)
            {
                if (manager.data_MusicScore[lane].Count == laneIndex[lane])
                {
                    continue;
                }

                if (info == null)
                {
                    info = manager.data_MusicScore[lane][laneIndex[lane]];
                    tgt  = lane;
                    cont = true;
                }
                else
                {
                    float     info_time = (float)info.bar + (float)info.th / (float)info.barOriginTh;
                    NotesInfo tgtInfo   = manager.data_MusicScore[lane][laneIndex[lane]];
                    float     tgt_time  = (float)tgtInfo.bar + (float)tgtInfo.th / (float)tgtInfo.barOriginTh;
                    if (tgt_time < info_time)
                    {
                        info = tgtInfo;
                        tgt  = lane;
                    }
                }
            }
            if (cont)
            {
                string str = "[" + tgt + "," + ((int)info.type) + "," + info.bar + "." + info.th + "/" + info.barOriginTh + "]";
                sw.WriteLine(str);
                laneIndex[tgt]++;
            }
        }

        //for(int lane = 0; lane < manager.data_MusicScore.Length; lane++)
        //{
        //    foreach(NotesInfo notes in manager.data_MusicScore[lane])
        //    {
        //        string str = "[" + lane + "," + ((int)notes.type) + "," + notes.bar + "." + notes.th + "/" + notes.barOriginTh + "]";
        //        Debug.Log(str);
        //        sw.WriteLine(str);
        //    }
        //}
        sw.Close();


        EditorApplication.delayCall += DestroyObj;
    }