LanguageSource Object[] Assets.
9 years 5 months ago #1102
by yuewah
LanguageSource Object[] Assets. was created by yuewah
Instead of dragging asset into the Assets array in inspector, can you provide easier API to add new item in runtime ?
Also, it is a Array, if there are tons of items, FindAssets might take more time to search for specific item.
Also, it is a Array, if there are tons of items, FindAssets might take more time to search for specific item.
Please Log in or Create an account to join the conversation.
9 years 5 months ago - 9 years 5 months ago #1113
by Frank
Are you
Give I2L
5 stars!
Are you
Please lets us know how to improve it!
Replied by Frank on topic LanguageSource Object[] Assets.
Hi,
Normally, that array only holds 10-30 objects, so linear searching gets mostly as fast as doing a more complex searching. And most of the time when several objects are used, they are added into the Localize component and not the LanguageSource.
However, I can see it taking longer than needed, if you have quite a few objects. In the next release I will try changing the management into a dictionary similar to how the Terms are treated.
I will also add functions to add/delete elements from that array.
In the meantime, you can add this functions to add assets:
LanguageSource.cs (I added the AddAsset( obj ) function)
So you can call
Also, you can a similar function to the Localize component
Hope that helps,
Frank
Normally, that array only holds 10-30 objects, so linear searching gets mostly as fast as doing a more complex searching. And most of the time when several objects are used, they are added into the Localize component and not the LanguageSource.
However, I can see it taking longer than needed, if you have quite a few objects. In the next release I will try changing the management into a dictionary similar to how the Terms are treated.
I will also add functions to add/delete elements from that array.
In the meantime, you can add this functions to add assets:
LanguageSource.cs (I added the AddAsset( obj ) function)
#region Assets
public Object FindAsset( string Name )
{
if (Assets!=null)
{
for (int i=0, imax=Assets.Length; i<imax; ++i)
if (Assets[i]!=null && Assets[i].name == Name)
return Assets[i];
}
return null;
}
public bool HasAsset( Object Obj )
{
return System.Array.IndexOf (Assets, Obj) >= 0;
}
// this is the new function
public void AddAsset( Object Obj )
{
System.Array.Resize (ref Assets, Assets.Length + 1);
Assets [Assets.Length - 1] = Obj;
}
#endregion
So you can call
I2.Loc.LocalizationManager.Sources[0].AddAsset( myObject );
Also, you can a similar function to the Localize component
bool HasTranslatedObject( Object Obj )
{
if (System.Array.IndexOf (TranslatedObjects, Obj) >= 0)
return true;
return ResourceManager.pInstance.HasAsset(Obj);
}
// this is the new function
void AddTranslatedObject( Object Obj )
{
System.Array.Resize (ref TranslatedObjects, TranslatedObjects.Length + 1);
TranslatedObjects [TranslatedObjects.Length - 1] = Obj;
}
#endregion
Hope that helps,
Frank
Are you

Are you

To get the betas as soon as they are ready,
check this out
Last edit: 9 years 5 months ago by Frank.
The following user(s) said Thank You: yuewah
Please Log in or Create an account to join the conversation.
Time to create page: 0.167 seconds