conversations.from: human
conversations.value: a title for a book about Unity, Witcher, Maciej with the genre: Computers & Technology, Computer Science
conversations.from: assistant
conversations.value: A title for this book could be 'Unity 5.x Animation Cookbook'
conversations.from: human
conversations.value: Give me the first five paragraphs for the book.
conversations.from: assistant
conversations.value: Unity 5.x Animation Cookbook
  If you want to animate a character talking or changing its facial expression, it is best to use Blend Shapes. This recipe covers creating facial expressions with Blend Shapes exported from a 3D package.
  We need several **Blend Shapes** that store our facial expressions. In this recipe, we will use **Smile** , **Angry** , **BlinkLeft** , **BlinkRight** , and **BrowsDown** shapes. Create them in your 3D package. If you are using Blender, **Blend Shapes** are called Shape Keys. In other softwares, they may be called Morph Targets.
  You can also use the provided example Unity project and go to the `Chapter 05 Character actions and expressions\Recipe 08 Animating facial expressions with blend shapes` directory. You will find an `Example.scene` there. Open it, play the game, and adjust the sliders on the UI to see the effect. You can find the character with all the Blend Shapes in the `Rigs` directory.
  You don't have to create Animation Clips for Blend Shapes. Instead, you can manipulate them directly from code. Use the `SetBlendShapeWeight()` function on the **Skinned Mesh Renderer** component. You will need to know the index of the **Blend Shape** in the **Blend Shapes** array (you can check it in the Inspector, in the **Skinned Mesh Renderer** component of the character). We've prepared a small script that sets the weight. It is attached to the **DirectBlendShapes** game object. You can also find it in the `Scripts` directory of this recipe.
  Creating animations for **Blend Shapes** gives more flexibility. You can also animate the Blend Shapes' weight with the **Animation** View. This way you can create dialog animations and believable animated facial expressions.
conversations.from: human
conversations.value: Give me three more paragraphs.
conversations.from: assistant
conversations.value: The key component of this recipe is the `AudioSource.GetOutputData(float[] samples, int channel)` function. It grabs a number of samples from the currently playing audio. The number of samples is specified by the length of the `float[] samples` array. This length has to be a power of 2. We get the samples every frame in the `IEnumerator SampleAudio()` coroutine. We average the values of squared samples to calculate an RMS of the audio (an average volume of a number of samples). The more samples we average, the smoother the changes of the RMS. For most sounds, 1024 is a good number. We use the calculated RMS to scale the **Cube** game object.
  You can perform more complex signal analysis of the waveform to create more interesting effects. For instance, if you want to create an equalizer showing different frequencies of the sound, you need to use the fast Fourier transform. You can find a lot of interesting information about it in the Unity forums.
  We are going to create this recipe from scratch in Unity, so we don't need any additional assets. You can also use the provided example Unity project and go to the `Chapter 07 Special effects\Recipe 10 Creating a day and night cycle with the animation window` directory. You will find an `Example.unity` scene there.
conversations.from: human
conversations.value: Delete the last sentence.
conversations.from: assistant
conversations.value: The key component of this recipe is the `AudioSource.GetOutputData(float[] samples, int channel)` function. It grabs a number of samples from the currently playing audio. The number of samples is specified by the length of the `float[] samples` array. This length has to be a power of 2. We get the samples every frame in the `IEnumerator SampleAudio()` coroutine. We average the values of squared samples to calculate an RMS of the audio (an average volume of a number of samples). The more samples we average, the smoother the changes of the RMS. For most sounds, 1024 is a good number. We use the calculated RMS to scale the **Cube** game object.
  You can perform more complex signal analysis of the waveform to create more interesting effects. For instance, if you want to create an equalizer showing different frequencies of the sound, you need to use the fast Fourier transform. You can find a lot of interesting information about it in the Unity forums.
  We are going to create this recipe from scratch in Unity, so we don't need any additional assets. You can also use the provided example Unity project and go to the `Chapter 07 Special effects\Recipe 10 Creating a day and night cycle with the animation window` directory. You will find an `Example.
conversations.from: human
conversations.value: Give me the last five paragraphs.
conversations.from: assistant
conversations.value: We are going to create this recipe from scratch and we don't need any special assets. You can download the example project and go to the `Chapter 10 Miscellaneous\Recipe 05 Adding behaviors to Mecanim states` directory. Open the `Example.unity` scene there and play the game. If you play the game, you can press the space bar to change the states in the **Animator Controller** attached to the **Controller** game object. The cycle starts in the **NoBehaviors** state-this is simply an empty state with no additional behavior. If we press the space bar, we transition to **Light1Random**. This state changes the color of the **Light1** light in the scene. If we press the space bar again, the state will change to **WaitAndSwitch**. This state waits for a given time and switches to the next state: **Light2Random**. This one changes the color of the **Light2** light. If we press the space bar again, we will transition to the **RotateObject** state, which rotates an object visible in the scene. Pressing the space bar yet again transitions the controller to the **Light1Random** state again. Animator Controller can work without any Animation Clips-empty states can have behaviors as well.
  Mecanim state behaviors are scripts that derive from the `StateMachineBehavior` class instead of the `MonoBehavior` class. They have a number of functions we can override. The most useful ones are as follows:
  We can still manage the state transitions from a normal `MonoBehavior` script (in our example, it is the `LogicController.cs` script).
  Animator Controllers are assets, so they cannot reference objects in the scene. We can work around this by either finding the game objects by name (or tag) or by creating another `MonoBehavior` script that can reference objects in the scene. Our `LogicController.cs` script has an example of this: the `public Transform activeObject` variable. We can get the `LogicController.cs` script component in the behavior (as long as the Animator component is on the same game object). This way we can get to its `activeObject` variable and do an action on this transform.
conversations.from: human
conversations.value: Add another sentence about State, Animator, Controller, following, used.
conversations.from: assistant
conversations.value: We are going to create this recipe from scratch and we don't need any special assets. You can download the example project and go to the `Chapter 10 Miscellaneous\Recipe 05 Adding behaviors to Mecanim states` directory. Open the `Example. unity` scene there and play the game. If you play the game, you can press the space bar to change the states in the **Animator Controller** attached to the **Controller** game object. The cycle starts in the **NoBehaviors** state-this is simply an empty state with no additional behavior. If we press the space bar, we transition to **Light1Random**. This state changes the color of the **Light1** light in the scene. If we press the space bar again, the state will change to **WaitAndSwitch**. This state waits for a given time and switches to the next state: **Light2Random**. This one changes the color of the **Light2** light. If we press the space bar again, we will transition to the **RotateObject** state, which rotates an object visible in the scene. Pressing the space bar yet again transitions the controller to the **Light1Random** state again. See the following screenshot for reference:
  State behaviors can be used to create logic graphs--these graphs use Animator Controller as a state machine. Animator Controller can work without any Animation Clips-empty states can have behaviors as well. 
  Mecanim state behaviors are scripts that derive from the `StateMachineBehavior` class instead of the `MonoBehavior` class. They have a number of functions we can override. The most useful ones are as follows:
  We can still manage the state transitions from a normal `MonoBehavior` script (in our example, it is the `LogicController. cs` script). 
  Animator Controllers are assets, so they cannot reference objects in the scene. We can work around this by either finding the game objects by name (or tag) or by creating another `MonoBehavior` script that can reference objects in the scene. Our `LogicController. cs` script has an example of this: the `public Transform activeObject` variable. We can get the `LogicController. cs` script component in the behavior (as long as the Animator component is on the same game object). This way we can get to its `activeObject` variable and do an action on this transform.