Esempio n. 1
0
        public void ApplyChangeActiveFingers()
        {
            int        numActiveFingers = 0;
            List <int> activeFingers    = new List <int>();

            for (int i = 0; i < activeFingerToggles.Count; i++)
            {
                Finger finger = (Finger)i;
                m_gameState.ActiveFingers[finger] = activeFingerToggles[i].isOn;

                if (activeFingerToggles[i].isOn)
                {
                    numActiveFingers++;

                    activeFingers.Add(i);
                }
            }

            NetOutMessage message = new NetOutMessage();

            message.WriteInt32((int)MessageType.Command.Control);
            message.WriteInt32((int)MessageType.ControlType.ChangeActiveFingers);
            message.WriteInt32(numActiveFingers);

            for (int i = 0; i < activeFingers.Count; i++)
            {
                message.WriteInt32(activeFingers[i]);
            }

            m_udpHelper.Send(message, m_appState.HololensIP, Constants.NETWORK_PORT);
        }
        private void FingerDataReceivedHandler(Dictionary <Finger, double> forceValues)
        {
            foreach (Finger finger in forceValues.Keys)
            {
                int   fingerIndex = (int)finger;
                float fingerForce = (float)(forceValues[finger] - m_appState.GetCurrentHandData().GetFingerBaseForce(finger));

                if (MathUtils.IsInRange(fingerForce, fingerForceMinThresholds[fingerIndex], fingerForceMaxThresholds[fingerIndex]))
                {
                    CustomInput.PressKey(keyMappings[fingerIndex]);

                    NetOutMessage outMessage = new NetOutMessage();

                    outMessage.WriteInt32((int)MessageType.Command.Control);
                    outMessage.WriteInt32((int)MessageType.ControlType.PressKey);
                    outMessage.WriteInt32((int)keyMappings[fingerIndex]);

                    m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);
                }
                else
                {
                    CustomInput.ReleaseKey(keyMappings[fingerIndex]);

                    NetOutMessage outMessage = new NetOutMessage();

                    outMessage.WriteInt32((int)MessageType.Command.Control);
                    outMessage.WriteInt32((int)MessageType.ControlType.ReleaseKey);
                    outMessage.WriteInt32((int)keyMappings[fingerIndex]);

                    m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);
                }
            }
        }
Esempio n. 3
0
        void StartStopSend()
        {
            if (Input.GetKeyUp(KeyCode.Space))
            {
                NetOutMessage outMessage = new NetOutMessage();
                outMessage.WriteInt32((int)MessageType.Command.Control);

                if (playing_music)  //Stop the music
                {
                    client.Send("/start", 0);
                    m_scoremanage.SaveScore();

                    outMessage.WriteInt32((int)MessageType.ControlType.StopSong);
                }
                else   //Start the music
                {
                    client.Send("/start", 1);

                    outMessage.WriteInt32((int)MessageType.ControlType.PlaySong);
                    outMessage.WriteFloat(m_scoreMove.tempo);
                }

                m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);

                playing_music = !playing_music;
            }
        }
        private void ScoreValueChangedHandler(int oldScore, int newScore)
        {
            NetOutMessage outMessage = new NetOutMessage();

            outMessage.WriteInt32((int)MessageType.Command.Control);
            outMessage.WriteInt32((int)MessageType.ControlType.UpdateScore);
            outMessage.WriteInt32(newScore);

            m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);
        }
        void OnTriggerStay(Collider other)  //noteが来ている間
        {
            if (!note_in)
            {
                note_in = true;
            }

            if (pressing && !changedColor)   //押していたら
            {
                changedColor = true;
                correct      = true;
                ignore       = false;

                //HoloLensのCylinderの色を変える
                NetOutMessage outMessage = new NetOutMessage();
                outMessage.WriteInt32((int)MessageType.Command.Control);
                outMessage.WriteInt32((int)MessageType.ControlType.ChangeColor);
                outMessage.WriteInt32((int)finger_num[chr]);

                if (chr == 'c')
                {
                    this.GetComponent <Renderer>().material.color = Color.red;
                    outMessage.WriteVector3(new Vector3(1, 0, 0));
                }
                else if (chr == 'v')
                {
                    this.GetComponent <Renderer>().material.color = Color.yellow;
                    outMessage.WriteVector3(new Vector3(1, 1, 0));
                }
                else if (chr == 'b')
                {
                    this.GetComponent <Renderer>().material.color = Color.green;
                    outMessage.WriteVector3(new Vector3(0, 1, 0));
                }
                else if (chr == 'n')
                {
                    this.GetComponent <Renderer>().material.color = Color.cyan;
                    outMessage.WriteVector3(new Vector3(0, 1, 1));
                }
                else if (chr == 'm')
                {
                    this.GetComponent <Renderer>().material.color = Color.blue;
                    outMessage.WriteVector3(new Vector3(0, 0, 1));
                }
                m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);
            }
            else if (!pressing && changedColor)
            {
                this.GetComponent <Renderer>().material.color = Color.white;
                correct      = false;
                changedColor = false;
            }
        }
