该插件主要用来做音游,下面主要介绍一些API:
using SonicBloom.Koreo;
1.头文件必不可少
Koreographer.Instance.RegisterForEventsWithTime(eventId, ChangeCubeScale);
void ChangeCubeScale(KoreographyEvent koreoEvent, int sampleTime, int sampleDelta, DeltaSlice deltaSlice)
float curveValue = koreoEvent.GetValueOfCurveAtTime(sampleTime);
Koreographer.Instance.RegisterForEvents(eventId, MyCallBack);
void MyCallBack(KoreographyEvent koreographyEvent)
2.首先Koregrapher类有一个单例,用来方便地调用其中的函数。
3.先看下面的两句,第一个是就是用来处理事件的,即我们在轨道上添加事件后,当音乐播放到添加事件位置时会触发相应的函数,即第二个参数;第一个参数即事件的Id,这个Id要和在Track上设置的Id相同,以便Koreographer插件能与游戏物体建立连接
4.上面两句同样也是处理事件的,下面举例说明其不同:
我们在一个事件还可以加Payload,如我们在一个事件上加一个Curve(曲线),曲线的横坐标便表示某个时间点,纵坐标表示某个0-1之间的值,当我们想获取某个时间点上曲线的值时便可以通过GetValueOfCurveAtTime(sampleTime)来获得,至于为什么要获得这个值,是因为充分利用这个值可以将游戏物体的变化与音乐节奏的变化关联起来
particleSystem.Emit();
Koreographer.GetBeatTimeDelta();
5.第一个方法是用来控制粒子生成数目的,有一个参数,即表示生成粒子的数目;第二个方法表示在某一段时间中完成了一个拍子的多少(那个某一段时间是一个不固定的值,有点像deltaTime),也就是节拍时间(用节拍表示的时间)在某一个时间中的变化量
void ColorChange(KoreographyEvent koreographyEvent, int sampleTime, int sampleDelta, DeltaSlice deltaSlice)
{
if (koreographyEvent.HasColorPayload())
{
Color targetColor = koreographyEvent.GetColorValue();
ApplyColor(targetColor);
}
else if (koreographyEvent.HasGradientPayload())
{
Color targetColor = koreographyEvent.GetColorOfGradientAtTime(sampleTime);
ApplyColor(targetColor);
}
}
6.HasColorPayload()判断当前事件有没有颜色负载,同理稍作修改也可以检查有无其它负载。GetColorValue()获得当前事件上颜色负载的颜色。GetColorOfGradientAtTime(sampleTime)得到事件上渐变颜色负载在sampleTime时间点上的颜色
Koreographer.GetBeatTime()
Koreographer.GetBeatTime(null, 2)
7.第一个方法:获得当前节拍时间(即用节拍表示的时间,因为博主所用歌曲为以4分音符为一拍,所以这里也可以理解为用四分音符表示的时间)。第二个方法:与第一个方法相比,不同之处在于参数,第一个参数一般为null(在使用多首歌曲时不为空),第二个参数为2表示四分音符的一半,也就是用八分音符表示的时间(是四分音符表示时间的两倍)。注意这里用节拍或者音符表示的时间是可以直接在编辑器界面看到的:
void ChangeText(KoreographyEvent koreographyEvent, int sampleTime, int sampleDelta, DeltaSlice deltaSlice)
koreographyEvent.StartSample
koreographyEvent.EndSample
8.分别是当前事件开始的时间和结束的时间