-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from rwth-acis/feature/audio
Feature/audio
- Loading branch information
Showing
22 changed files
with
2,757 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentAudioTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using UnityEngine; | ||
|
||
namespace i5.VirtualAgents.AgentTasks | ||
{ | ||
public class AgentAudioTask : AgentBaseTask, ISerializable | ||
{ | ||
/// <summary> | ||
/// The audio to be played | ||
/// </summary> | ||
public AudioClip Audio; | ||
|
||
/// <summary> | ||
/// The audio source which plays the audio | ||
/// </summary> | ||
public AudioSource AgentAudioSource; | ||
|
||
/// <summary> | ||
/// Creates a new audio task | ||
/// </summary> | ||
/// <param name="audio">The audio to be played</param> | ||
public AgentAudioTask(AudioClip audio, int priority = 0) | ||
{ | ||
Audio = audio; | ||
} | ||
|
||
/// <summary> | ||
/// Starts the audio task | ||
/// </summary> | ||
/// <param name="agent">The agent which should execute the movement task</param> | ||
public override void StartExecution(Agent agent) | ||
{ | ||
base.StartExecution(agent); | ||
AgentAudioSource = agent.GetComponent<AudioSource>(); | ||
AgentAudioSource.clip = Audio; | ||
AgentAudioSource.Play(); | ||
} | ||
|
||
public override TaskState EvaluateTaskState() | ||
{ | ||
if (AgentAudioSource.time < Audio.length) | ||
{ | ||
return TaskState.Running; | ||
} | ||
else | ||
{ | ||
return TaskState.Success; | ||
} | ||
} | ||
/// <summary> | ||
/// Finish the task | ||
/// </summary> | ||
public override void StopExecution() | ||
{ | ||
base.StopExecution(); | ||
AgentAudioSource.Stop(); | ||
} | ||
|
||
/// <summary> | ||
/// Method to pause the audio | ||
/// </summary> | ||
public void PauseAudio() | ||
{ | ||
AgentAudioSource.Pause(); | ||
} | ||
|
||
/// <summary> | ||
/// Method to continue the audio | ||
/// </summary> | ||
public void ContinueAudio() | ||
{ | ||
AgentAudioSource.UnPause(); | ||
} | ||
public void Serialize(SerializationDataContainer serializer) | ||
{ | ||
serializer.AddSerializedData("Audio", Audio); | ||
serializer.AddSerializedData("Agent Audio Source", AgentAudioSource); | ||
} | ||
|
||
public void Deserialize(SerializationDataContainer serializer) | ||
{ | ||
Audio = serializer.GetSerializedAudioClip("Audio"); | ||
AgentAudioSource = serializer.GetSerializedAudioSource("Agent Audio Source"); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentAudioTask.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.