FANDOM


When Auto-name speech audio files? is unchecked, the user is required to assign audio clips manually.  This is better for performance, but requires can be a slog for games with lots of speech audio.

The script searches your Resources folder and automatically assigns files used when the checkbox above is checked.  The required filenames are given in the Speech Manager when this is checked.

For example, the Demo game's Player lines are audio files of the format:

/Resources/Speech/Brain39

This will locate the auto-expected filename and assign it into the manual Audio clip field.

To use, make sure your speech lines are correctly named for auto-assigning, and place them in the appropriate Resources folder.  Then place this script on a GameObject and run the scene.

using UnityEngine;
using System.Collections;
using AC;

public class AutoAssignCustomAudio : MonoBehaviour
{

    public bool overwrite;

    private SpeechManager speechManager;
    private int numAssigned = 0;


    private void Start ()
    {
        if (AdvGame.GetReferences ().speechManager)
        {
            speechManager = AdvGame.GetReferences ().speechManager;
            UpdateAllLines ();
        }
    }


    private void UpdateAllLines ()
    {
        foreach (SpeechLine line in speechManager.lines)
        {
            if (line.textType == AC_TextType.Speech)
            {
                UpdateLine (line);
            }
        }

        Debug.Log (numAssigned + " lines updated.");
    }


    private void UpdateLine (SpeechLine line)
    {
        UpdateLine (line, 0);

        if (speechManager.languages != null && speechManager.languages.Count > 1 && speechManager.translateAudio)
        {
            for (int i=1; i<speechManager.languages.Count; i++)
            {
                UpdateLine (line, i);
            }
        }
    }


    private void UpdateLine (SpeechLine line, int language)
    {
        string fullFilename = "Speech/";
        string filename = line.GetFilename ();
        string languageName = (speechManager.languages != null && speechManager.languages.Count > language) ? speechManager.languages[language] : "";

        if (language > 0 && !string.IsNullOrEmpty (languageName))
        {
            // Not in original language
            fullFilename += languageName + "/";
        }

        if (KickStarter.speechManager.placeAudioInSubfolders)
        {
            fullFilename += filename + "/";
        }

        fullFilename += filename + line.lineID;

        AudioClip clipObj = Resources.Load (fullFilename) as AudioClip;
        if (clipObj != null)
        {
            if (language > 0)
            {
                if (line.customTranslationAudioClips != null && line.customTranslationAudioClips.Count > (language-1))
                {
                    if (line.customTranslationAudioClips[language-1] == null || overwrite)
                    {
                        line.customTranslationAudioClips[language-1] = clipObj;
                    }
                }
            }
            else
            {
                if (line.customAudioClip == null || overwrite)
                {
                    line.customAudioClip = clipObj;
                }
            }

            numAssigned ++;
        }

    }

}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.