Advertisement
Guest User

AutoAssignCustomAudio

a guest
Oct 30th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using AC;
  4.  
  5. public class AutoAssignCustomAudio : MonoBehaviour
  6. {
  7.  
  8.     public bool overwrite;
  9.  
  10.     private SpeechManager speechManager;
  11.     private int numAssigned = 0;
  12.  
  13.  
  14.     private void Start()
  15.     {
  16.         if (AdvGame.GetReferences().speechManager)
  17.         {
  18.             speechManager = AdvGame.GetReferences().speechManager;
  19.             UpdateAllLines();
  20.         }
  21.     }
  22.  
  23.  
  24.     private void UpdateAllLines()
  25.     {
  26.         foreach (SpeechLine line in speechManager.lines)
  27.         {
  28.             if (line.textType == AC_TextType.Speech)
  29.             {
  30.                 UpdateLine(line);
  31.             }
  32.         }
  33.  
  34.         Debug.Log(numAssigned + " lines updated.");
  35.     }
  36.  
  37.  
  38.     private void UpdateLine(SpeechLine line)
  39.     {
  40.         UpdateLine(line, 0);
  41.  
  42.         if (speechManager.languages != null && speechManager.languages.Count > 1 && speechManager.translateAudio)
  43.         {
  44.             for (int i = 1; i < speechManager.languages.Count; i++)
  45.             {
  46.                 UpdateLine(line, i);
  47.             }
  48.         }
  49.     }
  50.  
  51.  
  52.     private void UpdateLine(SpeechLine line, int language)
  53.     {
  54.         string fullFilename = "Speech/";
  55.         string filename = line.GetFilename();
  56.         string languageName = (speechManager.languages != null && speechManager.languages.Count > language) ? speechManager.languages[language] : "";
  57.  
  58.         if (language > 0 && !string.IsNullOrEmpty(languageName))
  59.         {
  60.             // Not in original language
  61.             fullFilename += languageName + "/";
  62.         }
  63.  
  64.         if (KickStarter.speechManager.placeAudioInSubfolders)
  65.         {
  66.             fullFilename += filename + "/";
  67.         }
  68.  
  69.         fullFilename += filename + line.lineID;
  70.  
  71.         AudioClip clipObj = Resources.Load(fullFilename) as AudioClip;
  72.         if (clipObj != null)
  73.         {
  74.             if (language > 0)
  75.             {
  76.                 if (line.customTranslationAudioClips != null && line.customTranslationAudioClips.Count > (language - 1))
  77.                 {
  78.                     if (line.customTranslationAudioClips[language - 1] == null || overwrite)
  79.                     {
  80.                         line.customTranslationAudioClips[language - 1] = clipObj;
  81.                     }
  82.                 }
  83.             }
  84.             else
  85.             {
  86.                 if (line.customAudioClip == null || overwrite)
  87.                 {
  88.                     line.customAudioClip = clipObj;
  89.                 }
  90.             }
  91.  
  92.             numAssigned++;
  93.         }
  94.  
  95.     }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement