Introduce TargetString to eliminate text GC.

This commit is contained in:
2022-11-21 14:09:01 +08:00
parent 784c3fc338
commit 109b489104
4 changed files with 154 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
using Cryville.Common.Pdt;
using Cryville.Common.Buffers;
using Cryville.Common.Pdt;
using System;
using System.Collections.Generic;
using UnityEngine;
@@ -7,7 +8,7 @@ namespace Cryville.Crtr.Components {
public class SpriteText : SpriteBase {
public SpriteText() {
SubmitProperty("frames", new op_set_frames(this));
SubmitProperty("value", new PropOp.String(v => Value = v));
SubmitProperty("value", new PropOp.TargetString(() => Value));
SubmitProperty("size", new PropOp.Float(v => Size = v));
SubmitProperty("spacing", new PropOp.Float(v => Spacing = v));
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
@@ -48,14 +49,8 @@ namespace Cryville.Crtr.Components {
set { m_frames = value; UpdateFrames(); UpdateScale(); }
}
public string m_value;
public string Value {
get { return m_value; }
set {
if (m_value == value) return;
m_value = value; UpdateScale();
}
}
readonly TargetString m_value = new TargetString();
public TargetString Value { get { return m_value; } }
public float m_size;
public float Size {
@@ -175,6 +170,7 @@ namespace Cryville.Crtr.Components {
UpdateFrames();
mesh.Mesh.Clear();
UpdateScale();
Value.OnUpdate += UpdateScale;
}
}
}