private void Awake() { pressedCode = null; countdown = 3f; currentCalibratedButton = DanceMatInput.Up; numberOfButtons = System.Enum.GetValues(typeof(DanceMatInput)).Length; DanceMatInputManager.inputToCode.Clear(); }
public static bool GetAnyInput() { for (int i = 0; i < danceMatInputsArray.Length; i++) { DanceMatInput input = (DanceMatInput)danceMatInputsArray.GetValue(i); if (getInput[input]) { return(true); } } return(false); }
// Returns which mat button was pressed on the current frame. private DanceMatInput GetDanceMatKeyDown() { for (int i = 0; i < danceMatInputsArray.Length; i++) { DanceMatInput input = (DanceMatInput)danceMatInputsArray.GetValue(i); if (DanceMatInputManager.GetInput(input)) { return(input); } } return(DanceMatInput.Up); }
private IEnumerator CalibrateKeys() { while ((int)currentCalibratedButton < numberOfButtons) { while (pressedCode == null || ButtonHasBeenRegistered()) { yield return(new WaitForEndOfFrame()); } switch (currentCalibratedButton) { case DanceMatInput.Up: messageDisplay.text = "Agora aperte a seta para baixo"; break; case DanceMatInput.Down: messageDisplay.text = "Aperte para esquerda"; break; case DanceMatInput.Left: messageDisplay.text = "E para direita"; break; case DanceMatInput.Right: messageDisplay.text = "Aperte X"; break; case DanceMatInput.Cross: messageDisplay.text = "Aperte quadrado"; break; case DanceMatInput.Square: messageDisplay.text = "Aperte triângulo"; break; case DanceMatInput.Triangle: messageDisplay.text = "Aperte círculo"; break; case DanceMatInput.Circle: messageDisplay.text = "Calibragem completa.\nAperte qualquer botão para começar"; break; } DanceMatInputManager.inputToCode.Add(currentCalibratedButton, pressedCode); pressedCode = null; currentCalibratedButton = (DanceMatInput)((int)currentCalibratedButton + 1); } DanceMatInputManager.isInitialized = true; }
private void CheckInput() { // If manager wasn't initialized or no button was pressed, do nothing. if (!DanceMatInputManager.isInitialized || !DanceMatInputManager.GetAnyInput()) { return; } // Gets which button was pressed on current frame DanceMatInput pressedButton = GetDanceMatKeyDown(); // If the pressed button is different than the last pressed button, // increases the score if (pressedButton != lastPressedInput) { DoFootStep(); Grape closestGrape = GetClosestGrape(); if (closestGrape) { float hitRadius = ResourcesMaster.instance.hitRadius; if ((closestGrape.transform.position - target.position).sqrMagnitude < hitRadius * hitRadius) { audioSource.PlayOneShot(grapeSquashing); float resourcePerTap = ResourcesMaster.instance.resourcesPerTap; ResourcesMaster.AddResource(generatedResourceName, resourcePerTap); steppedGrapesColors.Add(closestGrape.colorSpectrumValue); if (steppedGrapesColors.Count > 10) { steppedGrapesColors.RemoveAt(0); } } else { feedbackPanel.SetAlpha(0f); feedbackPanel.DOFade(0.5f, 0.5f).From(); //float resourcePerTap = ResourcesMaster.instance.danceMatProperties.resourcesPerTap; //float usedResources = ResourcesMaster.GetResourceData(generatedResourceName).requiredToGeneratedRatio * resourcePerTap; //ResourcesMaster.RemoveRequiredResource(generatedResourceName, usedResources); } fallingGrapes.Remove(closestGrape); Destroy(closestGrape.gameObject); GameMaster.instance.collectActivity.RemoveGrapeByColor(closestGrape.colorSpectrumValue); } } // Saves current button as last pressed button for next frame. lastPressedInput = pressedButton; }
private void Update() { if (!isInitialized) { return; } for (int i = 0; i < danceMatInputsArray.Length; i++) { DanceMatInput input = (DanceMatInput)danceMatInputsArray.GetValue(i); bool isInputPressed = IsInputPressed(input); getInputDown[input] = getInputDown[input] == false && isInputPressed; getInput[input] = isInputPressed; } }
private bool IsInputPressed(DanceMatInput input) { DanceMatInputCode code = inputToCode[input]; if (code.type == InputType.Axis) { return(Input.GetAxisRaw(code.axisName) == code.axisDirection); } else if (code.type == InputType.Key) { return(Input.GetKey(code.keycode)); } Debug.Log(string.Concat(input.ToString(), " is undefined.")); return(false); }
private void Awake() { if (instance != this) { Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); getInput = new Dictionary <DanceMatInput, bool>(); getInputDown = new Dictionary <DanceMatInput, bool>(); for (int i = 0; i < danceMatInputsArray.Length; i++) { DanceMatInput input = (DanceMatInput)danceMatInputsArray.GetValue(i); getInput.Add(input, false); getInputDown.Add(input, false); } isInitialized = false; }
public static bool GetInput(DanceMatInput input) { return(getInput[input]); }