Skip to content

Commit e744800

Browse files
committed
Merge branch 'release/1.5.0'
2 parents 9a1998b + cf1145b commit e744800

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+742
-470
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.5.0]
9+
10+
### Added
11+
12+
- Default button
13+
14+
### Changed
15+
16+
- Monospaced fonts now respects custom character properties
17+
- Keeping changes at runtime
18+
19+
---
20+
821
## [1.4.0]
922

1023
### Added
@@ -119,6 +132,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
119132

120133
Initial version
121134

135+
[1.5.0]: https://github.com/kleber-swf/unity-bitmap-font-creator/releases/tag/1.5.0
122136
[1.4.0]: https://github.com/kleber-swf/unity-bitmap-font-creator/releases/tag/1.4.0
123137
[1.3.0]: https://github.com/kleber-swf/unity-bitmap-font-creator/releases/tag/1.3.0
124138
[1.2.1]: https://github.com/kleber-swf/unity-bitmap-font-creator/releases/tag/1.2.1

Documentation/screenshot-01.png

1.45 KB
Loading

Editor/Resources/RuntimeData.asset

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: c4647d479c338325f9328893d838e266, type: 3}
13+
m_Name: RuntimeData
14+
m_EditorClassIdentifier:

Editor/Resources/RuntimeData.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Scripts/BitmapFontCreator.cs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,14 @@ private static Material CreateMaterial(string baseName, Texture2D texture)
8585

