Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        /*if (!GameState.Instance.Playing)
         * {
         *  startTS = Time.time;
         *  return_time = -1;
         *  return;
         * }
         *
         * if(return_time == (int)(Time.time - startTS))
         * {
         *  return;
         * }
         * if (GameState.Instance.Forward)
         * {
         *  prev_t = prev_t + 1;
         *  GameState.Instance.Forward = false;
         * }
         * if (GameState.Instance.Backward)
         * {
         *  prev_t = prev_t - 3;
         *  GameState.Instance.Backward = false;
         * }
         * return_time = (int)(Time.time - startTS);
         * int t = prev_t + 1;
         * prev_t = t;
         * Debug.Log(t);*/

        Debug.Log("Keyboard scale: ");
        Debug.Log(this.gameObject.transform.localScale);
        Debug.Log(this.gameObject.transform.lossyScale);



        double curTS = Time.time;

        if (showingGetReady)
        {
            fingerText.gameObject.SetActive(false);
            hand.gameObject.SetActive(false);
            double elapsed = curTS - getReadyStartTS;
            double mul     = 1.2;
            if (elapsed < 0.5 * mul)
            {
                getReadyButton.gameObject.GetComponent <TextMesh>().text = "3.";
            }
            else if (elapsed < 1 * mul)
            {
                getReadyButton.gameObject.GetComponent <TextMesh>().text = "3 .";
            }
            else if (elapsed < 1.5 * mul)
            {
                getReadyButton.gameObject.GetComponent <TextMesh>().text = "2.";
            }
            else if (elapsed < 2 * mul)
            {
                getReadyButton.gameObject.GetComponent <TextMesh>().text = "2 .";
            }
            else if (elapsed < 2.5 * mul)
            {
                getReadyButton.gameObject.GetComponent <TextMesh>().text = "1.";
            }
            else if (elapsed < 3 * mul)
            {
                getReadyButton.gameObject.GetComponent <TextMesh>().text = "1 .";
            }
            else if (elapsed < 3.3 * mul)
            {
                getReadyButton.gameObject.GetComponent <TextMesh>().text = "GO";
            }
            else
            {
                getReadyDone();
            }
            return;
        }

        if (sp.getPressedKeyAtTime(curTS) == null)
        {
            fingerText.gameObject.SetActive(false);
            hand.gameObject.SetActive(false);
            if (prevKeyIndex != -1)
            {
                pianoKeys[prevKeyIndex].gameObject.GetComponent <MeshRenderer>().material.color = prevKeyColor;
                prevKeyIndex = -1;
            }

            Debug.Log("not playing");
            return;
        }

        KeyPress kp = sp.getPressedKeyAtTime(curTS);

        //Debug.Log(kp.key + " " + kp.finger);

        if (kp == prevKp)
        {
            return;
        }

        if (prevKeyIndex != -1)
        {
            pianoKeys[prevKeyIndex].gameObject.GetComponent <MeshRenderer>().material.color = prevKeyColor;
        }

        for (int i = 0; i < pianoKeys.Capacity; i++)
        {
            if (pianoKeys[i].name.StartsWith(kp.key))
            {
                prevKeyColor = pianoKeys[i].gameObject.GetComponent <MeshRenderer>().material.color;
                Debug.Log("key pos: " + pianoKeys[i].gameObject.transform.position);
                Vector3 keyPos = pianoKeys[i].gameObject.transform.position;
                //fingerText.gameObject.SetActive(true);
                fingerText.gameObject.transform.position             = new Vector3(keyPos.x - 0.005f, keyPos.y, fingerTextZ);
                fingerText.gameObject.GetComponent <TextMesh>().text = kp.finger;

                hand.gameObject.SetActive(true);
                hand.gameObject.transform.position = new Vector3(keyPos.x - 0.005f, keyPos.y, handZ);
                for (int j = 0; j < 6; j++)
                {
                    Color defColor = new Color(1, 1, 1, 0.15f);
                    handFingers[j].gameObject.GetComponent <MeshRenderer>().material.color = defColor;
                }
                Color fingerColor = new Color(0.1462f, 0.7607f, 1, 1);
                if (kp.finger.Equals("rt"))
                {
                    handFingers[5].gameObject.GetComponent <MeshRenderer>().material.color = fingerColor;
                }
                else
                {
                    int fingerNum = int.Parse(kp.finger[1].ToString());
                    handFingers[fingerNum - 1].gameObject.GetComponent <MeshRenderer>().material.color = fingerColor;
                }

                Color newColor;
                if (kp.key.StartsWith("B_"))
                {
                    newColor = new Color(1, 0, 0, 1);
                }
                else
                {
                    newColor = new Color(0, 1, 0, 1);
                }
                pianoKeys[i].gameObject.GetComponent <MeshRenderer>().material.color = newColor;
                prevKeyIndex = i;

                break;
            }
        }

        prevKp = kp;
    }