Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        // 更新song 的时间位置 与 节拍位置
        songPosition  = (float)(AudioSettings.dspTime - dspTimeSong);
        songPosInBeat = songPosition / secPerBeat;

        // Debug.Log(songPosition);
        for (int trackind = 0; trackind < 4; ++trackind)
        {
            // 判定每个轨道是否需要生成新的 音符
            if (song_note.ReadyToSpawn(trackind, nextSpawnIndex[trackind], songPosInBeat, BeatAdvance))
            {
                //Debug.Log("ReadyToSpawn!");
                // 实例化位置
                int posX = 0;
                switch (trackind)
                {
                case 0: posX = -9; break;

                case 1: posX = -3; break;

                case 2: posX = 3; break;

                case 3: posX = 9; break;

                default: break;
                }
                //实例化 并为其改名
                GameObject mk_GP = Instantiate(Resources.Load("mk_GP"),
                                               new Vector3(posX, -10, 30), Quaternion.identity) as GameObject;
                mk_GP.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, -velocity);

                // 多轨道tag , Hit 时根据tag 销毁
                mk_GP.name = trackind.ToString() + '-' + nextSpawnIndex[trackind].ToString();

                nextSpawnIndex[trackind]++;
            }
            // 判定当前Hit位置是否需要检索下一个Note
            if (song_note.ReadyToMove(trackind, nextIndex[trackind], songPosInBeat))
            {
                nextIndex[trackind]++;
            }
        }

        // 是否 按键 Hit 轨道
        bool[] HitTrackInd = new bool[4];
        // Input GetKey 这个操作以后需要封装到 另一个GameObject player 里统一得到 输入 信息. ezio 191113
        // HitTrackInd[0] = Input.GetKey(KeyCode.D)?true:false;
        // HitTrackInd[1] = Input.GetKey(KeyCode.F)?true:false;
        // HitTrackInd[2] = Input.GetKey(KeyCode.J)?true:false;
        // HitTrackInd[3] = Input.GetKey(KeyCode.K)?true:false;
        play_input.DoseHit(HitTrackInd);

        for (int trackind = 0; trackind < 4; ++trackind)
        {
            if (HitTrackInd[trackind])
            {
                //根据 当前拍子时间计算 最近的Note下标
                int nearestInd = song_note.GetNearestIndex(trackind, nextIndex[trackind], songPosInBeat);
                if (PreHitIndex[trackind] == nearestInd)
                {
                    // 命中过则不在计算
                }
                else
                {
                    float TimeDif = song_note.HitDif(trackind, nearestInd, songPosInBeat);
                    if (score_manager.DoesGetHit(TimeDif))
                    {
                        // 更改PreHitIndex信息 , 并立刻销毁之前实例化的对象
                        PreHitIndex[trackind] = nearestInd;

                        GameObject obj = GameObject.Find(trackind.ToString()
                                                         + '-' + PreHitIndex[trackind].ToString());
                        DestroyImmediate(obj);

                        // Debug.Log("Hit !!");
                    }
                }
            }
        }

        progress_degree.UpdateText(GetComponent <AudioSource>().time);
        if (progress_degree.IsOver())
        {
            //给下一个场景传递得分
            SelectionMsg.Instance().cntPerfect = score_manager.GetCntPerfect();
            SelectionMsg.Instance().cntGood    = score_manager.GetCntGood();
            SelectionMsg.Instance().cntMiss    = score_manager.GetCntMiss();
            SelectionMsg.Instance().score      = score_manager.GetTotalScore();

            float ScoreMole = 1f * score_manager.GetTotalScore();
            float ScoreDeno = 1f * score_manager.Perfect_Score * song_note.GetCntTotNote();
            //为分数定级
            if (ScoreMole / ScoreDeno > 0.95f)
            {
                SelectionMsg.Instance().scoreDegree = 0;
            }
            else if (ScoreMole / ScoreDeno > 0.8f)
            {
                SelectionMsg.Instance().scoreDegree = 1;
            }
            else
            {
                SelectionMsg.Instance().scoreDegree = 2;
            }
            StartCoroutine(Delay());
        }
    }