Esempio n. 6
0
    public void SetTempo()
    {
        m_scoreMove.ChangeDy(SongTempo);

        //Send to HoloLens
        NetOutMessage outMessage = new NetOutMessage();

        outMessage.WriteInt32((int)MessageType.Command.Control);
        outMessage.WriteInt32((int)MessageType.ControlType.ChangeTempo);

        outMessage.WriteFloat(SongTempo);

        m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);
    }
        public void StartGame()
        {
            ResetState();

            m_gameState.isPlaying = true;

            m_isSpawning = true;

            NetOutMessage outMessage = new NetOutMessage();

            outMessage.WriteInt32((int)MessageType.Command.Control);
            outMessage.WriteInt32((int)MessageType.ControlType.Start);

            m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);
        }
Esempio n. 8
0
        // Update is called once per frame
        void Update()
        {
            NetOutMessage outMessage = new NetOutMessage();

            outMessage.WriteInt32((int)MessageType.Command.Data);
            //outMessage.WriteInt32((int)MessageType.ControlType.KeyVelocity);

            for (int i = 0; i < Data.Count; i++)
            {
                outMessage.WriteInt32(i);
                outMessage.WriteFloat(Data[i]);
            }

            m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);
        }
        private void FingerForceDataReceivedHandler(Dictionary <Finger, double> forceData)
        {
            if (m_gameState.isGameOver.Value)
            {
                return;
            }

            double sumMax = 0;
            double sum    = 0;

            foreach (Finger finger in forceData.Keys)
            {
                if (m_gameState.ActiveFingers[finger])
                {
                    sumMax += m_appState.GetCurrentHandData().GetFingerMaxForce(finger);
                    sum    += forceData[finger] - m_appState.GetCurrentHandData().GetFingerBaseForce(finger);
                }
            }

            if (sum < 0.0)
            {
                sum = 0.0;
            }

            if (sumMax > 0.0)
            {
                float percentage = (float)(sum / sumMax);

                float topY    = topBorderTransform.localPosition.y;
                float bottomY = bottomBorderTransform.localPosition.y;

                float playerY        = bottomY + (topY - bottomY) * percentage;
                float playerCurrentY = m_playerController.transform.localPosition.y;

                Vector3 translateVector = new Vector3(0.0f, playerY - playerCurrentY, 0.0f);
                m_playerController.transform.localPosition += translateVector;

                NetOutMessage outMessage = new NetOutMessage();
                outMessage.WriteInt32((int)MessageType.Command.Control);
                outMessage.WriteInt32((int)MessageType.ControlType.PlayerPosition);
                outMessage.WriteVector3(m_playerController.transform.localPosition);

                m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);
            }
        }
        private void IsGameOverValueChangedHandler(bool oldValue, bool newValue)
        {
            Time.timeScale = newValue ? 0.0f : 1.0f;

            if (newValue)
            {
                m_isSpawning      = false;
                m_timeToNextSpawn = 0.0f;

                m_gameState.isPlaying = false;

                NetOutMessage outMessage = new NetOutMessage();
                outMessage.WriteInt32((int)MessageType.Command.Control);
                outMessage.WriteInt32((int)MessageType.ControlType.TriggerGameOver);

                m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);
            }
        }
