Demonstration of Demo implementation process in Unity Koreographer II music production plug-in

Demonstration of Demo implementation process in Unity Koreographer II music production plug-in

catalogue

Demonstration of Demo implementation process in Unity Koreographer II music production plug-in

1, Koreographer brief introduction

2, Development environment

3, Precautions

4, Demo demo Preview

5, Step by step demonstration to explain the implementation steps

1. Basic scenario and data construction

2. The ball beats according to the beat

3. The particle effect controls the particle emission according to the time span set by the beat

4. Effect of gradual change of cube

5. The text on the beat obtains and displays the effect

6. The effect of lights flashing with the beat

7. Dynamic change of color with beat

8. The overall effect of the Demo is the superposition of all scene effects

1, Koreographer brief introduction

Koreographer   Official website: Sonic Bloom

    Koreographer Professional Edition ™ It simplifies the process of synchronizing game play and music in video games. Its simple editing interface allows you to map the rhythm, beat, notes, volume and other dynamic elements of music to events in the game.

    Koreographer can be used to create rhythm games, make any game more cinematic, enhance the game environment with music, and create new control and music driven game playing methods.

    Koreographer function:

        1. Create a rhythm game, enable lip sync or add subtitles to the game with minimal effort
        2. Accurately synchronize events in the game to different points in the game music
        3. Quickly create new music games and effects
 

It is recommended to download Koreographer Professional Edition from the Unity Asset Store. The download path here is for learning only. It is recommended to purchase the genuine version for commercial use.

Koreographer Professional Edition 1.6.1 learning download address: under review

This section mainly introduces Koreographer   The Demo implementation process in is to get familiar with Koreographer   And related interfaces for later Koreographer   In depth study and use of.

If you have time, you can also refer to the official website to learn more, Koreographer   Official website: Sonic Bloom.

2, Development environment

1, Koreographer Professional Edition 1.6.1

2,Unity 2019.3.13f1

3, Precautions

1. Koreographer after import   There are four folders: Editor Default Resources, Gizmos, koreographer and Plugins. Do not create a new folder, and then unify them in this file. This may lead to some unknown errors or no errors, but some functions will not work

4, Demo demo Preview

5, Step by step demonstration to explain the implementation steps

1. Basic scenario and data construction

1) In the scenario, build the scenario as follows

2) Create a new Koreography in the project to add audio, related data and beat event settings

 

  3) Add a GameObject named Music Player in the scene. Add components. Koreographer, AudioSource, Simple Music Player and Simple Music Player correspond to the newly created Koreography

2. The ball beats according to the beat

1) In the scene, you two spheres and add a rigid body to the sphere

 

2) Create a new koreograph track in the project, set the Event ID and assign it to   Koreohgraphy

 

3) Select   Koreography, click Open In Koreography Editor, select the Event ID corresponding to the koreography track, and set the beat. Here, set the Payload as float, and the value can be set as needed (this value is not used in Demo, so you can use evt.GetFloatValue() to get the value of your own setting)

 

4) In this way, the Event List of the corresponding koreograph track will also be set accordingly

 

5) Create a new script, which is used to obtain the corresponding event, make the ball jump, add the script to the ball, and set the Event ID accordingly

//----------------------------------------------
//            	   Koreographer                 
//    Copyright © 2014-2020 Sonic Bloom, LLC    
//----------------------------------------------

using UnityEngine;

namespace SonicBloom.Koreo.Demos
{
	[RequireComponent(typeof(Rigidbody))]
	[AddComponentMenu("Koreographer/Demos/Musical Impulse")]
	public class MusicalImpulse : MonoBehaviour
	{
		[EventID]
		public string eventID;
		public float jumpSpeed = 3f;

		Rigidbody rigidbodyCom;

		void Start()
		{
			// Register for Koreography Events.  This sets up the callback.
			Koreographer.Instance.RegisterForEvents(eventID, AddImpulse);

			rigidbodyCom = GetComponent<Rigidbody>();
		}

		void OnDestroy()
		{
			// Sometimes the Koreographer Instance gets cleaned up before hand.
			//  No need to worry in that case.
			if (Koreographer.Instance != null)
			{
				Koreographer.Instance.UnregisterForAllEvents(this);
			}
		}
		
		void AddImpulse(KoreographyEvent evt)
		{
			// Add impulse by overriding the Vertical component of the Velocity.
			Vector3 vel = rigidbodyCom.velocity;
			//vel.y = jumpSpeed + evt.GetFloatValue();
			vel.y = jumpSpeed ;

			rigidbodyCom.velocity = vel;
		}
	}
}

 

6) Run the scenario, and the effect is as above

3. The particle effect controls the particle emission according to the time span set by the beat

1) In the scene, add two particle effects

2) Similarly, create a new Koreohgraphy Track and set it to   Koreohgraphy

 

3) Edit the beat event of Koreohgraphy Track corresponding to Koreohgraphy. Here, set the time span according to the beat

4) Create a new script, set the number of particles emitted according to the time span, hang the script on the particles and assign values accordingly

 

//----------------------------------------------
//            	   Koreographer                 
//    Copyright © 2014-2020 Sonic Bloom, LLC    
//----------------------------------------------

using UnityEngine;

namespace SonicBloom.Koreo.Demos
{
	[RequireComponent(typeof(ParticleSystem))]
	[AddComponentMenu("Koreographer/Demos/Emit Particles On Span")]
	public class EmitParticlesOnSpan : MonoBehaviour
	{
		[EventID]
		public string eventID;
		public float particlesPerBeat = 100;

		ParticleSystem particleCom;
		int lastEmitFrame = -1;

		void Start()
		{
			particleCom = GetComponent<ParticleSystem>();

			// Register for Koreography Events.  This sets up the callback.
			Koreographer.Instance.RegisterForEvents(eventID, OnParticleControlEvent);
		}

		void OnDestroy()
		{
			// Sometimes the Koreographer Instance gets cleaned up before hand.
			//  No need to worry in that case.
			if (Koreographer.Instance != null)
			{
				Koreographer.Instance.UnregisterForAllEvents(this);
			}
		}

		void OnParticleControlEvent(KoreographyEvent evt)
		{
			// If two Koreography span events overlap, this can be called twice in the same frame.
			//  This check ensures that we only ask the particle system to emit once for any frame.
			if (Time.frameCount != lastEmitFrame)
			{
				// Spans get called over a specified amount of music time.  Use Koreographer's beat delta
				//  to calculate the number of particles to emit this frame based on the "particlesPerBeat"
				//  rate configured in the Inspector.
				int particleCount = (int)(particlesPerBeat * Koreographer.GetBeatTimeDelta());
				Debug.Log(GetType()+ "/OnParticleControlEvent()/ Koreographer.GetBeatTimeDelta:" + Koreographer.GetBeatTimeDelta());
				Debug.Log(GetType()+ "/OnParticleControlEvent()/ particleCount:" + particleCount);
				// Emit the calculated number of particles!
				particleCom.Emit(particleCount);

				lastEmitFrame = Time.frameCount;
			}
		}
	}
}

5) Run the scenario, and the effect is as above

4. Effect of gradual change of cube

1) In the scene, add two edge cubes

2) Similarly, create a new Koreohgraphy Track and set it to   Koreohgraphy

 

3) Edit the beat event of koreograph track corresponding to koreograph. Here, set the Curve value on the time span according to the beat

 

4) Create a new script and dynamically change the size of the Cube according to the Value of the Curve in the time span. The script is hung on the Cube and assigned a corresponding Value

//----------------------------------------------
//            	   Koreographer                 
//    Copyright © 2014-2020 Sonic Bloom, LLC    
//----------------------------------------------

using UnityEngine;

namespace SonicBloom.Koreo.Demos
{
	[AddComponentMenu("Koreographer/Demos/Cube Scaler")]
	public class CubeScaler : MonoBehaviour
	{
		[EventID]
		public string eventID;
		public float minScale = 0.5f;
		public float maxScale = 1.5f;
		
		void Start()
		{
			// Register for Koreography Events.  This sets up the callback.
			Koreographer.Instance.RegisterForEventsWithTime(eventID, AdjustScale);
		}
		
