First working text rendering
parent
f3698fc108
commit
dbb3281e95
Binary file not shown.
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:282c893d34ca9c703aee8c1af30efe3fcf9fb38d28cee5097a470ddcc2eaaf7a
|
||||
size 364831
|
||||
oid sha256:fe7efdec2d12a1bad8b4661cbb53b092d8082c2a704bb7c2cf18e5c9ab555184
|
||||
size 364850
|
||||
|
Binary file not shown.
@ -1,16 +1,54 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ConformalDecals.Text {
|
||||
public struct DecalText {
|
||||
public string text;
|
||||
public DecalFont font;
|
||||
public FontStyles style;
|
||||
public bool vertical;
|
||||
|
||||
public Color color;
|
||||
public Color outlineColor;
|
||||
public float outlineWidth;
|
||||
public class DecalText : IEquatable<DecalText> {
|
||||
public string Text { get; }
|
||||
|
||||
public DecalFont Font { get; }
|
||||
|
||||
public DecalTextStyle Style { get; }
|
||||
|
||||
public string FormattedText {
|
||||
get {
|
||||
if (Style.Vertical) {
|
||||
return Regex.Replace(Text, @"(.)", "$1\n");
|
||||
}
|
||||
else {
|
||||
return Text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DecalText(string text, DecalFont font, DecalTextStyle style) {
|
||||
Text = text;
|
||||
Font = font;
|
||||
Style = style;
|
||||
}
|
||||
|
||||
public bool Equals(DecalText other) {
|
||||
return other != null && (Text == other.Text && Equals(Font, other.Font) && Style.Equals(other.Style));
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return obj is DecalText other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
unchecked {
|
||||
var hashCode = (Text != null ? Text.GetHashCode() : 0);
|
||||
hashCode = (hashCode * 397) ^ (Font != null ? Font.GetHashCode() : 0);
|
||||
hashCode = (hashCode * 397) ^ Style.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DecalText left, DecalText right) {
|
||||
return left != null && left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DecalText left, DecalText right) {
|
||||
return left != null && !left.Equals(right);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ConformalDecals.Text {
|
||||
public struct DecalTextStyle : IEquatable<DecalTextStyle> {
|
||||
public FontStyles FontStyle { get; set; }
|
||||
|
||||
public bool Bold {
|
||||
get => (FontStyle & FontStyles.Bold) != 0;
|
||||
set {
|
||||
if (value) FontStyle |= FontStyles.Bold;
|
||||
else FontStyle &= ~FontStyles.Bold;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Italic {
|
||||
get => (FontStyle & FontStyles.Italic) != 0;
|
||||
set {
|
||||
if (value) FontStyle |= FontStyles.Italic;
|
||||
else FontStyle &= ~FontStyles.Italic;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Underline {
|
||||
get => (FontStyle & FontStyles.Underline) != 0;
|
||||
set {
|
||||
if (value) FontStyle |= FontStyles.Underline;
|
||||
else FontStyle &= ~FontStyles.Underline;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SmallCaps {
|
||||
get => (FontStyle & FontStyles.SmallCaps) != 0;
|
||||
set {
|
||||
if (value) FontStyle |= FontStyles.SmallCaps;
|
||||
else FontStyle &= ~FontStyles.SmallCaps;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Vertical { get; set; }
|
||||
|
||||
public float LineSpacing { get; set; }
|
||||
|
||||
public float CharacterSpacing { get; set; }
|
||||
|
||||
public bool Equals(DecalTextStyle other) {
|
||||
return FontStyle == other.FontStyle && Vertical == other.Vertical &&
|
||||
Mathf.Approximately(LineSpacing, other.LineSpacing) &&
|
||||
Mathf.Approximately(CharacterSpacing, other.CharacterSpacing);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return obj is DecalTextStyle other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
unchecked {
|
||||
var hashCode = (int) FontStyle;
|
||||
hashCode = (hashCode * 397) ^ Vertical.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ LineSpacing.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ CharacterSpacing.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(DecalTextStyle left, DecalTextStyle right) {
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(DecalTextStyle left, DecalTextStyle right) {
|
||||
return !left.Equals(right);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace ConformalDecals.Text {
|
||||
public class RenderedText : ScriptableObject {
|
||||
public Texture2D Texture { get; private set; }
|
||||
|
||||
public Rect Window { get; private set; }
|
||||
|
||||
public int UserCount { get; private set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue