This directory contains scripts that control GameObjects with the beat of the music.
##Scripts
- _AbstractRhythmObject.cs: Contains basic framework common to all rhythm synced game objects
- ChangeColors.cs: Applies color transitions to a game object.
- MoveToPositions.cs: Moves a GameObject to a list of specified positions.
- RotateToEulers.cs: Rotates a GameObject to a list of specified Euler angles.
##Script Documentation
###_AbstractRhythmObject.cs
This script contains the basic framework for synchronizing events with the beat.
####Usage
To create your own script that does things with the beat of the music, create a script that extends _AbstractRhythmObject instead of MonoBehaviour. Then implement the rhythmUpdate() function, which gets executed once every beat.
Important: Remove the Start() and Update() functions that Unity generates for you in your subclasses, otherwise you may get unexpected results when extending this class.
####Field Summary
| Type and Modifiers | Field Name |
|---|---|
protected int |
BPM |
protected float |
samplesPerBeat |
protected float |
secondsPerBeat |
protected int BPM
Tempo of the audio clip in beats per minute.
protected float samplesPerBeat
The number of audio samples in one beat.
protected float secondsPerBeat
The number of seconds in one beat.
####Function Summary
| Return Type and Modifiers | Function Name and Parameters |
|---|---|
protected virtual void |
asyncUpdate() |
protected virtual void |
init() |
protected abstract void |
rhythmUpdate(int beat) |
protected bool |
onBeat() |
protected virtual void asyncUpdate()
This is the replacement for theUpdate()function that Unity generates.
protected virtual void init()
This is the replacement for theStart()function that Unity generates.
protected abstract void rhythmUpdate(int beat)
This function will be executed once every beat.
######Parameters:
beat: The number of beats that have elapsed since the beginning of the clip
protected bool onBeat(float deltaSeconds)
This function will return true if the current time is close enough to a beat. This allows you to detect whether player input is on beat or not.
######Parameters:
deltaSeconds: The number of seconds that the current time can be off by. Note that the window of time is twice as long, since this checks before and after the beat.
###ChangeColors.cs
This script is an example usage of _AbstractRhythmObject. This applies a series of color transitions to a GameObject if the GameObject has a material with a color setting.
####Usage To use this script, attach it to a GameObject. Then specify the color transitions that you want to apply to the GameObject.
######ColorTransition
This script uses a second class called ColorTransition. ColorTransitions is a container for holding information relevant to a color transition. The field descriptions for a ColorTransition is as follows:
public Color endColorThe ending color of the transition.
public bool smoothDetermines whether the transition will be smooth or not. If true,startColorandendColorwill be interpolated in the middle of a beat. If false the material color will be immediately set toendColor.
public Color startColor
The starting color of the transition. This will only be used ifsmoothis true.
####Field Summary
| Type and Modifiers | Field Name |
|---|---|
public ColorTransition[] |
colorTransitions |
public int[] |
indices |
public int |
offset |
public bool |
shared |
public ColorTransition[] colorTransitions
The list ofColorTransitionobjects that you want to apply to a GameObject.
public int[] indices
Indices into thecolorTransitionsarray that specfies the order in which the color transitions will be applied to the GameObject. If the size of this array is 0, the color transitions in thecolorTransitionsarray will be used in a round-robin style. If a negative index is specified, the current color will be held.
public int offset
Ifindiceshas 0 elements, this is the index ofcolorTransitionsarray that you want to start at. Otherwise, this is the index of theindicesarray that you want to start at.
public bool shared
If true, this will change the shared material's color instead of creating a copy of the material. Use this if you want every object that uses the material to be changed in the same way. Changes to the shared material will stay after the game resets.
###MoveToPositions.cs
This script is an example usage of _AbstractRhythmObject. This translates a GameObject through a list of positions, one at a time, in a round-robin style by default.
####Usage To use this script, attach it to a GameObject. Then specify the positions that you want the GameObject to travel through in the inspector.
####Field Summary
| Type and Modifiers | Field Name |
|---|---|
public int[] |
indices |
public bool |
local |
public int |
offset |
public Vector3[] |
positions |
public bool |
relative |
public bool |
rigid |
public int[] indices
Indices into thepositionsarray that specfies the order of the positions through which the GameObject will travel. If the size of this array is 0, the positions in thepositionsarray will be used in a round-robin style.
public bool local
If true, will transform relative to local coordinates instead of world coordinates. This field is ignored ifrigidis true.
public int offset
Ifindiceshas 0 elements, this is the index ofpositionsarray that you want to start at. Otherwise, this is the index of theindicesarray that you want to start at.
public Vector3[] positions
The list of positions that the GameObject will travel through.
public bool relative
If true, the positions in thepositionsarray are relative to the start position of the GameObject.
public bool rigid
If true, this will use rigid body transforms instead.
###RotateToEulers.cs
This script is an example usage of _AbstractRhythmObject. This rotates a GameObject through a list of Euler angle rotations, one at a time, in a round-robin style by default.
####Usage To use this script, attach it to a GameObject. Then specify the rotations that you want the GameObject to travel through in the inspector.
####Field Summary
| Type and Modifiers | Field Name |
|---|---|
public Vector3[] |
eulerAngles |
public int[] |
indices |
public bool |
local |
public int |
offset |
public bool |
rigid |
public bool |
spherical |
>**`public int[] indices`** >Indices into the [`eulerAngles`](#eulerAngles) array that specfies the order of the rotations through which the GameObject will travel. If the size of this array is 0, the rotations in the [`eulerAngles`](#eulerAngles) array will be used in a round-robin style.
public Vector3[] eulerAngles
The list of Euler angle rotations that the GameObject will rotate through.
public bool local
If true, will transform relative to local coordinates instead of world coordinates. This field is ignored ifrigidis true.
public int offset
If theindicesarray has 0 elements, this is the index of theeulerAnglesthat you want to start at. Otherwise, this is the index of theindicesarray that you want to start at.
public bool rigid
If true, this will use rigid body transforms instead.
public bool spherical
If true, this will use spherical interpolation instead of linear interpolation.