Beispiel #1
0
    // Spawns a flick note
    // Definition of a FLICKNOTE: [offset, noteType, startPath,endPath,flickDirection]
    public static void SpawnFlick(string[] def)
    {
        // Change the name of the note for easier debugging.
        noteID = "Note " + noteIndex.ToString();
        noteIndex++;

        if (def.Length != 5)
        {
            Debug.Log("Note type doesn't match the note parameters");
            return;
        }

        float offset    = float.Parse(def[0]) / 1000f;
        int   startPath = int.Parse(def[2]);
        int   endPath   = int.Parse(def[3]);
        bool  direction = bool.Parse(def[4]);

        string definition = Conductor.songPosition.ToString() + "," + startPath + "," + endPath + "," + direction;

        Vector3   spawnPosition = new Vector3((NotePath.NotePaths[startPath].transform.position.x + NotePath.NotePaths[endPath].transform.position.x) / 2, basePosition.y, basePosition.z);
        NoteFlick n             = (NoteFlick)GetNoteFromPool(NoteType.Flick);

        n.Construct(spawnPosition, offset, startPath, endPath, direction, noteID);
        n.gameObject.SetActive(true);
    }
Beispiel #2
0
    private void PreloadNotes()
    {
        for (int i = 0; i < noteAmount; i++)
        {
            Note tempNote = Instantiate(Note, spawnPosition, BoardObject.rotation).GetComponent <Note>();
            NoteList.Add(tempNote);
            tempNote.gameObject.SetActive(false);

            NoteFlick tempFlick = Instantiate(Flick, spawnPosition, BoardObject.rotation).GetComponent <NoteFlick>();
            FlickList.Add(tempFlick);
            tempFlick.gameObject.SetActive(false);

            NoteHold tempHold = Instantiate(Hold, spawnPosition, BoardObject.rotation).GetComponent <NoteHold>();
            HoldList.Add(tempHold);
            tempHold.gameObject.SetActive(false);
        }

        for (int i = 0; i < dragAmount; i++)
        {
            NoteDrag tempDrag = Instantiate(Drag, spawnPosition, BoardObject.rotation).GetComponent <NoteDrag>();
            DragList.Add(tempDrag);
            tempDrag.gameObject.SetActive(false);
        }
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        // Detect a touch from the screen.
        if (Input.GetButtonDown("Touch"))
        {
            //GameObject note = GameObject.Find("Note");
            //note.GetComponent<Note>().ChangeMaterial();

            // Add one to the touches list.
            fingersTouching += 1;

            // Player clicks...
            // Determine which Notepath was hit.
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit[] hitObjects = Physics.RaycastAll(ray, 1000f, layermask);
            NotePath hitPath;
            Debug.Log("Number of objects hit: " + hitObjects.Length);
            for (int i = 0; i < hitObjects.Length; i++)
            {
                // If we hit a Notepath...
                if (hitObjects[i].collider.tag == "NotePath")
                {
                    hitPath = hitObjects[i].collider.gameObject.GetComponent<NotePath>();
                    Debug.Log("Hit Object: " + hitPath.name);
                    flickDragEnabled = hitPath.CheckIfValidHit();
                    if (flickDragEnabled)
                    {
                        Debug.Log("Time to drag!");
                        endFlickPath = NotePath.NotePaths[hitPath.ActiveNotes[0].pathEnd];
                        activeNoteFlick = (NoteFlick)hitPath.ActiveNotes[0];
                    }
                    break;
                }

                // Drag the sliderbar
                else if (hitObjects[i].collider.tag == "SliderBar")
                {
                    Debug.Log("We have hit the sliderbar");
                    // First, center the slider to the mouse position, and set the offset
                    Slider.transform.position = new Vector3(hitObjects[i].point.x, Slider.transform.position.y, Slider.transform.position.z);
                    offset = Slider.transform.position - hitObjects[i].point;
                    distanceFromRayOrigin = (ray.origin - hitObjects[i].point).magnitude;
                    sliderDragEnabled = true;
                    // Here we will cache the touch ID and send it to the Sliderbar
                }
            }
        }

        // Remove that finger from the amount of total fingers touching
        if (Input.GetButtonUp("Touch"))
        {
            fingersTouching -= 1;
            sliderDragEnabled = false;
            flickDragEnabled = false;
        }

        // If we are dragging an the slider
        else if (sliderDragEnabled)
        {
            // This will be replaced with finger location via finger ID
            // TODO: See if there is an easier way to do this 1-Dimmentional Movement
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Vector3 oldPosition = Slider.transform.position;
            Vector3 newXPosition = ray.GetPoint(distanceFromRayOrigin) + offset;
            Slider.transform.position = new Vector3(newXPosition.x, oldPosition.y, oldPosition.z);
        }

        // If the player is currently flicking
        if (flickDragEnabled)
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit[] hitObjects = Physics.RaycastAll(ray, 1000f, layermask);
            Debug.Log("We have hit: " + hitObjects.Length);
            for (int i = 0; i < hitObjects.Length; i++)
            {
                if (hitObjects[i].collider.tag == "NotePath")
                {
                    Debug.Log("Currently dragging along path: " + hitObjects[i].collider.gameObject.GetComponent<NotePath>().NotePathID);
                    if (hitObjects[i].collider.gameObject.GetComponent<NotePath>().NotePathID == endFlickPath.NotePathID && activeNoteFlick != null)
                    {
                        activeNoteFlick.CalculateError();
                        activeNoteFlick = null;
                    }
                }
            }

            /* Code that should work, but for some reason, doesn't
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, mask))
            {
                Debug.Log(hit.collider.name);
                Debug.Log("We are currently dragging along path " + hit.collider.gameObject.GetComponent<NotePath>().NotePathID);
            } */
        }
    }