-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3deb1b
commit 36159b0
Showing
15 changed files
with
204 additions
and
185 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
namespace TMPro | ||
{ | ||
[Serializable] | ||
public class TmpSpriteAssetData | ||
{ | ||
public string atlasGuid = string.Empty; | ||
public float bearingX = 0.0f; | ||
public float bearingY = 0.0f; | ||
public float advance = 0.0f; | ||
public float scale = 1.0f; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,64 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEditor.AssetImporters; | ||
using UnityEngine; | ||
using UnityEngine.U2D; | ||
|
||
namespace TMPro | ||
{ | ||
[ScriptedImporter(1, FileExtension)] | ||
public class TmpSpriteAssetImporter : ScriptedImporter | ||
{ | ||
public const string FileExtension = "tmpspriteatlas"; | ||
public const string FileExtensionWithDot = ".tmpspriteatlas"; | ||
public const string FileVersion = "1.1.0"; | ||
|
||
private static string[] GatherDependenciesFromSourceFile(string path) | ||
{ | ||
var data = JsonUtility.FromJson<TmpSpriteAssetData>(File.ReadAllText(path)); | ||
var spriteAtlasPath = AssetDatabase.GUIDToAssetPath(data.atlasGuid); | ||
return new[] {spriteAtlasPath}; | ||
} | ||
|
||
public override void OnImportAsset(AssetImportContext ctx) | ||
{ | ||
var mainSpriteAsset = ScriptableObject.CreateInstance<TMP_SpriteAsset>(); | ||
|
||
ctx.AddObjectToAsset("main", mainSpriteAsset); | ||
ctx.SetMainObject(mainSpriteAsset); | ||
|
||
mainSpriteAsset.name = "main"; | ||
mainSpriteAsset.hideFlags = HideFlags.NotEditable; | ||
mainSpriteAsset.fallbackSpriteAssets = new List<TMP_SpriteAsset>(); | ||
|
||
if (EditorSettings.spritePackerMode != SpritePackerMode.SpriteAtlasV2) | ||
{ | ||
ctx.LogImportError("TmpSpriteAtlasAsset can be updates only when spritePackerMode is SpriteAtlasV2"); | ||
return; | ||
} | ||
|
||
var data = JsonUtility.FromJson<TmpSpriteAssetData>(File.ReadAllText(ctx.assetPath)); | ||
|
||
if (!GUID.TryParse(data.atlasGuid, out var spriteAtlasGuid)) | ||
{ | ||
ctx.LogImportError("Failed to import TmpSpriteAtlasAsset: atlas guid is invalid"); | ||
return; | ||
} | ||
|
||
var spriteAtlas = AssetDatabase.LoadMainAssetAtGUID(spriteAtlasGuid) as SpriteAtlas; | ||
if (spriteAtlas == null) | ||
{ | ||
return; | ||
} | ||
|
||
mainSpriteAsset.version = FileVersion; | ||
mainSpriteAsset.hashCode = TMP_TextUtilities.GetSimpleHashCode(spriteAtlas.name); | ||
|
||
TmpSpriteAssetGenerator.Generate(ctx, mainSpriteAsset, spriteAtlas, data); | ||
|
||
mainSpriteAsset.SortGlyphTable(); | ||
mainSpriteAsset.UpdateLookupTables(); | ||
} | ||
} | ||
} |
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.