Esempio n. 1
0
    private void DropDraggedPrompt()
    {
        if (gridSnapping)
        {
            Vector3 droppedPosition = selectedPrompt.transform.localPosition;

            Vector3 gridPosition = GetGridSnappedPosition(droppedPosition);

            StopCoroutine(draggingPrompt);
            selectedPrompt.transform.localPosition = gridPosition;
        }

        SavePromptLocationToAsset(selectedPrompt.GetIndex(), selectedPrompt.transform.localPosition);

        //clear the cached reference
        selectedPrompt = null;
    }
Esempio n. 2
0
    private void StartDragPrompt(DrumGamePrompt prompt)
    {
        //If successful, cache a ref to scene Prompt obj
        selectedPrompt = prompt;

        //Save its current position to our undo history
        AddToUndoHistory(prompt.GetIndex(), prompt.transform.localPosition);
        ClearRedoHistory();

        //Start dragging!
        if (draggingPrompt != null)
        {
            StopCoroutine(draggingPrompt);
        }

        draggingPrompt = StartCoroutine(DraggingPrompt());
    }
Esempio n. 3
0
    /// <summary>
    /// Returns the first prompt hit by a raycast, or null if none available
    /// </summary>
    private DrumGamePrompt TryRaycastToPrompt()
    {
        //Raycast into scene
        var pointerEventData = new PointerEventData(eventSystem);

        pointerEventData.position = Input.mousePosition;

        List <RaycastResult> results = new List <RaycastResult>();

        raycaster.Raycast(pointerEventData, results);

        if (results.Count > 0)
        {
            //Check for collisions with objects holding a Prompt
            DrumGamePrompt prompt = results[0].gameObject.GetComponentInParent <DrumGamePrompt>();
            return(prompt);
        }

        else
        {
            return(null);
        }
    }
    protected override void SpawnAndArrangePrompts(DrumSequence next)
    {
        if (next.type != DrumSequence.SequenceType.Circle)
        {
            return;
        }

        //Add needed prompts
        while (prompts.Count < next.keys.Count)
        {
            GameObject promptObj = Instantiate(promptPrefab, wheelPivotT);
            promptObj.SetActive(true);
            DrumGamePrompt prompt = promptObj.GetComponent <DrumGamePrompt>();
            prompt.SetHighlightVisible(false);
            prompts.Add(prompt);
        }

        //Remove extras
        while (prompts.Count > next.keys.Count)
        {
            DrumGamePrompt last = prompts[prompts.Count - 1];
            prompts.Remove(last);
            Destroy(last.gameObject);
        }

        //Arrange around a circle
        float radius = promptPrefab.transform.localPosition.y;

        for (int i = 0; i < prompts.Count; i++)
        {
            float phaseRadians = ((i / (float)prompts.Count) * 360f) * Mathf.Deg2Rad;
            float x            = radius * Mathf.Sin(phaseRadians);
            float y            = radius * Mathf.Cos(phaseRadians);

            prompts[i].transform.localPosition = new Vector3(x, y, 0);
        }
    }
Esempio n. 5
0
    protected override void SpawnAndArrangePrompts(DrumSequence next)
    {
        if (next.type != DrumSequence.SequenceType.Line)
        {
            return;
        }

        //Add needed prompts
        while (prompts.Count < next.keys.Count)
        {
            GameObject promptObj = Instantiate(promptPrefab, this.transform);
            promptObj.SetActive(true);
            promptObj.transform.SetParent(promptParent.transform);
            DrumGamePrompt prompt = promptObj.GetComponent <DrumGamePrompt>();
            prompt.SetIndex(prompts.Count);
            prompt.SetHighlightVisible(false);
            prompts.Add(prompt);
        }

        //Remove extras
        while (prompts.Count > next.keys.Count)
        {
            DrumGamePrompt last = prompts[prompts.Count - 1];
            prompts.Remove(last);
            Destroy(last.gameObject);
        }

        //Arrange according to coordinate info

        for (int i = 0; i < prompts.Count; i++)
        {
            prompts[i].transform.localPosition = next.coords[i];
        }

        segmentHighlighter.DrawSegments(next.coords, next.showLine);
    }
Esempio n. 6
0
    void Update()
    {
        if (isEditing.Value)
        {
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                DrumGamePrompt selectedPrompt = TryRaycastToPrompt();

                if (selectedPrompt != null && !Input.GetKey(KeyCode.LeftShift))
                {
                    StartDragPrompt(selectedPrompt);
                }
                else if (selectedPrompt != null && Input.GetKey(KeyCode.LeftShift))
                {
                    ToggleShowLine(selectedPrompt.GetIndex());
                }
            }

            if (selectedPrompt != null && Input.GetKeyUp(KeyCode.Mouse0))
            {
                DropDraggedPrompt();
            }

            if (Input.GetAxis("Mouse ScrollWheel") > 0)
            {
                ChangeCameraZoom(25);
            }

            if (Input.GetAxis("Mouse ScrollWheel") < 0)
            {
                ChangeCameraZoom(-25);
            }

            if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(saveZoomoutPositionKey))
            {
                SaveZoomoutPosition();
            }

            //TODO: add these to the undo/redo history... might require changing the model
            if (Input.GetKeyDown(addNewPrompt))
            {
                AddPromptUnderCursor(DrumSequence.DrumKey.One);
            }

            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                AddPromptUnderCursor(DrumSequence.DrumKey.One);
            }

            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                AddPromptUnderCursor(DrumSequence.DrumKey.Two);
            }

            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                AddPromptUnderCursor(DrumSequence.DrumKey.Three);
            }

            if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                AddPromptUnderCursor(DrumSequence.DrumKey.Four);
            }

            if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                AddPromptUnderCursor(DrumSequence.DrumKey.Five);
            }

            if (Input.GetKeyDown(KeyCode.Alpha6))
            {
                AddPromptUnderCursor(DrumSequence.DrumKey.Six);
            }

            if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                AddPromptUnderCursor(DrumSequence.DrumKey.Seven);
            }

            if (Input.GetKeyDown(delLastPrompt))
            {
                DeleteLastPrompt();
            }

            if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(undoKey))
            {
                Undo();
            }

            if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(redoKey))
            {
                Redo();
            }
        }

        if (Input.GetKeyDown(toggleSnapToGrid))
        {
            gridSnapping = !gridSnapping;
        }

        if (Input.GetKeyDown(toggleAutoRedraw))
        {
            autoRedrawSegments = !autoRedrawSegments;
        }
    }