-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFloatFormatAdapter.cs
60 lines (51 loc) · 1.8 KB
/
FloatFormatAdapter.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using TriInspector;
using UnityEngine;
namespace CodeWriter.ViewBinding.Applicators.Adapters
{
[AddComponentMenu("View Binding/Adapters/[Binding] Float Format Adapter")]
public class FloatFormatAdapter : SingleResultAdapterBase<float, FloatFormatAdapter.ViewVariableFloatFormatted>
{
[Space]
[SerializeField]
private ViewVariableFloat source = default;
[ShowInInspector]
public int Precision
{
get => result.precision;
set => result.precision = value;
}
[ShowInInspector]
public bool FixedPrecision
{
get => result.fixedPrecision;
set => result.fixedPrecision = value;
}
[Serializable]
public class ViewVariableFloatFormatted : ViewVariable<float, ViewVariableFloatFormatted>
{
public override string TypeDisplayName => "Float (Formatted)";
public int precision = 1;
public bool fixedPrecision = true;
public override void AppendValueTo(ref ValueTextBuilder builder)
{
builder.Append(Value, precision, fixedPrecision);
}
#if UNITY_EDITOR
public override void DoGUI(Rect position, GUIContent label,
UnityEditor.SerializedProperty property, string variableName)
{
property.floatValue = UnityEditor.EditorGUI.FloatField(position, label, property.floatValue);
}
public override void DoRuntimeGUI(Rect position, GUIContent label, string variableName)
{
UnityEditor.EditorGUI.FloatField(position, label, Value, GUI.skin.label);
}
#endif
}
protected override float Adapt()
{
return source.Value;
}
}
}