This VRPiano script was created by Reimajo and is sold at https://reimajo.booth.pm/
Please don't share or redistribute these asset files in any way.
Only use them within your own VRChat worlds after you paid for them.

If you have any issues, please contact me on Discord (Reimajo#1009) or Booth or Twitter https://twitter.com/ReimajoChan or Telegram @Reimajo

#####################################################################################################
##  There is a better online version of this documentation which might have new information:
##  https://docs.google.com/document/d/1C3hytJVUq4KOV5jaunDQ2tDoiWWcwUveiGhmaaT3JiY/
#####################################################################################################

There is a sample scene included (PianoAssemblyExampleSetup.unity / PianoScriptExampleSetup.unity) which shows the general setup. Simply copy the VRKeyboardSetup-Object into your own scene.

I've made a video tutorial for everything: https://www.youtube.com/watch?v=OqEmOEOdMp8

I also made a short video tutorial on how to import the player calibration script (in case you have that) 
and also how to set up the piano for it as an example: https://www.youtube.com/watch?v=LWLB7QDdguk

This piano can be instanced as many times as you want in your world. 

--------------------------------------------------------------------------------------- 
The following is an API of this script to adjust it to the localPlayer avatar for an optimal user experience.
One such script is my Player Calibration Script which I'll sell on my booth page -> https://booth.pm/en/items/2753511


        Avatar height in meter (of localPlayer), can be set by an external script for better usability of the keyboard. 
        One such script is my Player Calibration Script which I sell on my booth page (https://booth.pm/en/items/2753511)
        
        public float _avatarHeight = 1.3f;

		
        Relevant bone from the left hand (of localPlayer), can be set by an external script for better usability of the keyboard accross all players. 
        One such script is my Player Calibration Script which I sell on my booth page (https://booth.pm/en/items/2753511)

        public HumanBodyBones _leftIndexBone = HumanBodyBones.LeftIndexDistal;

		
        Relevant bone from the right hand (of localPlayer), can be set by an external script for better usability of the keyboard accross all players. 
        One such script is my Player Calibration Script which I sell on my booth page (https://booth.pm/en/items/2753511)

        public HumanBodyBones _rightIndexBone = HumanBodyBones.RightIndexDistal;

--------------------------------------------------------------------------------------- 

        ///Material is assigned to a block while it's being hit correctly
        private Material _blockMaterialWhenHitting;

        /// Standard gap between two note blocks in game mode for a piano of scale 1, will be scaled with the piano
        private float NOTE_GAP_DIVIDER = 0.7f;

        /// Speed at which a note will fall down in the game mode in meters per second
        private float DEFAULT_BLOCK_SPEED_MS = 0.15f;

        /// Maximum distance to a player of 1.5m in size in meters after which the script will stop running.
        /// This value is scaled up/down with avatar size
        private float DEFAULT_INTERACTION_DISTANCE = 3f; //for standard sized avatars

        /// Distance from finger bone to skin for a standard sized avatar (1.3m)
        /// This value scales up/down with avatar size
        private float FINGER_THICKNESS_DEFAULT = 0.02f;

        /// Distance from head bone to skin for a standard sized avatar (1.3m)
        /// This value scales up/down with avatar size
        private float HEAD_THICKNESS_DEFAULT = 0.25f;

        /// Distance from feet bone to skin for a standard sized avatar (1.3m)
        /// This value scales up/down with avatar size
        private float FOOT_THICKNESS_DEFAULT = 0.05f;

        /// Speed at which a key moves back after being pressed, higher is faster, 8 is default value
        private int MOVE_BACK_SPEED = 8;

        /// Maximum distance after which audio is no longer audible and no code will run
        private float MAX_AUDIO_DISTANCE = 15f;

        /// (Maximum) Time in seconds of one note sound. Needs to match the length of the corresponding animation. Do not change without changing the animation!
        private float PLAY_TIME = 4f;

        /// Maximum number of parallel audio sources = key sounds that can play at once. 
	    ///This can be used to avoid CPU performance spikes. 120 max is recommended, can be set lower to ensure your world doesn't run into performance issues.
        private int MAX_AUDIO_SOURCES = 100;

--------------------------------------------------------------------------------------- 

Please make sure you have the newest SDK3-Worlds (https://vrchat.com/home/download) and UdonSharp (https://github.com/Merlin-san/UdonSharp/releases/latest) 
imported into your project. This code requires VRCSDK3-WORLD-2020.10.26.22.43_Public or later and UdonSharp_v0.18.6 or later to compile.

In case you need to update your SDK or UdonSharp, please follow these steps:

0. Enter Playmode in each scene. If there are compile errors, remove the scripts that have an issue first.

1. Close Unity (and Visual Studio if you have it open)

2. Backup your whole Unity Project folder, e.g. by zipping it

3. Delete the following files in "Assets":
```
VRCSDK.meta
VRChat Examples.meta
Udon.meta
UdonSharp.meta
```

4. Delete those folders in "Assets":
```
VRCSDK
VRChat Examples
Udon
UdonSharp
```

5. Open the project in Unity, ignore the console errors

6. Import newest VRCSDK3 for worlds (https://vrchat.com/home/download)

7. Import newest UdonSharp package (https://github.com/Merlin-san/UdonSharp/releases/latest)

8. Enter playmode in each scene (!)
