Ejemplo n.º 1
0
    void Awake()
    {
        // 四个轨道的 三种Index 初始化
        for (int i = 0; i < 4; ++i)
        {
            nextSpawnIndex[i] = 0;
            PreHitIndex[i]    = -1;
            nextIndex[i]      = 0;
        }

        song_note     = GameObject.Find("NoteInfo").GetComponent <NoteInfo>();
        score_manager = GameObject.Find("ScoreManager").GetComponent <ScoreManager>();
        play_input    = GameObject.Find("Main Camera").GetComponent <PlayerInput>();
// 如果要 不build调试 就注释掉下面用这个实例加载 NoteFileName 与 MusicName
// 还有背景图的7行
        song_note.NoteFileName            = SelectionMsg.Instance().NoteTxtName;
        GetComponent <AudioSource>().clip =
            (AudioClip)Resources.Load(
                "Audios/" + SelectionMsg.Instance().MusicName,
                typeof(AudioClip));
        GameObject.Find("BGpic").GetComponent <SpriteRenderer>().sprite
            = (Sprite)Resources.Load("Textures/GameBG/" + SelectionMsg.Instance().GameBGname, typeof(Sprite));


        progress_degree = GameObject.Find("ProgressDegree").GetComponent <ProgressDegree>();
        progress_degree.Load(GetComponent <AudioSource>().clip.length);

        song_note.LoadNote();
    }
Ejemplo n.º 2
0
 public static SelectionMsg Instance()
 {
     if (ins == null)
     {
         ins = new SelectionMsg();
     }
     return(ins);
 }
Ejemplo n.º 3
0
    public void OnPointerClick(PointerEventData eventData)
    {
        SelectionMsg.Instance().NoteTxtName = NoteTxtName;
        SelectionMsg.Instance().MusicName   = MusicName;
        SelectionMsg.Instance().PicName     = PicName;
        SelectionMsg.Instance().GameBGname  = GameBGname;

        SceneManager.LoadScene("sel_game");
    }
Ejemplo n.º 4
0
    // public string testpicname;
    // Use this for initialization
    void Start()
    {
        RawImage raw = GameObject.Find("Pic").GetComponent <RawImage>();

        //仅测试图片效果
        // raw.texture = (Texture)Resources.Load(
        //              "Textures/Pic/" + testpicname
        //              ,typeof(Texture));

        raw.texture = (Texture)Resources.Load(
            "Textures/Pic/" + SelectionMsg.Instance().PicName
            , typeof(Texture));
        //传递得分情况
        GameObject.Find("SongText").GetComponent <Text>().text =
            SelectionMsg.Instance().MusicName;
        GameObject.Find("ScoreText").GetComponent <Text>().text =
            SelectionMsg.Instance().score.ToString();
        GameObject.Find("PerfectText").GetComponent <Text>().text =
            SelectionMsg.Instance().cntPerfect.ToString();
        GameObject.Find("GoodText").GetComponent <Text>().text =
            SelectionMsg.Instance().cntGood.ToString();
        GameObject.Find("MissText").GetComponent <Text>().text =
            SelectionMsg.Instance().cntMiss.ToString();


        //Load 得分等级 texture
        raw = GameObject.Find("ScoreDegree").GetComponent <RawImage>();
        if (SelectionMsg.Instance().scoreDegree == 0)
        {
            raw.texture = (Texture)Resources.Load("Textures/S", typeof(Texture));
        }
        else if (SelectionMsg.Instance().scoreDegree == 1)
        {
            raw.texture = (Texture)Resources.Load("Textures/A", typeof(Texture));
        }
        else
        {
            raw.texture = (Texture)Resources.Load("Textures/B", typeof(Texture));
        }

        //定义Back按钮
        GameObject.Find("BackButton").GetComponent <Button>
            ().onClick.AddListener(() => { OnClickBack(); });
    }
Ejemplo n.º 5
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());
        }
    }