Commented Button2Midi.cs.

This commit is contained in:
Niall Moody 2020-12-08 16:58:37 +00:00
parent 0d508db542
commit 92e64c7020
8 changed files with 422 additions and 388 deletions

View file

@ -954,7 +954,7 @@ GameObject:
m_Component:
- component: {fileID: 1780628284}
m_Layer: 0
m_Name: Bang Button
m_Name: Midi2Pd Button
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

View file

@ -26,23 +26,28 @@ using System.Collections.Generic;
using UnityEngine;
/// Script used to let the player quit by pressing Escape (in a build).
public class GameManager : MonoBehaviour {
public class GameManager : MonoBehaviour
{
/// Used to ensure we don't create another instance of GameManager if we
/// return to the MainScene.
private static bool instantiated = false;
/// We use this to ensure our GameManager doesn't get destroyed when we switch scenes.
void Awake () {
if(!instantiated) {
void Awake ()
{
if(!instantiated)
{
DontDestroyOnLoad(this.gameObject);
instantiated = true;
}
}
/// Listen for the user pressing Escape to quit.
void Update() {
if(Input.GetButton("Quit")) {
void Update()
{
if(Input.GetButton("Quit"))
{
Application.Quit();
}
}

View file

@ -26,7 +26,8 @@ using UnityEngine;
/// Script to send a random MIDI note to a PD patch when the player enters and
/// leaves a collision volume.
public class Button2Midi : MonoBehaviour {
public class Button2Midi : MonoBehaviour
{
/// The PD patch we're going to communicate with.
public LibPdInstance pdPatch;
@ -35,17 +36,29 @@ public class Button2Midi : MonoBehaviour {
/// note off message when the player exits the collision volume.
private int note;
/// We send a bang when the player steps on the button (enters the collision
/// volume).
void OnTriggerEnter(Collider other) {
/// We send a MIDI note when the player steps on the button (enters the
/// collision volume).
void OnTriggerEnter(Collider other)
{
//First, pick a random note. This should pick from an octave starting at
//middle C.
note = 60 + Mathf.FloorToInt(Random.value * 12.0f);
//Now send our MIDI note on message to our PD patch.
//SendMidiNoteOn's 3 arguments are: channel, note number, velocity
pdPatch.SendMidiNoteOn(0, note, 127);
}
/// We send a different bang when the player steps off the button (leaves
/// We send a note off message when the player steps off the button (leaves
/// the collision volume).
void OnTriggerExit(Collider other) {
void OnTriggerExit(Collider other)
{
//Send a note off message to our patch when the player leaves the
//button's collision volume.
//Note that there is no dedicated 'SendMidiNoteOff' function. To send a
//note off message we have to send a 'note on' message with a velocity
//of 0.
pdPatch.SendMidiNoteOn(0, note, 0);
}
}

View file

@ -27,7 +27,8 @@ using UnityEngine;
/// Simple first person movement script, included so we don't need to include
/// any Standard Assets (they're far heavier than we need).
public class PlayerMovement : MonoBehaviour {
public class PlayerMovement : MonoBehaviour
{
/// Used to implement mouselook on the vertical axis.
public Camera playerCamera;
@ -40,12 +41,14 @@ public class PlayerMovement : MonoBehaviour {
private float jumpAmount;
/// We use this to hide the mouse cursor.
void Start () {
void Start()
{
Cursor.visible = false;
}
/// This is where we move the Player object and Camera.
void Update () {
void Update()
{
//Get our current WASD speed.
Vector3 strafe = new Vector3(Input.GetAxis("Horizontal") * 10.0f, 0.0f, 0.0f);
float forwardSpeed = Input.GetAxis("Vertical") * 10.0f;
@ -74,9 +77,11 @@ public class PlayerMovement : MonoBehaviour {
//jumping AND on the ground, OR they are jumping but they've not reached
//the top of the jump, increase their jumpAmount and move them
//accordingly on the y-axis.
if(Input.GetButton("Jump")) {
if(Input.GetButton("Jump"))
{
if(((jumpAmount <= 0.0f) && controller.isGrounded) ||
((jumpAmount > 0.0f) && (jumpAmount < 1.0f))) {
((jumpAmount > 0.0f) && (jumpAmount < 1.0f)))
{
jumpAmount += Time.deltaTime * 5.0f;
jumpVector.y = 4.0f + ((1.0f - jumpAmount) * 20.0f);
@ -84,7 +89,8 @@ public class PlayerMovement : MonoBehaviour {
}
//Otherwise, if they're on the ground but their jumpAmount is not 0,
//reset it.
else if((jumpAmount > 0.0f) && controller.isGrounded) {
else if((jumpAmount > 0.0f) && controller.isGrounded)
{
jumpAmount = 0.0f;
}

View file

@ -26,7 +26,8 @@ using System.Collections.Generic;
using UnityEngine;
/// Script used to move an object in a circle.
public class CircleMotion : MonoBehaviour {
public class CircleMotion : MonoBehaviour
{
/// The Transform of the GameObject we're going to move in a circle.
public Transform objectToMove;
@ -40,7 +41,8 @@ public class CircleMotion : MonoBehaviour {
private Vector3 centrePos;
/// Used to setup centrePos.
void Start () {
void Start()
{
//These lines calculate the centre of the circle we're going to move the
//object in. We assume the developer has placed the object at the
//12 o'clock position of the circle, so the centre position is its
@ -50,7 +52,8 @@ public class CircleMotion : MonoBehaviour {
}
/// Move the object along its path.
void Update () {
void Update()
{
Vector3 pos = centrePos;
//Update circleIndex to move the object further around the circle.

View file

@ -27,13 +27,15 @@ using UnityEngine;
using UnityEngine.SceneManagement;
/// Simple script used to teleport the player between scenes.
public class Teleport : MonoBehaviour {
public class Teleport : MonoBehaviour
{
/// The name of the scene to load when the player walks into the associated portal.
public string sceneToLoad;
/// This gets called when the player walks into the associated portal.
void OnTriggerEnter(Collider other) {
void OnTriggerEnter(Collider other)
{
//This loads our new scene.
SceneManager.LoadSceneAsync(sceneToLoad);
}

View file

@ -28,14 +28,16 @@ using UnityEngine;
/// Script to send a bang to a PD patch when the player enters and leaves a
/// collision volume.
public class Button2Bang : MonoBehaviour {
public class Button2Bang : MonoBehaviour
{
/// The PD patch we're going to communicate with.
public LibPdInstance pdPatch;
/// We send a bang when the player steps on the button (enters the collision
/// volume).
void OnTriggerEnter(Collider other) {
void OnTriggerEnter(Collider other)
{
//To send a bang to our PD patch, the patch needs a named receive object
//(in this case, named VolumeUp), and then we can just use the
//SendBang() function to send a bang to that object from Unity.
@ -46,7 +48,8 @@ public class Button2Bang : MonoBehaviour {
/// We send a different bang when the player steps off the button (leaves
/// the collision volume).
void OnTriggerExit(Collider other) {
void OnTriggerExit(Collider other)
{
pdPatch.SendBang("VolumeDown");
}
}

View file

@ -28,7 +28,8 @@ using UnityEngine;
/// Script to send a float to a PD patch determined by the player's proximity to
/// a specific GameObject.
public class Proximity2Float : MonoBehaviour {
public class Proximity2Float : MonoBehaviour
{
// The Pd patch we'll be communicating with.
public LibPdInstance pdPatch;
@ -37,7 +38,8 @@ public class Proximity2Float : MonoBehaviour {
/// All our calculations for this class take place in MonoBehaviour's
/// Update() function.
void Update () {
void Update()
{
//Get the distance between the sphere and the main camera.
float proximity = Vector3.Distance(sphereTransform.position, Camera.main.transform.position);