Esempio n. 1
0
        private void UDPMessageReceivedHandler(NetInMessage message)
        {
            int    fingerNum = message.ReadInt32();
            double voltage   = message.ReadDouble();

            switch (fingerNum)
            {
            case 1:
                lineGraph1.Plot(t, voltage);
                break;

            case 2:
                lineGraph2.Plot(t, voltage);
                break;

            case 3:
                lineGraph3.Plot(t, voltage);
                break;

            case 4:
                lineGraph4.Plot(t, voltage);
                break;

            case 5:
                lineGraph5.Plot(t, voltage);
                break;
            }
        }
Esempio n. 2
0
        private void UDPMessageReceivedHandler(NetInMessage message)
        {
            int commandInt = message.ReadInt32();

            MessageType.Command command = (MessageType.Command)commandInt;
            if (command == MessageType.Command.Data)
            {
                for (int i = 0; i < 5; i++)
                {
                    int   fin_num  = message.ReadInt32();
                    float velocity = message.ReadFloat();
                    Cylinders[fin_num].transform.localScale = new Vector3(CyliSize * velocity, 0.003f, CyliSize * velocity);
                }
            }
            else if (command == MessageType.Command.Control)
            {
                //MidiDebug.text = "Command: Control";
                MessageType.ControlType controlType = (MessageType.ControlType)message.ReadInt32();
                if (controlType == MessageType.ControlType.SpawnNote)
                {
                    int NoteCount = message.ReadInt32();
                    DestroyScore(Origins);
                    //Debug.Log("notecount = " + NoteCount);
                    //MidiDebug.text = "Control Type: SpawnNote";

                    for (int i = 0; i < NoteCount - 1; i++)
                    {
                        //Debug.Log(i);
                        Vector3 NoteInfo = message.ReadVector3();

                        GameObject note = Instantiate(note_obj);
                        note.transform.SetParent(Origins[(int)NoteInfo.x].transform);

                        note.GetComponent <RectTransform>().localPosition = new Vector3(0, NoteInfo.y, 0);
                        note.GetComponent <RectTransform>().sizeDelta     = new Vector2(0.02f, NoteInfo.z);
                        note.GetComponent <RectTransform>().localRotation = Quaternion.Euler(Vector3.zero);
                        note.GetComponent <RawImage>().color = FingerColor[(int)NoteInfo.x];
                    }
                    //MidiDebug.text = "count = " + NoteCount;
                    message.ReadVector3();

                    int LastTime = message.ReadInt32();

                    for (int i = 0; i < LastTime; i++)
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            GameObject bar = Instantiate(bar_obj);
                            bar.transform.SetParent(Origins[j].transform);

                            bar.GetComponent <RectTransform>().localPosition = new Vector3(0, i / scale, 0);
                            //bar.GetComponent<RectTransform>().sizeDelta = new Vector2(0.03f, 1 / scale);
                            bar.GetComponent <RectTransform>().localRotation = Quaternion.Euler(Vector3.zero);
                            bar.transform.SetAsFirstSibling();
                        }
                    }
                }
                else if (controlType == MessageType.ControlType.DestroyNote)
                {
                }
                else if (controlType == MessageType.ControlType.PlaySong)
                {
                    tempo = message.ReadFloat();
                    GetComponent <Move>().PlayMusic(tempo);
                }
                else if (controlType == MessageType.ControlType.StopSong)
                {
                    GetComponent <Move>().ResetPosition();
                }
                else if (controlType == MessageType.ControlType.ChangeColor)
                {
                    int     fin_num = message.ReadInt32();
                    Vector3 RGB     = message.ReadVector3();

                    Cylinders[fin_num].GetComponent <Renderer>().material.color = new Color(RGB.x, RGB.y, RGB.z, 1.0f);
                }
                else if (controlType == MessageType.ControlType.ChangeTempo)
                {
                    tempo          = message.ReadFloat();
                    MidiDebug.text = "tempo = " + tempo;
                    GetComponent <Move>().ChangeDy(tempo);
                }
            }
        }
        private void UDPMessageReceivedHandler(NetInMessage message)
        {
            message.ResetIndex();

            MessageType.Command command = (MessageType.Command)message.ReadInt32();
            if (command == MessageType.Command.Data)
            {
                for (int i = 0; i < 5; i++)
                {
                    int   fingerIndex = message.ReadInt32();
                    float plotValue   = message.ReadFloat();

                    FingerForceGraphs[fingerIndex].value = Mathf.FloorToInt(plotValue);
                    forceScalingNoteActivators[fingerIndex].GetComponent <ForceScalingNoteActivatorController>().SetForcePercentage(plotValue);
                }
            }
            else if (command == MessageType.Command.Control)
            {
                MessageType.ControlType controlType = (MessageType.ControlType)message.ReadInt32();
                if (controlType == MessageType.ControlType.PlaySong)
                {
                    int songIndex = message.ReadInt32();

                    audioSource.clip = songList.songs[songIndex].audioClip;
                    audioSource.loop = false;
                    audioSource.Play();
                }
                else if (controlType == MessageType.ControlType.StopSong)
                {
                    audioSource.Stop();

                    noteSpawner.DeleteAllNotes();
                }
                else if (controlType == MessageType.ControlType.SpawnNote)
                {
                    int     spawnIndex         = message.ReadInt32();
                    float   duration           = message.ReadFloat();
                    Vector3 locationInNoteLane = message.ReadVector3();

                    noteSpawner.SpawnHoldNote(spawnIndex, locationInNoteLane, duration);
                }
                else if (controlType == MessageType.ControlType.SpawnForceScalingNote)
                {
                    int     spawnIndex         = message.ReadInt32();
                    float   duration           = message.ReadFloat();
                    Vector3 locationInNoteLane = message.ReadVector3();
                    float   noteScaleX         = message.ReadFloat();

                    noteSpawner.SpawnForceScalingNote(spawnIndex, locationInNoteLane, noteScaleX, duration);
                }
                else if (controlType == MessageType.ControlType.InitVisualizations)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        int   fingerIndex = message.ReadInt32();
                        float minTargetValuePercentage = message.ReadFloat();
                        float maxTargetValuePercentage = message.ReadFloat();

                        FingerForceGraphs[fingerIndex].minTargetValue = Mathf.FloorToInt(minTargetValuePercentage);
                        FingerForceGraphs[fingerIndex].maxTargetValue = Mathf.FloorToInt(maxTargetValuePercentage);

                        forceScalingNoteActivators[fingerIndex].GetComponent <ForceScalingNoteActivatorController>().SetForceRangePercentage(minTargetValuePercentage, maxTargetValuePercentage);
                    }
                }
                else if (controlType == MessageType.ControlType.PressKey)
                {
                    KeyCode key = (KeyCode)message.ReadInt32();
                    CustomInput.PressKey(key);
                }
                else if (controlType == MessageType.ControlType.ReleaseKey)
                {
                    KeyCode key = (KeyCode)message.ReadInt32();
                    CustomInput.ReleaseKey(key);
                }
                else if (controlType == MessageType.ControlType.ChangeForceScalingMode)
                {
                    int isForceScalingMode = message.ReadInt32();

                    SetForceScalingModeValue(isForceScalingMode == 1);
                }
            }
        }
        private void UDPMessageReceivedHandler(NetInMessage message)
        {
            MessageType.Command command = (MessageType.Command)message.ReadInt32();
            if (command == MessageType.Command.Control)
            {
                MessageType.ControlType controlType = (MessageType.ControlType)message.ReadInt32();
                if (controlType == MessageType.ControlType.SpawnObstacle)
                {
                    float yPos    = message.ReadFloat();
                    float gapSize = message.ReadFloat();

                    GameObject obstacleObj = m_obstacleSpawner.SpawnObstacle(yPos, gapSize);

                    Vector3 upperPipeScale = message.ReadVector3();
                    Vector3 lowerPipeScale = message.ReadVector3();

                    ObstacleController obstacle = obstacleObj.GetComponent <ObstacleController>();
                    obstacle.upperPipe.transform.localScale = upperPipeScale;
                    obstacle.lowerPipe.transform.localScale = lowerPipeScale;
                }
                else if (controlType == MessageType.ControlType.PlayerPosition)
                {
                    Vector3 playerPosition = message.ReadVector3();

                    m_playerController.transform.localPosition = playerPosition;
                }
                else if (controlType == MessageType.ControlType.Start)
                {
                    m_gameState.isGameOver.Value = false;
                    m_gameState.score.Value      = 0;

                    m_obstacleSpawner.ResetState();
                }
                else if (controlType == MessageType.ControlType.TriggerGameOver)
                {
                    m_gameState.isGameOver.Value = true;
                }
                else if (controlType == MessageType.ControlType.UpdateScore)
                {
                    int score = message.ReadInt32();
                    m_gameState.score.Value = score;
                }
                else if (controlType == MessageType.ControlType.ChangeActiveFingers)
                {
                    int        numActiveFingers = message.ReadInt32();
                    List <int> activeFingers    = new List <int>();
                    for (int i = 0; i < numActiveFingers; i++)
                    {
                        int activeFingerIndex = message.ReadInt32();
                        activeFingers.Add(activeFingerIndex);
                    }

                    for (int i = 0; i < fingerIndicators.Count; i++)
                    {
                        bool isFingerActive = activeFingers.Contains(i);
                        fingerIndicators[i].IsVisible = isFingerActive;
                        if (isFingerActive)
                        {
                            fingerIndicators[i].SetIsOn(true);
                        }
                    }
                }
            }
        }