8686
private static Font CreateFontAsset(string baseName, Material material, ExecutionData data, out string error)
8787
{
88-
error = null;
89-
var map = new Dictionary<char, CharacterProps>();
90-
for (var i = 0; i < data.CustomCharacterProps.Count; i++)
91-
{
92-
var e = data.CustomCharacterProps[i];
93-
if (string.IsNullOrEmpty(e.Character))
94-
{
95-
error = $"Character for Custom Character Properties at position {i + 1} is empty";
96-
return null;
97-
}
98-
map.Add(e.Character[0], e);
99-
}
88+
var custom = GetCustomPropsAsMap(data.CustomCharacterProps, out error);
89+
if (!string.IsNullOrEmpty(error)) return null;
10090

10191
var metrics = new FontMetrics();
10292
var font = new Font(baseName)
10393
{
10494
material = material,
105-
characterInfo = CreateCharacters(data, map, data.Descent, ref metrics),
95+
characterInfo = CreateCharacters(data, custom, data.Descent, ref metrics),
10696
};
10797

10898
var so = new SerializedObject(font);
@@ -115,8 +105,27 @@ private static Font CreateFontAsset(string baseName, Material material, Executio
115105
return font;
116106
}
117107

118-
private static CharacterInfo[] CreateCharacters(ExecutionData data, Dictionary<char, CharacterProps> map,
119-
float descent, ref FontMetrics metrics)
108+
private static Dictionary<char, CharacterProps> GetCustomPropsAsMap(List<CharacterProps> props, out string error)
109+
{
110+
error = null;
111+
var map = new Dictionary<char, CharacterProps>();
112+
113+
for (var i = 0; i < props.Count; i++)
114+
{
115+
var e = props[i];
116+
if (string.IsNullOrEmpty(e.Character))
117+
{
118+
error = $"Character for Custom Character Properties at position {i + 1} is empty";
119+
return null;
120+
}
121+
map.Add(e.Character[0], e);
122+
}
123+
124+
return map;
125+
}
126+
127+
private static CharacterInfo[] CreateCharacters(ExecutionData data, Dictionary<char, CharacterProps> custom,
128+
float descent, ref FontMetrics metrics)
120129
{
121130
var texSize = new Vector2Int(data.Texture.width, data.Texture.height);
122131
var cellSize = new Vector2Int(Mathf.FloorToInt(texSize.x / data.Cols), Mathf.FloorToInt(texSize.y / data.Rows));
@@ -164,14 +173,14 @@ ref gi
164173
gi.uvBottom = cellUVSize.x * (col + 1) - ((cellSize.x - gi.xMax) * ratio.x);
165174
gi.uvRight = cellUVSize.y * (data.Rows - row - 1) + ((cellSize.y - gi.yMax) * ratio.y);
166175

167-
var info = CreateCharacterInfo(ch, gi, map);
176+
var info = CreateCharacterInfo(ch, gi, custom);
168177
characters.Add(info);
169178

170179
if (!data.CaseInsentive) continue;
171180
var ch2 = char.ToUpper(ch);
172-
if (ch2 != ch) characters.Add(CreateCharacterInfo(ch2, gi, map));
181+
if (ch2 != ch) characters.Add(CreateCharacterInfo(ch2, gi, custom));
173182
ch2 = char.ToLower(ch2);
174-
if (ch2 != ch) characters.Add(CreateCharacterInfo(ch2, gi, map));
183+
if (ch2 != ch) characters.Add(CreateCharacterInfo(ch2, gi, custom));
175184

176185
#if BITMAP_FONT_CREATOR_DEV
177186
static string _(float x) => $"<color=yellow>{x}</color>";
@@ -183,12 +192,12 @@ ref gi
183192
characters.Add(CreateSpaceCharacter(advanceMin));
184193

185194
if (data.Monospaced)
186-
SetFontAsMonospaced(characters, advanceMax);
195+
SetFontAsMonospaced(characters, advanceMax, custom);
187196

188197
return characters.ToArray();
189198
}
190199

191-
private static CharacterInfo CreateCharacterInfo(char ch, GlyphInfo g, Dictionary<char, CharacterProps> map)
200+
private static CharacterInfo CreateCharacterInfo(char ch, GlyphInfo g, Dictionary<char, CharacterProps> custom)
192201
{
193202
var info = new CharacterInfo
194203
{
@@ -203,7 +212,7 @@ private static CharacterInfo CreateCharacterInfo(char ch, GlyphInfo g, Dictionar
203212
advance = g.advance,
204213
};
205214

206-
if (map.TryGetValue(ch, out var props))
215+
if (custom.TryGetValue(ch, out var props))
207216
{
208217
info.minX += props.Padding.x;
209218
info.maxX += props.Padding.x;
@@ -256,10 +265,11 @@ private static CharacterInfo CreateSpaceCharacter(int advance)
256265
};
257266
}
258267

259-
private static void SetFontAsMonospaced(List<CharacterInfo> characters, int advMax)
268+
private static void SetFontAsMonospaced(List<CharacterInfo> characters, int advMax, Dictionary<char, CharacterProps> custom)
260269
{
261270
for (var i = 0; i < characters.Count; i++)
262271
{
272+
if (custom.ContainsKey((char)characters[i].index)) continue;
263273
var c = characters[i];
264274
var x = c.minX + Mathf.RoundToInt((advMax - c.advance) * 0.5f);
265275
c.minX += x;

Editor/Scripts/Model/BitmapFontCreatorModel.cs

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,8 @@
44

55
namespace dev.klebersilva.tools.bitmapfontcreator
66
{
7-
internal enum Orientation
8-
{
9-
Horizontal,
10-
Vertical,
11-
}
12-
13-
[Serializable]
14-
internal class CharacterProps
15-
{
16-
public string Character = "";
17-
public Vector2Int Padding = Vector2Int.zero;
18-
public int Spacing = 0;
19-
20-
public CharacterProps Clone()
21-
{
22-
return new CharacterProps
23-
{
24-
Character = Character,
25-
Padding = Padding,
26-
Spacing = Spacing,
27-
};
28-
}
29-
}
30-
317
[Serializable]
32-
internal class BitmapFontCreatorData : ISerializationCallbackReceiver
8+
internal class BitmapFontCreatorModel : ISerializationCallbackReceiver
339
{
3410
private const string IgnoreCharacter = "\n";
3511

@@ -63,7 +39,7 @@ public string Characters
6339
public string ValidCharacters { get; protected set; } = string.Empty;
6440
public int ValidCharactersCount { get; protected set; } = 0;
6541

66-
public virtual void CopyTo(BitmapFontCreatorData dest)
42+
public virtual void CopyTo(BitmapFontCreatorModel dest)
6743
{
6844
if (dest == null) return;
6945

@@ -74,10 +50,10 @@ public virtual void CopyTo(BitmapFontCreatorData dest)
7450
dest.AlphaThreshold = AlphaThreshold;
7551
dest.LineSpacing = LineSpacing;
7652
dest.AutoLineSpacing = AutoLineSpacing;
77-
dest.Monospaced = Monospaced;
78-
dest.CaseInsentive = CaseInsentive;
7953
dest.FontSize = FontSize;
8054
dest.AutoFontSize = AutoFontSize;
55+
dest.Monospaced = Monospaced;
56+
dest.CaseInsentive = CaseInsentive;
8157
dest.Ascent = Ascent;
8258
dest.Descent = Descent;
8359
dest.DefaultCharacterSpacing = DefaultCharacterSpacing;
@@ -91,7 +67,6 @@ public virtual void CopyTo(BitmapFontCreatorData dest)
9167
UpdateChacters();
9268
}
9369

94-
// TODO this should be called automatically when the field Characters changes
9570
private void UpdateChacters()
9671
{
9772
ValidCharacters = _characters.Replace(IgnoreCharacter, string.Empty);
@@ -100,23 +75,23 @@ private void UpdateChacters()
10075

10176
public void OnBeforeSerialize() { }
10277
public void OnAfterDeserialize() { UpdateChacters(); }
103-
}
104-
105-
internal class ExecutionData : BitmapFontCreatorData
106-
{
107-
[NonSerialized] public Texture2D Texture;
10878

109-
public static ExecutionData Default => new()
79+
public static BitmapFontCreatorModel Default => new()
11080
{
111-
Texture = null,
11281
Characters = string.Empty,
11382
Orientation = Orientation.Horizontal,
11483
Cols = 1,
11584
Rows = 1,
11685
AlphaThreshold = 0f,
117-
DefaultCharacterSpacing = 10,
118-
Monospaced = false,
11986
LineSpacing = 0f,
87+
AutoLineSpacing = true,
88+
FontSize = 0f,
89+
AutoFontSize = true,
90+
Monospaced = false,
91+
CaseInsentive = false,
92+
Ascent = 0f,
93+
Descent = 0f,
94+
DefaultCharacterSpacing = 0,
12095
CustomCharacterProps = new List<CharacterProps>(),
12196
ValidCharacters = string.Empty,
12297
ValidCharactersCount = 0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using UnityEngine;
3+
4+
namespace dev.klebersilva.tools.bitmapfontcreator
5+
{
6+
[Serializable]
7+
internal class CharacterProps
8+
{
9+
public string Character = "";
10+
public Vector2Int Padding = Vector2Int.zero;
11+
public int Spacing = 0;
12+
13+
public CharacterProps Clone()
14+
{
15+
return new CharacterProps
16+
{
17+
Character = Character,
18+
Padding = Padding,
19+
Spacing = Spacing,
20+
};
21+
}
22+
}
23+
}

Editor/Scripts/Model/CharacterProps.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Scripts/Model/ExecutionData.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using UnityEngine;
3+
4+
namespace dev.klebersilva.tools.bitmapfontcreator
5+
{
6+
[Serializable]
7+
internal class ExecutionData : BitmapFontCreatorModel
8+
{
9+
public Texture2D Texture;
10+
11+
public static new ExecutionData Default
12+
{
13+
get
14+
{
15+
var data = new ExecutionData { Texture = null };
16+
BitmapFontCreatorModel.Default.CopyTo(data);
17+
return data;
18+
}
19+
}
20+
}
21+
}

Editor/Scripts/Model/ExecutionData.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Scripts/Model/Orientation.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace dev.klebersilva.tools.bitmapfontcreator
2+
{
3+
internal enum Orientation
4+
{
5+
Horizontal,
6+
Vertical,
7+
}
8+
}

Editor/Scripts/Model/Orientation.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Scripts/Model/PrefsModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ public static void Save(PrefsModel model)
2929
EditorPrefs.SetString(EditorPrefsKey, content);
3030
}
3131
}
32-
}
32+
}

Editor/Scripts/Model/RuntimeData.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using UnityEngine;
2+
3+
namespace dev.klebersilva.tools.bitmapfontcreator
4+
{
5+
// [CreateAssetMenu(fileName = "RuntimeData", menuName = "RuntimeData", order = 0)]
6+
internal class RuntimeData : ScriptableObject
7+
{
8+
private const string DataPath = "RuntimeData";
9+
public ExecutionData Data;
10+
11+
public static RuntimeData Load()
12+
{
13+
var data = Resources.Load<RuntimeData>(DataPath);
14+
data.Data ??= ExecutionData.Default;
15+
return data;
16+
}
17+
}
18+
}

Editor/Scripts/Model/RuntimeData.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)