Skip to content

Commit

Permalink
Use material for text color
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyDuchess committed Jun 21, 2024
1 parent 3effb0e commit d71177d
Show file tree
Hide file tree
Showing 5 changed files with 321 additions and 210 deletions.
8 changes: 8 additions & 0 deletions Assets/Resources.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions Assets/Resources/Skia Font Material.mat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Resources/Skia Font Material.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

416 changes: 208 additions & 208 deletions Assets/Scenes/Tests/SkiaUITest.unity

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions Assets/Scripts/OpenTS2/UI/Skia/SkiaLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ namespace OpenTS2.UI.Skia
[RequireComponent(typeof(RawImage))]
public class SkiaLabel : MonoBehaviour
{
private static Material Material
{
get
{
if (_material == null)
_material = Resources.Load<Material>("Skia Font Material");
return _material;
}
}
private static Material _material = null;
public bool SingleLine
{
get
Expand Down Expand Up @@ -152,7 +162,7 @@ public Color FontColor
if (value != m_FontColor)
{
m_FontColor = value;
Render();
ValidateMaterial();
}
}
}
Expand Down Expand Up @@ -413,8 +423,15 @@ public CharRect GetCharacterRect(int charIndex)
}
}

private void ValidateMaterial()
{
RawImage.material = Material;
RawImage.color = m_FontColor;
}

private void Render()
{
ValidateMaterial();
ValidateFont();
var skImageInfo = new SKImageInfo(PracticalWidth, PracticalHeight);
ValidateTexture(skImageInfo);
Expand All @@ -427,7 +444,7 @@ private void Render()

_skPaint.TextSize = m_FontSize;
_skPaint.IsAntialias = true;
_skPaint.Color = new SKColor(m_FontColor.r, m_FontColor.g, m_FontColor.b, m_FontColor.a);
_skPaint.Color = new SKColor(255, 255, 255, 255);
_skPaint.IsStroke = false;

if (m_Font != null && m_Font.Typeface != null)
Expand Down

0 comments on commit d71177d

Please sign in to comment.