protected virtual void UpdateColor() { float r, g, b, a; //Interpolate between initial color and end color based on current audio data, making sure not to go passed the end color //If buffer is applied if (bufferDecreaseSpeed > 0 || bufferIncreaseSpeed > 0) { r = initialColor.r + (endColor.r - initialColor.r) * valueBuffer * colorChangeSpeed; if ((r > endColor.r && endColor.r > initialColor.r) || (r < endColor.r && endColor.r < initialColor.r)) { r = endColor.r; } g = initialColor.g + (endColor.g - initialColor.g) * valueBuffer * colorChangeSpeed; if ((g > endColor.g && endColor.g > initialColor.g) || (g < endColor.g && endColor.g < initialColor.g)) { g = endColor.g; } b = initialColor.b + (endColor.b - initialColor.b) * valueBuffer * colorChangeSpeed; if ((b > endColor.b && endColor.b > initialColor.b) || (b < endColor.b && endColor.b < initialColor.b)) { b = endColor.b; } a = initialColor.a + (endColor.a - initialColor.a) * valueBuffer * colorChangeSpeed; if ((a > endColor.a && endColor.a > initialColor.a) || (a < endColor.a && endColor.a < initialColor.a)) { a = endColor.a; } } //no buffer else { float raw = AudioVisualizer.getRawAudioRange(range); r = (endColor.r - initialColor.r) * raw * colorChangeSpeed; if ((r > endColor.r && endColor.r > initialColor.r) || (r < endColor.r && endColor.r < initialColor.r)) { r = endColor.r; } g = (endColor.g - initialColor.g) * raw * colorChangeSpeed; if ((g > endColor.g && endColor.g > initialColor.g) || (g < endColor.g && endColor.g < initialColor.g)) { g = endColor.g; } b = (endColor.b - initialColor.b) * raw * colorChangeSpeed; if ((b > endColor.b && endColor.b > initialColor.b) || (b < endColor.b && endColor.b < initialColor.b)) { b = endColor.b; } a = (endColor.a - initialColor.a) * raw * colorChangeSpeed; if ((a > endColor.a && endColor.a > initialColor.a) || (a < endColor.a && endColor.a < initialColor.a)) { a = endColor.a; } } rend.material.color = new Color(r, g, b, a); }
/// <summary> /// Scale x, y, and/or z based on input settings /// </summary> protected virtual void UpdateScale() { //Check if any scaling occurs if (scaleX || scaleY || scaleZ) { Vector3 currentScale = initialScale; if (scaleX) { //If buffer is applied if (bufferDecreaseSpeed > 0 || bufferIncreaseSpeed > 0) { currentScale.x += valueBuffer * scaleFactor.x; } //no buffer else { currentScale.x += AudioVisualizer.getRawAudioRange(range) * scaleFactor.x; } } if (scaleY) { //If buffer is applied if (bufferDecreaseSpeed > 0 || bufferIncreaseSpeed > 0) { currentScale.y += valueBuffer * scaleFactor.y; } //no buffer else { currentScale.y += AudioVisualizer.getRawAudioRange(range) * scaleFactor.y; } } if (scaleZ) { //If buffer is applied if (bufferDecreaseSpeed > 0 || bufferIncreaseSpeed > 0) { currentScale.z += valueBuffer * scaleFactor.z; } //no buffer else { currentScale.z += AudioVisualizer.getRawAudioRange(range) * scaleFactor.z; } } transform.localScale = currentScale; } }
/// <summary> /// Move x, y, and/or z based on input settings /// </summary> protected virtual void UpdatePosition() { //Check if any scaling occurs if (moveX || moveY || moveZ) { Vector3 currentPosition = intialPosition; if (moveX) { //If buffer is applied if (bufferDecreaseSpeed > 0 || bufferIncreaseSpeed > 0) { currentPosition.x += valueBuffer * moveFactor.x; } //no buffer else { currentPosition.x += AudioVisualizer.getRawAudioRange(range) * moveFactor.x; } } if (moveY) { //If buffer is applied if (bufferDecreaseSpeed > 0 || bufferIncreaseSpeed > 0) { currentPosition.y += valueBuffer * moveFactor.y; } //no buffer else { currentPosition.y += AudioVisualizer.getRawAudioRange(range) * moveFactor.y; } } if (moveZ) { //If buffer is applied if (bufferDecreaseSpeed > 0 || bufferIncreaseSpeed > 0) { currentPosition.z += valueBuffer * moveFactor.z; } //no buffer else { currentPosition.z += AudioVisualizer.getRawAudioRange(range) * moveFactor.z; } } transform.position = currentPosition; } }
/// <summary> /// Rotate x, y, and/or z based on input settings /// </summary> protected virtual void UpdateRotation() { //Check if any scaling occurs if (rotX || rotY || rotZ) { Vector3 currentRotation = intialRotation; if (rotX) { //If buffer is applied if (bufferDecreaseSpeed > 0 || bufferIncreaseSpeed > 0) { currentRotation.x += valueBuffer * rotFactor.x; } //no buffer else { currentRotation.x += AudioVisualizer.getRawAudioRange(range) * rotFactor.x; } } if (rotY) { //If buffer is applied if (bufferDecreaseSpeed > 0 || bufferIncreaseSpeed > 0) { currentRotation.y += valueBuffer * rotFactor.y; } //no buffer else { currentRotation.y += AudioVisualizer.getRawAudioRange(range) * rotFactor.y; } } if (rotZ) { //If buffer is applied if (bufferDecreaseSpeed > 0 || bufferIncreaseSpeed > 0) { currentRotation.z += valueBuffer * rotFactor.z; } //no buffer else { currentRotation.z += AudioVisualizer.getRawAudioRange(range) * rotFactor.z; } } transform.localRotation = Quaternion.Euler(currentRotation); } }
protected virtual void UpdateBuffer() { float currentValue = AudioVisualizer.getRawAudioRange(range); float sqrtDifference = Mathf.Sqrt(Mathf.Abs(currentValue - valueBuffer)); if (currentValue < valueBuffer && bufferDecreaseSpeed != 0) { float decreaseAmount = bufferDecreaseSpeed; if (scaleDecreaseWithTime) { timeSinceLastIncrease += Time.deltaTime; decreaseAmount *= timeSinceLastIncrease; } else { decreaseAmount *= Time.deltaTime; } if (easeOutDecrease) { decreaseAmount *= sqrtDifference; } valueBuffer -= decreaseAmount; if (scaleIncreaseWithTime) { timeSinceLastDecrease = 0f; } if (valueBuffer < currentValue) { valueBuffer = currentValue; } } else if (currentValue > valueBuffer && bufferIncreaseSpeed != 0) { float increaseAmount = bufferIncreaseSpeed; if (scaleDecreaseWithTime) { timeSinceLastIncrease = 0f; } if (scaleIncreaseWithTime) { timeSinceLastDecrease += Time.deltaTime; increaseAmount *= timeSinceLastDecrease; } else { increaseAmount *= Time.deltaTime; } if (easeOutIncrease) { increaseAmount *= sqrtDifference; } valueBuffer += increaseAmount; if (valueBuffer > currentValue) { valueBuffer = currentValue; } } }