Welcome, Guest
Username: Password: Remember me

TOPIC: Using a LanguageSourceAsset outside of Resources?

Using a LanguageSourceAsset outside of Resources? 2 weeks 6 days ago #3319

  • GFX47
  • GFX47's Avatar
  • Offline
  • New Member
  • Posts: 7
  • Karma: 0
Hi! I'm S├ębastien/@GFX47, a french solo dev making Gladiabots.
I'm currently working on the localization of the game and giving I2Localization a try.

The thing is I'd like to avoid using the LanguageSource component in a scene I'd have to save every time I change terms.
Also I'm not a big fan of Unity's resources system that can be problematic in some cases.
So right now I'm using a LanguageSourceAsset (I've placed in a dedicated project folder) that I'm referencing in my localization manager component.
Basically my code is:
public LanguageSourceAsset sourceAsset;

private void AddSourceToLocalizationManager()
{
	I2.Loc.LocalizationManager.AddSource(this.sourceAsset.mSource);
	this.sourceAsset.mSource.owner = this;
}

private void Awake()
{
	this.AddSourceToLocalizationManager();
}

I also call the AddSourceToLocalizationManager method before doing anything related to localization in editor mode (game stopped).
But the problem is the owner reference often gets lost (probably because of the NonSerialized attribute), causing all kinds of null reference exceptions while using features like auto translation or category change.

The pieces of code raising those exceptions are most of the time something like that:
#if UNITY_EDITOR
	UnityEditor.EditorUtility.SetDirty(i2source.owner);
#endif

So my first question is: is there an option to disable the auto-creation of the I2Languages?
Second question: would you consider supporting the usage of LanguageSourceAsset outside of the Resources folder?
Last Edit: 2 weeks 6 days ago by GFX47.
The administrator has disabled public write access.

Using a LanguageSourceAsset outside of Resources? 2 weeks 5 days ago #3321

  • Frank
  • Frank's Avatar
  • Offline
  • Administrator
  • Posts: 1149
  • Thank you received: 248
  • Karma: 75
Hi,
I'm not a big fan of Unity's resources system that can be problematic in some cases.
So right now I'm using a LanguageSourceAsset (I've placed in a dedicated project folder) that I'm referencing in my localization manager component.

Given that the I2Languages.asset is loaded all the time, there is no real benefit of not using it from the Resources folder.
That should only be considered (as far as I know), in cases where you need to load and then unload assets. But the LanguageSource is always loaded, so, memory and performance wise, the benefits of not using the Resources may not be worth the trouble of the changes needed to handle that.

Said that, if you still prefer using a reference, you should add the source in the UpdateSource function of the LocalizationManager. (Assets\I2\Localization\Scripts\Manager\LocalizationManager_Sources.cs) line 22.
That way, it will be accessible whenever the plugin needs it.

Something like:
public static bool UpdateSources()
{
	UnregisterDeletededSources();
	RegisterSourceInResources();
	RegisterSceneSources();

	LanguageSourceData newSource = YourLocalizationManager.singleton.sourceAsset.Source.mSource;
	if (!Sources.Contains(newSource))
	{
		AddSource(newSource);
	}
	return Sources.Count>0;
}

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 administrator has disabled public write access.
The following user(s) said Thank You: GFX47

Using a LanguageSourceAsset outside of Resources? 2 weeks 4 days ago #3324

  • GFX47
  • GFX47's Avatar
  • Offline
  • New Member
  • Posts: 7
  • Karma: 0
Thanks for your answer! I'll try that.
The administrator has disabled public write access.
Time to create page: 0.120 seconds
Template by JoomlaShine