コード例 #1
0
 private byte[] ProcessMinion(IMinion minion)
 {
     if (minion is NoteStart)
     {
         int       Channel = 0;
         NoteStart m       = minion as NoteStart;
         return(new byte[] { (byte)(Control.NoteOn + Channel), (byte)m.NotePitch, (byte)m.Velocity });
     }
     else if (minion is NoteEnd)
     {
         int     Channel = 0;
         NoteEnd m       = minion as NoteEnd;
         return(new byte[] { (byte)(Control.NoteOff + Channel), (byte)m.NotePitch, 0 });
     }
     else if (minion is DrumStart)
     {
         int       Channel = 9;
         DrumStart m       = minion as DrumStart;
         return(new byte[] { (byte)(Control.NoteOn + Channel), (byte)(35 + m.DrumPitch), (byte)m.Velocity });
     }
     else if (minion is DrumEnd)
     {
         int     Channel = 9;
         DrumEnd m       = minion as DrumEnd;
         return(new byte[] { (byte)(Control.NoteOff + Channel), (byte)(35 + m.DrumPitch), 0 });
     }
     else if (minion is InstrumentChange)
     {
         int Channel        = 0;
         InstrumentChange m = minion as InstrumentChange;
         return(new byte[] { (byte)(Control.Program + Channel), (byte)m.NewInstrument, 0 });
     }
     else if (minion is NoOp)
     {
         return(null);
     }
     throw new InvalidOperationException("Minion not recognised for processing: " + minion);
 }
コード例 #2
0
    public void ProcessControlTouch(TouchCover touch)
    {
        if (!gameStarted)
        {
            return;
        }
        if (touch == null)
        {
            return;
        }

        //Touch Press
        if (touch.phase == TouchPhase.Began)
        {
            Vector2 rayOrigin = noteCamera.ScreenToWorldPoint(touch.position);

            //check if mouse hit any object?
            RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.zero, 100, ProjectConstants.Layers.MainGameMask);
            if (hit && hit.transform != null)
            {
                string hitObjName = hit.transform.name.ToLower();

                //start object?
                if (gameplay.CurrentGameStage != TileMasterGamePlay.GameState.Playing)
                {
                    if (hitObjName.Contains("start"))
                    {
                        //game start
                        NoteStart noteStart = hit.transform.gameObject.GetComponent <NoteStart>();
                        if (noteStart != null)
                        {
                            noteStart.Press(touch);
                        }
                    }
                }

                //tiles?
                if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Playing ||
                    gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Continue ||
                    gameplay.CurrentGameStage == TileMasterGamePlay.GameState.AutoPlay)
                {
                    if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Continue)
                    {
                        gameplay.StartGame();
                    }

                    if (hitObjName.Contains("simple_"))
                    {
                        NoteSimple simple = hit.transform.gameObject.GetComponent <NoteSimple>();
                        if (simple != null && CanTouchNote(simple))
                        {
                            simple.Press(touch);
                        }
                    }
                    else if (hitObjName.Contains("multi_"))
                    {
                        NoteMulti multi = hit.transform.gameObject.GetComponent <NoteMulti>();
                        if (multi != null && CanTouchNote(multi))
                        {
                            multi.Press(touch);
                            multi.OnShowUIWhenPress(GetRootPositionHit(touch));
                        }
                    }
                    else if (hitObjName.Contains("bonus"))
                    {
                        NoteBonus bonus = hit.transform.gameObject.GetComponent <NoteBonus>();
                        if (bonus != null)
                        {
                            bonus.Press(null);
                        }
                    }
                }
            }
            else
            {
                //if the touch didn't hit any note, check for hit on background
                RaycastHit2D bgCheck = Physics2D.Raycast(rayOrigin, Vector2.zero, 100, ProjectConstants.Layers.BackgroundMask);
                if (bgCheck.transform != null)
                {
                    if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Playing ||
                        gameplay.CurrentGameStage == TileMasterGamePlay.GameState.AutoPlay)
                    {
                        if (CheckGameOver(touch))
                        {
                            GameOverByPressWrong(touch);
                        }
                    }
                    else if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Continue)
                    {
                        gameplay.StartGame();
                    }
                }
            }
        }

        // Touch Hold
        else if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
        {
            OnHoldTouch(touch);
        }
        else
        {
            ResetTouch(touch);
        }
    }