-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a post-processor to update Unity string tables on Yarn Project im…
…port Due to a bug in Unity, ScriptedImporter objects aren't able to interact with ScriptableObject instances during import, and Unity string tables are scriptable objects. To work around this, we update the string table after import is complete, using a post-processor.
- Loading branch information
Showing
6 changed files
with
230 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#if USE_UNITY_LOCALIZATION | ||
|
||
using System.Linq; | ||
using UnityEditor; | ||
using UnityEditor.Callbacks; | ||
|
||
#nullable enable | ||
|
||
namespace Yarn.Unity.Editor | ||
{ | ||
/// <summary> | ||
/// An asset post processor that updates Unity Localization string tables | ||
/// when a Yarn Project that uses them is imported. | ||
/// </summary> | ||
/// <remarks> | ||
/// Due to a bug in Unity, <see cref="ScriptedImporter"/> objects aren't | ||
/// able to interact with ScriptableObject instances during import, and | ||
/// Unity string tables are scriptable objects. To work around this, we | ||
/// update the string table after import is complete, using a | ||
/// post-processor. | ||
/// </remarks> | ||
internal class YarnProjectUnityLocalizationUpdater : AssetPostprocessor | ||
{ | ||
[RunAfterPackage("com.unity.localization")] | ||
public static void OnPostprocessAllAssets(string[] importedAssets, | ||
string[] deletedAssets, | ||
string[] movedAssets, | ||
string[] movedFromAssetPaths, | ||
bool didDomainReload) | ||
{ | ||
// Get all importers for Yarn projects that were just imported | ||
var importedYarnProjectAssets = importedAssets | ||
.Select(path => AssetImporter.GetAtPath(path)) | ||
.OfType<YarnProjectImporter>(); | ||
|
||
foreach (var importer in importedYarnProjectAssets) | ||
{ | ||
// If the importer uses Unity Localization, get it to update its | ||
// table | ||
if (importer.UseUnityLocalisationSystem) | ||
{ | ||
importer.AddStringsToUnityLocalization(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
#endif |
11 changes: 11 additions & 0 deletions
11
Editor/Importers/YarnProjectUnityLocalizationUpdater.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.