Esempio n. 11
0
        private void OnTriggerExit(Collider other)  //noteが出たら
        {
            //other.enabled = false;
            changedColor = false;
            note_in      = false;

            this.GetComponent <Renderer>().material.color = Color.white;

            NetOutMessage outMessage = new NetOutMessage();

            outMessage.WriteInt32((int)MessageType.Command.Control);
            outMessage.WriteInt32((int)MessageType.ControlType.ChangeColor);
            outMessage.WriteInt32((int)finger_num[chr]);
            outMessage.WriteVector3(new Vector3(255, 255, 255));
            m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);

            if (ignore)
            {
                //scmn.ignored_note += 1;
            }
        }
        private void Update()
        {
            if (!m_isSpawning)
            {
                return;
            }

            m_startTime            += Time.deltaTime;
            m_gameState.score.Value = (int)m_startTime;

            m_timeToNextSpawn -= Time.deltaTime;
            if (m_isSpawning && (m_timeToNextSpawn <= 0.0f))
            {
                float distanceToNextPipe = Random.Range(minDistanceBetweenPipes, maxDistanceBetweenPipes);
                m_timeToNextSpawn = distanceToNextPipe / (m_obstacleSpawner.scroller.scrollSpeed * m_obstacleSpawner.scroller.scrollSpeedMultiplier);

                float      gapSize     = Random.Range(gapSizeLowerBound, gapSizeUpperBound);
                float      obstacleY   = Random.Range(bottomBorderTransform.localPosition.y + gapSize / 2.0f, topBorderTransform.localPosition.y - gapSize / 2.0f);
                GameObject obstacleObj = m_obstacleSpawner.SpawnObstacle(obstacleY, gapSize);

                ObstacleController obstacle       = obstacleObj.GetComponent <ObstacleController>();
                Vector3            upperPipeScale = obstacle.upperPipe.transform.localScale;
                Vector3            lowerPipeScale = obstacle.lowerPipe.transform.localScale;
                upperPipeScale.y = topBorderTransform.localPosition.y - obstacleObj.transform.localPosition.y - obstacle.gapSize / 2.0f;
                lowerPipeScale.y = obstacleObj.transform.localPosition.y - bottomBorderTransform.localPosition.y - obstacle.gapSize / 2.0f;
                obstacle.upperPipe.transform.localScale = upperPipeScale;
                obstacle.lowerPipe.transform.localScale = lowerPipeScale;

                NetOutMessage outMessage = new NetOutMessage();
                outMessage.WriteInt32((int)MessageType.Command.Control);
                outMessage.WriteInt32((int)MessageType.ControlType.SpawnObstacle);
                outMessage.WriteFloat(obstacleY);
                outMessage.WriteFloat(gapSize);
                outMessage.WriteVector3(upperPipeScale);
                outMessage.WriteVector3(lowerPipeScale);

                m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);
            }
        }
