From 92e64c7020a80dfe738326289d5fbb3d6d3ada73 Mon Sep 17 00:00:00 2001 From: Niall Moody <21282294+NiallMoody@users.noreply.github.com> Date: Tue, 8 Dec 2020 16:58:37 +0000 Subject: [PATCH] Commented Button2Midi.cs. --- Assets/Scenes/MidiScene.unity | 2 +- Assets/Scripts/GameManager.cs | 103 +++++---- .../Scripts/MidiSceneScripts/Button2Midi.cs | 25 +- Assets/Scripts/PlayerMovement.cs | 218 +++++++++--------- .../CircleMotion.cs | 141 +++++------ Assets/Scripts/Teleport.cs | 82 +++---- .../Unity2LibPdSceneScripts/Button2Bang.cs | 107 ++++----- .../Proximity2Float.cs | 132 +++++------ 8 files changed, 422 insertions(+), 388 deletions(-) diff --git a/Assets/Scenes/MidiScene.unity b/Assets/Scenes/MidiScene.unity index 1140f1c..fdcf7c4 100644 --- a/Assets/Scenes/MidiScene.unity +++ b/Assets/Scenes/MidiScene.unity @@ -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 diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 584243c..2980bda 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -1,49 +1,54 @@ -// GameManager.cs - Script used to let the player quit by pressing Escape. -// ----------------------------------------------------------------------------- -// Copyright (c) 2018 Niall Moody -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// ----------------------------------------------------------------------------- - -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -/// Script used to let the player quit by pressing Escape (in a build). -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) { - DontDestroyOnLoad(this.gameObject); - instantiated = true; - } - } - - /// Listen for the user pressing Escape to quit. - void Update() { - if(Input.GetButton("Quit")) { - Application.Quit(); - } - } -} +// GameManager.cs - Script used to let the player quit by pressing Escape. +// ----------------------------------------------------------------------------- +// Copyright (c) 2018 Niall Moody +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// ----------------------------------------------------------------------------- + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// Script used to let the player quit by pressing Escape (in a build). +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) + { + DontDestroyOnLoad(this.gameObject); + instantiated = true; + } + } + + /// Listen for the user pressing Escape to quit. + void Update() + { + if(Input.GetButton("Quit")) + { + Application.Quit(); + } + } +} diff --git a/Assets/Scripts/MidiSceneScripts/Button2Midi.cs b/Assets/Scripts/MidiSceneScripts/Button2Midi.cs index b470bae..5f2090a 100644 --- a/Assets/Scripts/MidiSceneScripts/Button2Midi.cs +++ b/Assets/Scripts/MidiSceneScripts/Button2Midi.cs @@ -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); } } diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index ddc13bc..54e9ee4 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -1,106 +1,112 @@ -// PlayerMovement.cs - Simple first person movement script. -// ----------------------------------------------------------------------------- -// Copyright (c) 2018 Niall Moody -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// ----------------------------------------------------------------------------- - -using System.Collections; -using System.Collections.Generic; -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 { - /// Used to implement mouselook on the vertical axis. - public Camera playerCamera; - - /// Used to set the player's rotation around the y-axis. - private float playerRotation; - /// Used to implement mouselook on the vertical axis. - private float viewY; - - /// Used to let the player jump. - private float jumpAmount; - - /// We use this to hide the mouse cursor. - void Start () { - Cursor.visible = false; - } - - /// This is where we move the Player object and Camera. - 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; - - //Get our current mouse/camera rotation. - playerRotation = Input.GetAxis("Mouse X") * 6.0f; - viewY = Input.GetAxis("Mouse Y") * 4.0f; - - //Don't let the player rotate the camera more than 90 degrees on the - //y-axis. - viewY = Mathf.Clamp(viewY, -90.0f, 90.0f); - - //Rotate the camera up/down. - playerCamera.transform.Rotate(new Vector3(-viewY, 0.0f, 0.0f)); - - //Rotate player (clamped so they can't move so fast they make themselves - //sick). - Mathf.Clamp(playerRotation, -5.0f, 5.0f); - transform.Rotate(0.0f, playerRotation, 0.0f); - - //Jump player. - CharacterController controller = GetComponent(); - Vector3 jumpVector = Vector3.zero; - - //If the player is holding the jump button down, AND they're not yet - //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(((jumpAmount <= 0.0f) && controller.isGrounded) || - ((jumpAmount > 0.0f) && (jumpAmount < 1.0f))) { - jumpAmount += Time.deltaTime * 5.0f; - - jumpVector.y = 4.0f + ((1.0f - jumpAmount) * 20.0f); - } - } - //Otherwise, if they're on the ground but their jumpAmount is not 0, - //reset it. - else if((jumpAmount > 0.0f) && controller.isGrounded) { - jumpAmount = 0.0f; - } - - //Move player. - Vector3 moveDirection = Vector3.zero; - - //Set the player's direction based on the direction of the mouse and - //which WASD keys they're pressing. - moveDirection = transform.rotation * ((Vector3.forward * forwardSpeed) + strafe); - moveDirection.y = jumpVector.y; - - //Apply gravity to the player's y-axis. - moveDirection.y -= 6.0f; - - //Finally, apply the updated direction to the player's Controller (this - //will figure out any collisions with the ground, other objects, etc.). - controller.Move(moveDirection * Time.deltaTime); - } -} +// PlayerMovement.cs - Simple first person movement script. +// ----------------------------------------------------------------------------- +// Copyright (c) 2018 Niall Moody +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// ----------------------------------------------------------------------------- + +using System.Collections; +using System.Collections.Generic; +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 +{ + /// Used to implement mouselook on the vertical axis. + public Camera playerCamera; + + /// Used to set the player's rotation around the y-axis. + private float playerRotation; + /// Used to implement mouselook on the vertical axis. + private float viewY; + + /// Used to let the player jump. + private float jumpAmount; + + /// We use this to hide the mouse cursor. + void Start() + { + Cursor.visible = false; + } + + /// This is where we move the Player object and Camera. + 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; + + //Get our current mouse/camera rotation. + playerRotation = Input.GetAxis("Mouse X") * 6.0f; + viewY = Input.GetAxis("Mouse Y") * 4.0f; + + //Don't let the player rotate the camera more than 90 degrees on the + //y-axis. + viewY = Mathf.Clamp(viewY, -90.0f, 90.0f); + + //Rotate the camera up/down. + playerCamera.transform.Rotate(new Vector3(-viewY, 0.0f, 0.0f)); + + //Rotate player (clamped so they can't move so fast they make themselves + //sick). + Mathf.Clamp(playerRotation, -5.0f, 5.0f); + transform.Rotate(0.0f, playerRotation, 0.0f); + + //Jump player. + CharacterController controller = GetComponent(); + Vector3 jumpVector = Vector3.zero; + + //If the player is holding the jump button down, AND they're not yet + //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(((jumpAmount <= 0.0f) && controller.isGrounded) || + ((jumpAmount > 0.0f) && (jumpAmount < 1.0f))) + { + jumpAmount += Time.deltaTime * 5.0f; + + jumpVector.y = 4.0f + ((1.0f - jumpAmount) * 20.0f); + } + } + //Otherwise, if they're on the ground but their jumpAmount is not 0, + //reset it. + else if((jumpAmount > 0.0f) && controller.isGrounded) + { + jumpAmount = 0.0f; + } + + //Move player. + Vector3 moveDirection = Vector3.zero; + + //Set the player's direction based on the direction of the mouse and + //which WASD keys they're pressing. + moveDirection = transform.rotation * ((Vector3.forward * forwardSpeed) + strafe); + moveDirection.y = jumpVector.y; + + //Apply gravity to the player's y-axis. + moveDirection.y -= 6.0f; + + //Finally, apply the updated direction to the player's Controller (this + //will figure out any collisions with the ground, other objects, etc.). + controller.Move(moveDirection * Time.deltaTime); + } +} diff --git a/Assets/Scripts/SpatialisationSceneScripts/CircleMotion.cs b/Assets/Scripts/SpatialisationSceneScripts/CircleMotion.cs index b0357d3..76975b6 100644 --- a/Assets/Scripts/SpatialisationSceneScripts/CircleMotion.cs +++ b/Assets/Scripts/SpatialisationSceneScripts/CircleMotion.cs @@ -1,69 +1,72 @@ -// CircleMotion.cs - Script used to move an object in a circle. -// ----------------------------------------------------------------------------- -// Copyright (c) 2018 Niall Moody -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// ----------------------------------------------------------------------------- - -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -/// Script used to move an object in a circle. -public class CircleMotion : MonoBehaviour { - - /// The Transform of the GameObject we're going to move in a circle. - public Transform objectToMove; - /// The radius of the circle we're going to move the object in. - [Range(0.1f, 50.0f)] - public float radius = 10.0f; - - /// Where we are in the circle right now. - private float circleIndex; - /// The circle's centre position. - private Vector3 centrePos; - - /// Used to setup centrePos. - 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 - //position - the circle's radius on the z-axis. - centrePos = objectToMove.transform.position; - centrePos.z -= radius; - } - - /// Move the object along its path. - void Update () { - Vector3 pos = centrePos; - - //Update circleIndex to move the object further around the circle. - circleIndex += 0.01f; - if(circleIndex > (2.0f * Mathf.PI)) - circleIndex -= 2.0f * Mathf.PI; - - //We calculate the object's position by feeding circleIndex into the - //Sin function for it's x-axis, and Cos for it's z-axis. - pos.x += Mathf.Sin(circleIndex) * radius; - pos.z += Mathf.Cos(circleIndex) * radius; - - //Finally, apply our updated position to the object's Transform. - objectToMove.transform.position = pos; - } -} +// CircleMotion.cs - Script used to move an object in a circle. +// ----------------------------------------------------------------------------- +// Copyright (c) 2018 Niall Moody +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// ----------------------------------------------------------------------------- + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// Script used to move an object in a circle. +public class CircleMotion : MonoBehaviour +{ + + /// The Transform of the GameObject we're going to move in a circle. + public Transform objectToMove; + /// The radius of the circle we're going to move the object in. + [Range(0.1f, 50.0f)] + public float radius = 10.0f; + + /// Where we are in the circle right now. + private float circleIndex; + /// The circle's centre position. + private Vector3 centrePos; + + /// Used to setup centrePos. + 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 + //position - the circle's radius on the z-axis. + centrePos = objectToMove.transform.position; + centrePos.z -= radius; + } + + /// Move the object along its path. + void Update() + { + Vector3 pos = centrePos; + + //Update circleIndex to move the object further around the circle. + circleIndex += 0.01f; + if(circleIndex > (2.0f * Mathf.PI)) + circleIndex -= 2.0f * Mathf.PI; + + //We calculate the object's position by feeding circleIndex into the + //Sin function for it's x-axis, and Cos for it's z-axis. + pos.x += Mathf.Sin(circleIndex) * radius; + pos.z += Mathf.Cos(circleIndex) * radius; + + //Finally, apply our updated position to the object's Transform. + objectToMove.transform.position = pos; + } +} diff --git a/Assets/Scripts/Teleport.cs b/Assets/Scripts/Teleport.cs index 95e3e3d..443299e 100644 --- a/Assets/Scripts/Teleport.cs +++ b/Assets/Scripts/Teleport.cs @@ -1,40 +1,42 @@ -// Teleport.cs - Simple script used to teleport the player between scenes. -// ----------------------------------------------------------------------------- -// Copyright (c) 2018 Niall Moody -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// ----------------------------------------------------------------------------- - -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.SceneManagement; - -/// Simple script used to teleport the player between scenes. -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) { - //This loads our new scene. - SceneManager.LoadSceneAsync(sceneToLoad); - } -} +// Teleport.cs - Simple script used to teleport the player between scenes. +// ----------------------------------------------------------------------------- +// Copyright (c) 2018 Niall Moody +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// ----------------------------------------------------------------------------- + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + +/// Simple script used to teleport the player between scenes. +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) + { + //This loads our new scene. + SceneManager.LoadSceneAsync(sceneToLoad); + } +} diff --git a/Assets/Scripts/Unity2LibPdSceneScripts/Button2Bang.cs b/Assets/Scripts/Unity2LibPdSceneScripts/Button2Bang.cs index b6ac98b..56e84df 100644 --- a/Assets/Scripts/Unity2LibPdSceneScripts/Button2Bang.cs +++ b/Assets/Scripts/Unity2LibPdSceneScripts/Button2Bang.cs @@ -1,52 +1,55 @@ -// Button2Bang.cs - Script to send a bang to a PD patch when the player enters -// and leaves a collision volume. -// ----------------------------------------------------------------------------- -// Copyright (c) 2018 Niall Moody -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// ----------------------------------------------------------------------------- - -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -/// Script to send a bang to a PD patch when the player enters and leaves a -/// collision volume. -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) { - //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. - // - //See the BangExample.pd patch for details. - pdPatch.SendBang("VolumeUp"); - } - - /// We send a different bang when the player steps off the button (leaves - /// the collision volume). - void OnTriggerExit(Collider other) { - pdPatch.SendBang("VolumeDown"); - } -} +// Button2Bang.cs - Script to send a bang to a PD patch when the player enters +// and leaves a collision volume. +// ----------------------------------------------------------------------------- +// Copyright (c) 2018 Niall Moody +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// ----------------------------------------------------------------------------- + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// Script to send a bang to a PD patch when the player enters and leaves a +/// collision volume. +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) + { + //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. + // + //See the BangExample.pd patch for details. + pdPatch.SendBang("VolumeUp"); + } + + /// We send a different bang when the player steps off the button (leaves + /// the collision volume). + void OnTriggerExit(Collider other) + { + pdPatch.SendBang("VolumeDown"); + } +} diff --git a/Assets/Scripts/Unity2LibPdSceneScripts/Proximity2Float.cs b/Assets/Scripts/Unity2LibPdSceneScripts/Proximity2Float.cs index 85209f7..52a1260 100644 --- a/Assets/Scripts/Unity2LibPdSceneScripts/Proximity2Float.cs +++ b/Assets/Scripts/Unity2LibPdSceneScripts/Proximity2Float.cs @@ -1,65 +1,67 @@ -// Proximity2Float.cs - Script to send a float to a PD patch determined by the -// player's proximity to a specific GameObject. -// ----------------------------------------------------------------------------- -// Copyright (c) 2018 Niall Moody -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// ----------------------------------------------------------------------------- - -using System.Collections; -using System.Collections.Generic; -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 { - - // The Pd patch we'll be communicating with. - public LibPdInstance pdPatch; - // We'll use the transform of the red sphere to judge the player's proximity. - public Transform sphereTransform; - - /// All our calculations for this class take place in MonoBehaviour's - /// Update() function. - void Update () { - //Get the distance between the sphere and the main camera. - float proximity = Vector3.Distance(sphereTransform.position, Camera.main.transform.position); - - //We want proximity to be in the range 0 -> 1. - //Since our blue circle has a diameter of 15, its radius will be 7.5, - //hence the following scaling. - proximity /= 7.5f; - - //We also want the pitch to increase as we get closer to the sphere, - //so we invert proximity. - proximity = 1.0f - proximity; - - if(proximity < 0.0f) - proximity = 0.0f; - - //Send our frequency value to the PD patch. - //Like in Button2Bang.cs/ButtonExample.pd, all we need to be able to - //send floats to our PD patch is a named receive object in the patch (in - //this case, named proximity). We can then use the SendFloat() function - //to send our float value to that named receive object. - // - //See the FloatExample.pd patch for details. - pdPatch.SendFloat("proximity", proximity); - } -} +// Proximity2Float.cs - Script to send a float to a PD patch determined by the +// player's proximity to a specific GameObject. +// ----------------------------------------------------------------------------- +// Copyright (c) 2018 Niall Moody +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// ----------------------------------------------------------------------------- + +using System.Collections; +using System.Collections.Generic; +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 +{ + + // The Pd patch we'll be communicating with. + public LibPdInstance pdPatch; + // We'll use the transform of the red sphere to judge the player's proximity. + public Transform sphereTransform; + + /// All our calculations for this class take place in MonoBehaviour's + /// Update() function. + void Update() + { + //Get the distance between the sphere and the main camera. + float proximity = Vector3.Distance(sphereTransform.position, Camera.main.transform.position); + + //We want proximity to be in the range 0 -> 1. + //Since our blue circle has a diameter of 15, its radius will be 7.5, + //hence the following scaling. + proximity /= 7.5f; + + //We also want the pitch to increase as we get closer to the sphere, + //so we invert proximity. + proximity = 1.0f - proximity; + + if(proximity < 0.0f) + proximity = 0.0f; + + //Send our frequency value to the PD patch. + //Like in Button2Bang.cs/ButtonExample.pd, all we need to be able to + //send floats to our PD patch is a named receive object in the patch (in + //this case, named proximity). We can then use the SendFloat() function + //to send our float value to that named receive object. + // + //See the FloatExample.pd patch for details. + pdPatch.SendFloat("proximity", proximity); + } +}