Add custom audio clip array to actor entry in database (like portraits)
Add custom audio clip array to actor entry in database (like portraits)
Hello,
i need to assign an array of sound effects to each actor in the database, in the same fashion as portraits.
my use case is the following;
i have a retro- style system that plays a random audio clip every time the typewriter script prints a character in the subtitle ui.
The audio clip is choosen from an array. I would like to change the array according to the actor that is speaking, so they have different "voices".
What is the best approach to achieve this? i read the documentation on custom fields but they are just for text from what i understand?
Thank you for your help!
i need to assign an array of sound effects to each actor in the database, in the same fashion as portraits.
my use case is the following;
i have a retro- style system that plays a random audio clip every time the typewriter script prints a character in the subtitle ui.
The audio clip is choosen from an array. I would like to change the array according to the actor that is speaking, so they have different "voices".
What is the best approach to achieve this? i read the documentation on custom fields but they are just for text from what i understand?
Thank you for your help!
Re: Add custom audio clip array to actor entry in database (like portraits)
Hi,
Make a subclass of DialogueActor that has your audio clip array:
Add this to your characters' GameObjects. If a character doesn't have a GameObject, you can create an empty GameObject for it.
Then add a script with an OnConversationLine method to the Dialogue Manager GameObject:
Note: I just typed that into the reply, so there might be typos. For clarity, I also omitted using statements at the top and error checking for null when getting panels, actors, etc.
Make a subclass of DialogueActor that has your audio clip array:
Code: Select all
public class AudibleDialogueActor : DialogueActor
{
public AudioClip[] typewriterAudioClip;
public AudioClip[] alternateTypewriterAudioClips;
}
Then add a script with an OnConversationLine method to the Dialogue Manager GameObject:
Code: Select all
public class SetTypewriterAudioForActor : MonoBehaviour
{
void OnConversationLine(Subtitle subtitle)
{
DialogueActor dialogueActor;
var panel = DialogueManager.standardDialogueUI.conversationUIElements.standardSubtitleControls.GetPanel(subtitle, out dialogueActor);
var audibleActor = dialogueActor as AudibleAudioActor;
var typewriter = panel.GetTypewriter();
typewriter.audioClip = audibleActor.typewriterAudioClip;
typewriter.alternateAudioClips = audibleActor.alternateTypewriterAudioClips;
}
}
Re: Add custom audio clip array to actor entry in database (like portraits)
Hi Tony,
Thank you so much for your answer!
i managed to make it work, but for some reason the serialized array in the sublcass is not visible in the inspector, and i can't seem to figure out why. Any ideas?
Thank you so much for your answer!
i managed to make it work, but for some reason the serialized array in the sublcass is not visible in the inspector, and i can't seem to figure out why. Any ideas?
Re: Add custom audio clip array to actor entry in database (like portraits)
DialogueActor has a custom inspector script.
Create a folder named Editor, and put this script in it:
AudibleDialogueActorEditor.cs
Create a folder named Editor, and put this script in it:
AudibleDialogueActorEditor.cs
Code: Select all
using UnityEditor;
namespace PixelCrushers.DialogueSystem
{
[CustomEditor(typeof(AudibleDialogueActor), true)]
[CanEditMultipleObjects]
public class AudibleDialogueActorEditor : DialogueActorEditor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
serializedObject.Update();
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AudibleDialogueActor.typewriterAudioClip)), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AudibleDialogueActor.alternateTypewriterAudioClips)), true);
serializedObject.ApplyModifiedProperties();
}
}
}
Re: Add custom audio clip array to actor entry in database (like portraits)
Oh i missed that.
Now it works,
thank you for your great (and very quick) support!
Now it works,
thank you for your great (and very quick) support!
Re: Add custom audio clip array to actor entry in database (like portraits)
Reviving this thread since I wanted to implement this solution, as it seems to be the most comfy for situations like this.
I encountered this issue:
https://a.uguu.se/WHXyMAdU.mp4
Can't assign the files to the array in any way. It won't let me. The individual clip behaves like this as well; no matter how much times I try to drag and drop the file into the slot it just won't accept it. The little circle doesn't work either.
Anything I can do to solve this?
I encountered this issue:
https://a.uguu.se/WHXyMAdU.mp4
Can't assign the files to the array in any way. It won't let me. The individual clip behaves like this as well; no matter how much times I try to drag and drop the file into the slot it just won't accept it. The little circle doesn't work either.
Anything I can do to solve this?
Re: Add custom audio clip array to actor entry in database (like portraits)
Hi,
That's strange. I've never seen that before. Does it still happen if you close and re-open Unity? What Unity version are you using?
As a test, can you try adding a typewriter effect to a new, empty GameObject in the scene, and then try assigning audio clips to it? Maybe this will point out some difference.
That's strange. I've never seen that before. Does it still happen if you close and re-open Unity? What Unity version are you using?
As a test, can you try adding a typewriter effect to a new, empty GameObject in the scene, and then try assigning audio clips to it? Maybe this will point out some difference.
Re: Add custom audio clip array to actor entry in database (like portraits)
I'm using 2021.3.0f1 - still happens when I restart Unity.
Made a new object and gave it Unity UI Typewriter Effect, and was able to assign files just fine. It's only the Audible Dialogue Actor that's giving me static. Every other component allows me to drag and drop objects as normal.
I did make some changes that I don't know if they have anything to do.
became (gives me an error otherwise)
became
(throws an error otherwise as well, saying it can't convert audioclip[] to audioclip)
Made a new object and gave it Unity UI Typewriter Effect, and was able to assign files just fine. It's only the Audible Dialogue Actor that's giving me static. Every other component allows me to drag and drop objects as normal.
I did make some changes that I don't know if they have anything to do.
Code: Select all
var audibleActor = dialogueActor as AudibleAudioActor;
Code: Select all
var audibleActor = dialogueActor as AudibleDialogueActor;
Code: Select all
public AudioClip[] typewriterAudioClip;
public AudioClip[] alternateTypewriterAudioClips;
Code: Select all
public AudioClip typewriterAudioClip;
public AudioClip[] alternateTypewriterAudioClips;
Re: Add custom audio clip array to actor entry in database (like portraits)
I just noticed there was a typo in the script above. The second "serializedObject.Update();" should be:
I just fixed in in the script above, too.
Code: Select all
serializedObject.ApplyModifiedProperties();