-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoolToFormattedStringAdapter.cs
40 lines (34 loc) · 1.13 KB
/
BoolToFormattedStringAdapter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using TriInspector;
using UnityEngine;
namespace CodeWriter.ViewBinding.Applicators.Adapters
{
[AddComponentMenu("View Binding/Adapters/[Binding] Bool To Formatted String Adapter")]
public class BoolToFormattedStringAdapter : SingleResultAdapterBase<string, ViewVariableString>
{
[Space]
[SerializeField]
private ViewVariableBool source;
[SerializeField]
private string trueFormat = "TRUE";
[SerializeField]
private string falseFormat = "FALSE";
[Required]
[SerializeField]
[ViewContextCollection]
private ViewContextBase[] extraContexts = Array.Empty<ViewContextBase>();
protected override string Adapt()
{
var textBuilder = new ValueTextBuilder(ValueTextBuilder.DefaultCapacity);
try
{
textBuilder.AppendFormat(source.Value ? trueFormat : falseFormat, extraContexts);
return new string(textBuilder.RawCharArray, 0, textBuilder.Length);
}
finally
{
textBuilder.Dispose();
}
}
}
}