Access a Term’s Assigned Asset Through Code
- luis Mendez
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
7 years 1 month ago #2530
by luis Mendez
Access a Term’s Assigned Asset Through Code was created by luis Mendez
Hey, all! I’d like to start off by saying that the I2Localization plugin is saving us tons of time on our project. We’re localizing text and audio in more than 10 languages!
That being said, we have A LOT of VO that’s being localized. I’ve set up all the keys for the different pieces of VO that are being played, and I’ve also added the localize component to all audio sources.
Even with all that done, I still need to assign the actual clip for each language. Because we have more than 100 lines of dialogue and more than 10 languages I was wondering if there was a way to get a Term on the Language Source component and if it is of Type Audio Clip, assigning an Audio Clip through code.
All Terms that have dialogue have the prefix ‘VO.’ So it may be easier to filter the search that way. I’ve gotten as far as generating a list of all of these Terms, but that doesn’t do me much good since I want to assign an Audio Clip component to it.
So the meat of my question is the following:
*Is there a way to get a Term in the Localize Source component?
*Can I then assign an Audio Clip to a Term with the following language through code (lets say Russian in this case)?
I’ve been looking for the API and commonly used API but don’t see anything that could help me here. Any help would be appreciated. And if no such calls exist I’ll just suck it up and do them all by hand
That being said, we have A LOT of VO that’s being localized. I’ve set up all the keys for the different pieces of VO that are being played, and I’ve also added the localize component to all audio sources.
Even with all that done, I still need to assign the actual clip for each language. Because we have more than 100 lines of dialogue and more than 10 languages I was wondering if there was a way to get a Term on the Language Source component and if it is of Type Audio Clip, assigning an Audio Clip through code.
All Terms that have dialogue have the prefix ‘VO.’ So it may be easier to filter the search that way. I’ve gotten as far as generating a list of all of these Terms, but that doesn’t do me much good since I want to assign an Audio Clip component to it.
So the meat of my question is the following:
*Is there a way to get a Term in the Localize Source component?
*Can I then assign an Audio Clip to a Term with the following language through code (lets say Russian in this case)?
I’ve been looking for the API and commonly used API but don’t see anything that could help me here. Any help would be appreciated. And if no such calls exist I’ll just suck it up and do them all by hand
Please Log in or Create an account to join the conversation.
7 years 1 month ago #2531
by Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
Replied by Frank on topic Access a Term’s Assigned Asset Through Code
Hi,
You can get the term data using the GetTermData(termName) function.
Here is some code to show several ways of filling the term's translations with an editor script:
Hope that helps,
Frank
You can get the term data using the GetTermData(termName) function.
Here is some code to show several ways of filling the term's translations with an editor script:
LocalizationManager.UpdateSources();
LanguageSource source = LocalizationManager.Sources[0]; // gets I2Languages.prefab
List<string> terms = LocalizationManager.GetTermsList(); // gets all terms
var audio02 = Resources.Load<AudioClip>("Assets/YourAudio/Audio02"); // example asset
List<Object> referencedAssets = new List<Object>(source.Assets); // if your assets are not in the Resources folder, they have to be added here
foreach (var term in terms)
{
var termData = LocalizationManager.GetTermData(term);
if (termData.TermType != eTermType.AudioClip)
continue;
// assigns an audio clip from the resources folder:
termData.Languages[0] = "English/Audio01"; // this references the audioClip at "Resources/English/AudioClip01";
// assigns an audio clip that its not in resources
termData.Languages[1] = "Audio02";
referencedAssets.Add(audio02);
// if you need to set directly into a language:
int langIdx = source.GetLanguageIndex("Russian");
termData.Languages[langIdx] = "Audio03";
}
// add all references
source.Assets = referencedAssets.ToArray();
EditorUtility.SetDirty(source); // just in case
Hope that helps,
Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
To get the betas as soon as they are ready,
check this out
The following user(s) said Thank You: luis Mendez
Please Log in or Create an account to join the conversation.
- luis Mendez
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
7 years 1 month ago #2532
by luis Mendez
Replied by luis Mendez on topic Access a Term’s Assigned Asset Through Code
Awesome! Thank you! That seems like exactly what I need. I’ll make some time to see if I can implement it for a single language and go from there
Please Log in or Create an account to join the conversation.
- luis Mendez
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
7 years 1 month ago #2535
by luis Mendez
Replied by luis Mendez on topic Access a Term’s Assigned Asset Through Code
Just wanted to follow up with you. I got the editor script working! Or so it seems. Whenever I run the editor script the I2Languages prefab gets it looks like it attempts to update the AudioClip slot for the selected language. But instead of assigning the AudioClip it shows a string with the name of the AudioClip I attempted to add. If it helps, the string is also red in the inspector. In this case I'm attempting to assign the AudioClips for Italian.
Here's a picture of what it looks like in engine:
I'm assuming the red string means something, but just not sure what exactly. Any help would be appreciated!
Here's my code:
Here's a picture of what it looks like in engine:
I'm assuming the red string means something, but just not sure what exactly. Any help would be appreciated!
Here's my code:
namespace Common.Editor.Audio
{
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using I2.Loc;
public class AssignAudioClipsToI2 : EditorWindow
{
static AssignAudioClipsToI2 assignLocalizedClips;
static string[] languages = new string[] {"None", "Chinese (Simplified)", "Italian", "Korean", "Russian", "Spanish (Latin)", "Portuguese (Brazil", "German", "Japanese", "Spanish (Castillian)", "French (Parisian)" };
static int languagesPopupIndex;
static int localizationLanguageIndex;
static string langSuffix;
static string audioClipName;
static List<string> terms;
static List<Object> referencedAssets;
LanguageSource source;
int langIndex;
[MenuItem("Deluxe VR/Editor/Audio/Assign Localized Clips", false, 200)]
static void Init()
{
assignLocalizedClips = (AssignAudioClipsToI2)EditorWindow.GetWindow(typeof(AssignAudioClipsToI2));
assignLocalizedClips.Show();
}
private void OnGUI()
{
GUILayout.Label("Assign Localized Audio Clips to I2 Prefab", EditorStyles.boldLabel);
languagesPopupIndex = EditorGUILayout.Popup("Language To Localize", languagesPopupIndex, languages);
if (GUILayout.Button("Assign Clips for Selected Language"))
{
AssignAudioClipsToLanguage(languagesPopupIndex);
}
}
private void GetAudioClipName(string suffix, int index)
{
langIndex = source.GetLanguageIndex("English");
referencedAssets = new List<Object>(source.Assets);
foreach (string term in terms)
{
var termData = LocalizationManager.GetTermData(term);
if (termData.TermType != eTermType.AudioClip)
{
continue;
}
audioClipName = termData.Languages[langIndex].ToString();
termData.Languages[index] = audioClipName + suffix;
}
source.Assets = referencedAssets.ToArray();
EditorUtility.SetDirty(source);
}
private void AssignAudioClipsToLanguage(int index)
{
LocalizationManager.UpdateSources();
source = LocalizationManager.Sources[0];
terms = source.GetTermsList();
switch (index)
{
case 0:
return;
case 1:
langSuffix = "_ZH";
langIndex = source.GetLanguageIndex("Chinese (Hong Kong)");
GetAudioClipName(langSuffix,langIndex);
return;
case 2:
langSuffix = "_IT";
langIndex = source.GetLanguageIndex("Italian");
GetAudioClipName(langSuffix, langIndex);
break;
case 3:
langSuffix = "_KO";
langIndex = source.GetLanguageIndex("Korean");
GetAudioClipName(langSuffix, langIndex);
break;
case 4:
langSuffix = "_RU";
langIndex = source.GetLanguageIndex("Russian");
GetAudioClipName(langSuffix, langIndex);
break;
case 5:
langSuffix = "_LAS";
langIndex = source.GetLanguageIndex("Spanish Latam");
GetAudioClipName(langSuffix, langIndex);
break;
case 6:
langSuffix = "_BPO";
langIndex = source.GetLanguageIndex("Portuguese (Brazil)");
GetAudioClipName(langSuffix, langIndex);
break;
case 7:
langSuffix = "_DE";
langIndex = source.GetLanguageIndex("German");
GetAudioClipName(langSuffix, langIndex);
break;
case 8:
langSuffix = "_JP";
langIndex = source.GetLanguageIndex("Japanese");
GetAudioClipName(langSuffix, langIndex);
break;
case 9:
langSuffix = "_CS";
langIndex = source.GetLanguageIndex("Spanish (Castilian)");
GetAudioClipName(langSuffix, langIndex);
break;
case 10:
langSuffix = "_FR";
langIndex = source.GetLanguageIndex("French");
GetAudioClipName(langSuffix, langIndex);
break;
}
}
}
}
Please Log in or Create an account to join the conversation.
7 years 1 month ago #2536
by Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
Replied by Frank on topic Access a Term’s Assigned Asset Through Code
Hi,
If it shows the AudioClip name in red, it means, that its trying to load it, but can't find it. You should verify that the audio source with that exact name is in the Resources folder, or that you added it to the source.Assets array.
If its in the resources folder, you don't need to place "Resources\" in its path, but you need to write the full path:
e.g. if its in Assets\Resources\Audio\English\MyAudio
then, the name you assign should be: "Audio\\English\\MyAudio"
Hope that helps,
Frank
If it shows the AudioClip name in red, it means, that its trying to load it, but can't find it. You should verify that the audio source with that exact name is in the Resources folder, or that you added it to the source.Assets array.
If its in the resources folder, you don't need to place "Resources\" in its path, but you need to write the full path:
e.g. if its in Assets\Resources\Audio\English\MyAudio
then, the name you assign should be: "Audio\\English\\MyAudio"
Hope that helps,
Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
To get the betas as soon as they are ready,
check this out
Please Log in or Create an account to join the conversation.
Time to create page: 0.136 seconds