		void OnDestroy()
		{
			// Sometimes the Koreographer Instance gets cleaned up before hand.
			//  No need to worry in that case.
			if (Koreographer.Instance != null)
			{
				Koreographer.Instance.UnregisterForAllEvents(this);
			}
		}
		
		void AdjustScale(KoreographyEvent evt, int sampleTime, int sampleDelta, DeltaSlice deltaSlice)
		{
			if (evt.HasCurvePayload())
			{
				// Get the value of the curve at the current audio position.  This will be a
				//  value between [0, 1] and will be used, below, to interpolate between
				//  minScale and maxScale.
				float curveValue = evt.GetValueOfCurveAtTime(sampleTime);

				transform.localScale = Vector3.one * Mathf.Lerp(minScale, maxScale, curveValue);

				Debug.Log(GetType()+ "/AdjustScale()/ curveValue : "+ curveValue);
				Debug.Log(GetType()+ "/AdjustScale()/ transform.localScale : " + transform.localScale);
			}
		}
	}
}

 

5) Run the scenario, and the effect is as above

5. The text on the beat obtains and displays the effect

1) Create a GameObject in the scene (the GUI used here, you can also use UGUI)

 

  2) Similarly, create a new Koreohgraphy Track and set it to   Koreohgraphy

3) Edit the beat event of koreograph track corresponding to koreograph. Here, set the Text value on the time span according to the beat

4) Create a new script, and dynamically set the GUI Text according to the Value of Text in the time span. The script is hung in the scene and assigned a corresponding Value

//----------------------------------------------
//            	   Koreographer                 
//    Copyright © 2014-2020 Sonic Bloom, LLC    
//----------------------------------------------

using UnityEngine;

namespace SonicBloom.Koreo.Demos
{
	[AddComponentMenu("Koreographer/Demos/UI Message Setter")]
	public class UIMessageSetter : MonoBehaviour
	{
		[EventID]
		public string eventID;
		public GUIStyle style;

		KoreographyEvent curTextEvent;
		
		void Start()
		{
			// Register for Koreography Events.  This sets up the callback.
			Koreographer.Instance.RegisterForEventsWithTime(eventID, UpdateText);
		}
		
		void OnDestroy()
		{
			// Sometimes the Koreographer Instance gets cleaned up before hand.
			//  No need to worry in that case.
			if (Koreographer.Instance != null)
			{
				Koreographer.Instance.UnregisterForAllEvents(this);
			}
		}

		void OnGUI()
		{
			if (curTextEvent != null)
			{
				// Use the entire screen size as the draw surface. Draw location is determined by
				//	the GUIStyle.
				GUI.Box(new Rect(0,0, Screen.width, Screen.height), curTextEvent.GetTextValue(), style);
			}
		}
		
		void UpdateText(KoreographyEvent evt, int sampleTime, int sampleDelta, DeltaSlice deltaSlice)
		{
			// Verify that we have Text in the Payload.
			if (evt.HasTextPayload())
			{
				// Set the text if we have a text event!
				// We can get multiple events called at the same time (if they overlap in the track).
				//  In this case, we prefer the event with the most recent start sample.
				if (curTextEvent == null ||
				    (evt != curTextEvent && evt.StartSample > curTextEvent.StartSample))
				{
					// Store for later use and comparison.
					curTextEvent = evt;
				}

				// Clear out the text if our event ended this musical frame.
				if (curTextEvent.EndSample < sampleTime)
				{
					// Remove so that the above timing logic works when the audio loops/jumps.
					curTextEvent = null;
				}
			}
		}
	}
}

5) Run the scenario, and the effect is as above

6. The effect of lights flashing with the beat

 

1) Add a few spotlights in the scene to the layout

 

2) Create a new script, get the beat according to Koreographer.GetBeatTime(), and then the corresponding switch

//----------------------------------------------
//            	   Koreographer                 
//    Copyright © 2014-2020 Sonic Bloom, LLC    
//----------------------------------------------

using UnityEngine;

namespace SonicBloom.Koreo.Demos
{
	[AddComponentMenu("Koreographer/Demos/Tempo Switch")]
	public class TempoSwitch : MonoBehaviour
	{
		// These should be set up in the inspector.
		public Behaviour[] quarterNoteGroup;
		public Behaviour[] eighthNoteGroup;

		int lastQuarterNote = 0;
		int lastEighthNote = -1;
		
		void Update()
		{
			// The Demo song has a quarter note as it's beat value.  This will get us the current
			//  quarter note!
			int curQuarterNote = Mathf.FloorToInt(Koreographer.GetBeatTime());

			if (curQuarterNote != lastQuarterNote)
			{
				// Turn the group on when the beat is an even number.
				SwitchGroup(quarterNoteGroup, lastQuarterNote % 2 != 0);

				lastQuarterNote = curQuarterNote;
			}

			// The 'null' value asks Koreographer to look at the beat time of what it considers
			//  the current "Main" song.  These demos use a basic player with a single song and
			//  define that as the Main song.  Therefore there is no need to specify it.  The
			//  '2' parameter, tells Koreographer to divide each beat into 2 equal parts.  As the
			//  base beat value is 4, this will result in eighth notes.
			int curEighthNote = Mathf.FloorToInt(Koreographer.GetBeatTime(null, 2));

			if (curEighthNote != lastEighthNote)
			{
				SwitchGroup(eighthNoteGroup, lastEighthNote % 2 != 0);

				lastEighthNote = curEighthNote;
			}
		}

		void SwitchGroup(Behaviour[] behaviours, bool bGroupOn)
		{
			for (int i = 0; i < behaviours.Length; ++i)
			{
				behaviours[i].enabled = bGroupOn;
			}
		}
	}
}

3) Run the scenario, and the effect is as above

7. Dynamic change of color with beat

 

1) The scene uses the combination of the front ball and cube to create a new GameObject object to monitor the color change and mount the object

  2) Similarly, create two koreohgraphy tracks (one color sudden change and one color gradient) and set them to   Koreohgraphy

 

3) Edit the beat event of Koreohgraphy Track corresponding to Koreohgraphy. Here, set Color and Gradient according to the beat

 

5) Create a new script, set the color according to the beat, hang the script in the scene and assign values accordingly

//----------------------------------------------
//            	   Koreographer                 
//    Copyright © 2014-2020 Sonic Bloom, LLC    
//----------------------------------------------

using UnityEngine;

namespace SonicBloom.Koreo.Demos
{
	[AddComponentMenu("Koreographer/Demos/Color Adjuster")]
	public class ColorAdjuster : MonoBehaviour
	{
		[EventID]
		public string eventID;
		public Renderer[] objectsToColor;
		
		void Start()
		{
			// Register for Koreography Events.  This sets up the callback.
			Koreographer.Instance.RegisterForEventsWithTime(eventID, AdjustColor);
		}
		
		void OnDestroy()
		{
			// Sometimes the Koreographer Instance gets cleaned up before hand.
			//  No need to worry in that case.
			if (Koreographer.Instance != null)
			{
				Koreographer.Instance.UnregisterForAllEvents(this);
			}
		}
		
		void AdjustColor(KoreographyEvent evt, int sampleTime, int sampleDelta, DeltaSlice deltaSlice)
		{
			// We have prepared two kinds of events that work with this system:
			//  1) OneOffs that store a Color.
			//  2) Spans that store a Gradient.
			// Ensure that we have the correct types before proceeding!
			if (evt.IsOneOff() && evt.HasColorPayload())
			{
				// This is a simple Color Payload.
				Color targetColor = evt.GetColorValue();
				ApplyColorToObjects(ref targetColor);
			}
			else if (!evt.IsOneOff() && evt.HasGradientPayload())
			{
				// Access the color specified at the current music-time.  This is what
				//  drives musical color animations from gradients!
				Color targetColor = evt.GetColorOfGradientAtTime(sampleTime);
				ApplyColorToObjects(ref targetColor);
			}
		}

		void ApplyColorToObjects(ref Color color)
		{
			for (int i = 0; i < objectsToColor.Length; ++i)
			{
				objectsToColor[i].material.color = color;
			}
		}
	}
}

5) Run the scenario, and the effect is as above

8. The overall effect of the Demo is the superposition of all scene effects

Tags: Unity Visualization

Posted on Fri, 08 Oct 2021 21:43:01 -0400 by alecjw