Esempio n. 13
0
    public static void Read_midi(byte[] midi_byte, GameObject obj, int tick, int freq, List <int> fingers, bool multifinger_mode, AppState m_appState, UDPHelper m_udpHelper, ScoreMove m_scoreMove, KeyManager m_keyManager, scoremanage m_scoremanage, GameObject BarObj)
    {
        Stack <Vector3> notes = new Stack <Vector3>();

        notes.Push(new Vector3(0, -100, 0.01f));

        int[]                     noteOn_time    = new int[128]; //各キーのnote-onの時間
        int                       tick_time      = 0;            //delta_time累積値
        bool                      in_MTrk        = false;
        float                     min_noteLength = 4 / (float)freq;
        float                     scale          = 50.0f;
        SortedSet <int>           keySet         = new SortedSet <int>();
        List <KeyManager.KeyInfo> ListKeyInfo    = new List <KeyManager.KeyInfo>();


        List <Color> FingerColor = new List <Color>()
        {
            new Color(1, 0.5f, 0.5f, 1),
            new Color(1, 1, 0.5f, 1),
            new Color(0.5f, 1, 0.5f, 1),
            new Color(0.5f, 1, 1, 1),
            new Color(0.5f, 0.5f, 1, 1)
        };

        GameObject origin, pre_note = Instantiate(obj);

        origin = GameObject.Find("ScoreOrigin");
        pre_note.transform.SetParent(origin.transform);
        pre_note.GetComponent <RectTransform>().localPosition = new Vector3(0.0f, -100f, 0.0f);

        m_keyManager.KeyInfoInit();

        for (int i = 4; i < midi_byte.Length; i++)
        {
            //トラックチャンク初め(4D 54 72 6B)と終わり(00 FF 2F 00)
            if (midi_byte[i] == 77 && midi_byte[i + 1] == 84 && midi_byte[i + 2] == 114 && midi_byte[i + 3] == 107)
            {
                in_MTrk = true;
                i      += 8; //MTrkとlengthを飛ばす
            }
            else if (midi_byte[i] == 0 && midi_byte[i + 1] == 255 && midi_byte[i + 2] == 47 && midi_byte[i + 3] == 0)
            {
                in_MTrk = false;
                break;
            }

            if (in_MTrk)
            {
                int[] tuple_time_size = Variable2int(midi_byte, i);  //(delta_time, data size of delta_time)
                tick_time += tuple_time_size[0];
                i         += tuple_time_size[1];

                if (midi_byte[i] == 144)   //90: note on
                {
                    int key = midi_byte[i + 1];
                    noteOn_time[key] = tick_time;    //noteの先頭の位置

                    i += 2;
                }
                else if (midi_byte[i] == 128) //80: note off
                {
                    int key = midi_byte[i + 1];
                    keySet.Add(key);

                    KeyManager.KeyInfo m_keyInfo;
                    m_keyInfo.key     = key;
                    m_keyInfo.OnTime  = noteOn_time[key] / (float)tick;
                    m_keyInfo.OffTime = tick_time / (float)tick;

                    m_keyInfo.tag = 0;

                    ListKeyInfo.Add(m_keyInfo);

                    i += 2;
                }
                else if (midi_byte[i] == 192)   //C0
                {
                    i += 1;
                }
                else if (midi_byte[i] == 176 || midi_byte[i] == 224)   //B0, E0
                {
                    i += 2;
                }
                else if (midi_byte[i] == 255)   //FF
                {
                    i += midi_byte[i + 2] + 2;
                }
            }
        }

        //Assign notes to five buttons
        int[] keyMap = new int[128];
        //Debug.Log("fingers: " + fingers.Count);
        int assignNum = fingers[0], ind = 0;

        foreach (var key in keySet)
        {
            keyMap[key] = assignNum;
            ind         = (ind + 1) % fingers.Count;
            assignNum   = fingers[ind];
        }
        foreach (var _keyinfo in ListKeyInfo)
        {
            // Spawn the note object
            float      note_height = _keyinfo.OffTime - _keyinfo.OnTime;
            Vector3    pos         = new Vector3((assignNum - 2) * fingerInterval, _keyinfo.OnTime, 0);
            Vector2    siz         = new Vector2(noteWidth, Mathf.Max(note_height, (float)(1.0 / 8.0)));
            GameObject note        = Instantiate(obj);
            note.transform.SetParent(origin.transform);
            note.GetComponent <RectTransform>().sizeDelta = siz;
            note.GetComponent <RawImage>().color          = FingerColor[assignNum];
            float   pre_y    = pre_note.GetComponent <RectTransform>().localPosition.y;
            float   pre_size = pre_note.GetComponent <RectTransform>().sizeDelta.y;
            Vector3 SendVec; //(fin_num, y_position, Height)
            if (pos.y - pre_y < min_noteLength || (assignNum == keyMap[_keyinfo.key] && pos.y - (pre_y + pre_size) < 1.0 / 8.0))
            {                //結合
                note_height = pos.y + siz.y - pre_y;

                note.GetComponent <RectTransform>().localPosition = new Vector3(pos.x, pre_y, 0);
                note.GetComponent <RectTransform>().sizeDelta     = new Vector3(noteWidth, note_height);

                Destroy(pre_note);
                notes.Pop();

                SendVec = new Vector3(assignNum, pre_y / scale, note_height / scale);
                notes.Push(SendVec);
            }
            else
            {
                assignNum = keyMap[_keyinfo.key];
                note.GetComponent <RectTransform>().localPosition = pos = new Vector3((assignNum - 2) * fingerInterval, _keyinfo.OnTime, 0);;
                note.GetComponent <RawImage>().color = FingerColor[assignNum];

                SendVec = new Vector3(assignNum, pos.y / scale, note_height / scale);
                notes.Push(SendVec);
            }

            /*
             * if (multifinger_mode)
             * {
             *  Clone(note, fingers);
             * }
             */
            m_keyManager.KeyInfoList[assignNum].Add(_keyinfo);
            note.GetComponent <BoxCollider>().center = new Vector3(0, note_height / 2.0f, 0);
            note.GetComponent <BoxCollider>().size   = new Vector3(0.5f, note_height, 0.2f);

            pre_note = note;
        }


        for (int i = 0; i < m_keyManager.KeyInfoList.Count; i++)
        {
            m_keyManager.KeyInfoList[i].Sort((a, b) => FloatSort(a.OnTime, b.OnTime));
        }
        m_keyManager.KeyInit();

        int LastTime = tick_time / tick;

        if (tick_time % tick != 0)
        {
            LastTime++;
        }
        m_scoreMove.MusicLength = LastTime;
        for (int i = 0; i < LastTime; i++)
        {
            GameObject barInstance = Instantiate(BarObj);
            barInstance.transform.SetParent(origin.transform);
            barInstance.GetComponent <RectTransform>().localPosition = new Vector3(0, i, 0);
            barInstance.transform.SetAsFirstSibling();
        }

        NetOutMessage outMessage = new NetOutMessage();

        outMessage.WriteInt32((int)MessageType.Command.Control);
        outMessage.WriteInt32((int)MessageType.ControlType.SpawnNote);

        int NumberofNotes = notes.Count;

        m_scoremanage.NofNote = notes.Count - 1;
        outMessage.WriteInt32(NumberofNotes);
        //Debug.Log("Number of notes is " + (NumberofNotes - 1));

        while (notes.Count > 0)
        {
            outMessage.WriteVector3(notes.Peek());
            notes.Pop();
        }

        outMessage.WriteInt32(LastTime);

        m_udpHelper.Send(outMessage, m_appState.HololensIP, Constants.NETWORK_PORT);
    }