Commented Button2Midi.cs.
This commit is contained in:
parent
0d508db542
commit
92e64c7020
8 changed files with 422 additions and 388 deletions
|
|
@ -954,7 +954,7 @@ GameObject:
|
||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 1780628284}
|
- component: {fileID: 1780628284}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Bang Button
|
m_Name: Midi2Pd Button
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
|
|
|
||||||
|
|
@ -26,23 +26,28 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
/// Script used to let the player quit by pressing Escape (in a build).
|
/// 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
|
/// Used to ensure we don't create another instance of GameManager if we
|
||||||
/// return to the MainScene.
|
/// return to the MainScene.
|
||||||
private static bool instantiated = false;
|
private static bool instantiated = false;
|
||||||
|
|
||||||
/// We use this to ensure our GameManager doesn't get destroyed when we switch scenes.
|
/// We use this to ensure our GameManager doesn't get destroyed when we switch scenes.
|
||||||
void Awake () {
|
void Awake ()
|
||||||
if(!instantiated) {
|
{
|
||||||
|
if(!instantiated)
|
||||||
|
{
|
||||||
DontDestroyOnLoad(this.gameObject);
|
DontDestroyOnLoad(this.gameObject);
|
||||||
instantiated = true;
|
instantiated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Listen for the user pressing Escape to quit.
|
/// Listen for the user pressing Escape to quit.
|
||||||
void Update() {
|
void Update()
|
||||||
if(Input.GetButton("Quit")) {
|
{
|
||||||
|
if(Input.GetButton("Quit"))
|
||||||
|
{
|
||||||
Application.Quit();
|
Application.Quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@ using UnityEngine;
|
||||||
|
|
||||||
/// Script to send a random MIDI note to a PD patch when the player enters and
|
/// Script to send a random MIDI note to a PD patch when the player enters and
|
||||||
/// leaves a collision volume.
|
/// leaves a collision volume.
|
||||||
public class Button2Midi : MonoBehaviour {
|
public class Button2Midi : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
/// The PD patch we're going to communicate with.
|
/// The PD patch we're going to communicate with.
|
||||||
public LibPdInstance pdPatch;
|
public LibPdInstance pdPatch;
|
||||||
|
|
@ -35,17 +36,29 @@ public class Button2Midi : MonoBehaviour {
|
||||||
/// note off message when the player exits the collision volume.
|
/// note off message when the player exits the collision volume.
|
||||||
private int note;
|
private int note;
|
||||||
|
|
||||||
/// We send a bang when the player steps on the button (enters the collision
|
/// We send a MIDI note when the player steps on the button (enters the
|
||||||
/// volume).
|
/// collision volume).
|
||||||
void OnTriggerEnter(Collider other) {
|
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);
|
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);
|
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).
|
/// 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);
|
pdPatch.SendMidiNoteOn(0, note, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@ using UnityEngine;
|
||||||
|
|
||||||
/// Simple first person movement script, included so we don't need to include
|
/// Simple first person movement script, included so we don't need to include
|
||||||
/// any Standard Assets (they're far heavier than we need).
|
/// 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.
|
/// Used to implement mouselook on the vertical axis.
|
||||||
public Camera playerCamera;
|
public Camera playerCamera;
|
||||||
|
|
||||||
|
|
@ -40,12 +41,14 @@ public class PlayerMovement : MonoBehaviour {
|
||||||
private float jumpAmount;
|
private float jumpAmount;
|
||||||
|
|
||||||
/// We use this to hide the mouse cursor.
|
/// We use this to hide the mouse cursor.
|
||||||
void Start () {
|
void Start()
|
||||||
|
{
|
||||||
Cursor.visible = false;
|
Cursor.visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is where we move the Player object and Camera.
|
/// This is where we move the Player object and Camera.
|
||||||
void Update () {
|
void Update()
|
||||||
|
{
|
||||||
//Get our current WASD speed.
|
//Get our current WASD speed.
|
||||||
Vector3 strafe = new Vector3(Input.GetAxis("Horizontal") * 10.0f, 0.0f, 0.0f);
|
Vector3 strafe = new Vector3(Input.GetAxis("Horizontal") * 10.0f, 0.0f, 0.0f);
|
||||||
float forwardSpeed = Input.GetAxis("Vertical") * 10.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
|
//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
|
//the top of the jump, increase their jumpAmount and move them
|
||||||
//accordingly on the y-axis.
|
//accordingly on the y-axis.
|
||||||
if(Input.GetButton("Jump")) {
|
if(Input.GetButton("Jump"))
|
||||||
|
{
|
||||||
if(((jumpAmount <= 0.0f) && controller.isGrounded) ||
|
if(((jumpAmount <= 0.0f) && controller.isGrounded) ||
|
||||||
((jumpAmount > 0.0f) && (jumpAmount < 1.0f))) {
|
((jumpAmount > 0.0f) && (jumpAmount < 1.0f)))
|
||||||
|
{
|
||||||
jumpAmount += Time.deltaTime * 5.0f;
|
jumpAmount += Time.deltaTime * 5.0f;
|
||||||
|
|
||||||
jumpVector.y = 4.0f + ((1.0f - jumpAmount) * 20.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,
|
//Otherwise, if they're on the ground but their jumpAmount is not 0,
|
||||||
//reset it.
|
//reset it.
|
||||||
else if((jumpAmount > 0.0f) && controller.isGrounded) {
|
else if((jumpAmount > 0.0f) && controller.isGrounded)
|
||||||
|
{
|
||||||
jumpAmount = 0.0f;
|
jumpAmount = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
/// Script used to move an object in a circle.
|
/// 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.
|
/// The Transform of the GameObject we're going to move in a circle.
|
||||||
public Transform objectToMove;
|
public Transform objectToMove;
|
||||||
|
|
@ -40,7 +41,8 @@ public class CircleMotion : MonoBehaviour {
|
||||||
private Vector3 centrePos;
|
private Vector3 centrePos;
|
||||||
|
|
||||||
/// Used to setup centrePos.
|
/// Used to setup centrePos.
|
||||||
void Start () {
|
void Start()
|
||||||
|
{
|
||||||
//These lines calculate the centre of the circle we're going to move the
|
//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
|
//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
|
//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.
|
/// Move the object along its path.
|
||||||
void Update () {
|
void Update()
|
||||||
|
{
|
||||||
Vector3 pos = centrePos;
|
Vector3 pos = centrePos;
|
||||||
|
|
||||||
//Update circleIndex to move the object further around the circle.
|
//Update circleIndex to move the object further around the circle.
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,15 @@ using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
/// Simple script used to teleport the player between scenes.
|
/// 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.
|
/// The name of the scene to load when the player walks into the associated portal.
|
||||||
public string sceneToLoad;
|
public string sceneToLoad;
|
||||||
|
|
||||||
/// This gets called when the player walks into the associated portal.
|
/// This gets called when the player walks into the associated portal.
|
||||||
void OnTriggerEnter(Collider other) {
|
void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
//This loads our new scene.
|
//This loads our new scene.
|
||||||
SceneManager.LoadSceneAsync(sceneToLoad);
|
SceneManager.LoadSceneAsync(sceneToLoad);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,16 @@ using UnityEngine;
|
||||||
|
|
||||||
/// Script to send a bang to a PD patch when the player enters and leaves a
|
/// Script to send a bang to a PD patch when the player enters and leaves a
|
||||||
/// collision volume.
|
/// collision volume.
|
||||||
public class Button2Bang : MonoBehaviour {
|
public class Button2Bang : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
/// The PD patch we're going to communicate with.
|
/// The PD patch we're going to communicate with.
|
||||||
public LibPdInstance pdPatch;
|
public LibPdInstance pdPatch;
|
||||||
|
|
||||||
/// We send a bang when the player steps on the button (enters the collision
|
/// We send a bang when the player steps on the button (enters the collision
|
||||||
/// volume).
|
/// volume).
|
||||||
void OnTriggerEnter(Collider other) {
|
void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
//To send a bang to our PD patch, the patch needs a named receive object
|
//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
|
//(in this case, named VolumeUp), and then we can just use the
|
||||||
//SendBang() function to send a bang to that object from Unity.
|
//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
|
/// We send a different bang when the player steps off the button (leaves
|
||||||
/// the collision volume).
|
/// the collision volume).
|
||||||
void OnTriggerExit(Collider other) {
|
void OnTriggerExit(Collider other)
|
||||||
|
{
|
||||||
pdPatch.SendBang("VolumeDown");
|
pdPatch.SendBang("VolumeDown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,8 @@ using UnityEngine;
|
||||||
|
|
||||||
/// Script to send a float to a PD patch determined by the player's proximity to
|
/// Script to send a float to a PD patch determined by the player's proximity to
|
||||||
/// a specific GameObject.
|
/// a specific GameObject.
|
||||||
public class Proximity2Float : MonoBehaviour {
|
public class Proximity2Float : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
// The Pd patch we'll be communicating with.
|
// The Pd patch we'll be communicating with.
|
||||||
public LibPdInstance pdPatch;
|
public LibPdInstance pdPatch;
|
||||||
|
|
@ -37,7 +38,8 @@ public class Proximity2Float : MonoBehaviour {
|
||||||
|
|
||||||
/// All our calculations for this class take place in MonoBehaviour's
|
/// All our calculations for this class take place in MonoBehaviour's
|
||||||
/// Update() function.
|
/// Update() function.
|
||||||
void Update () {
|
void Update()
|
||||||
|
{
|
||||||
//Get the distance between the sphere and the main camera.
|
//Get the distance between the sphere and the main camera.
|
||||||
float proximity = Vector3.Distance(sphereTransform.position, Camera.main.transform.position);
|
float proximity = Vector3.Distance(sphereTransform.position, Camera.main.transform.position);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue