Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement