-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
860 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using TMPro; | ||
using UnityEngine; | ||
#if UNITY_EDITOR | ||
using UnityEditor; | ||
#endif | ||
|
||
namespace Aya.DataBinding | ||
{ | ||
[AddComponentMenu("Data Binding/TMP Text Format Value Binder")] | ||
public class TMPTextFormatValueBinder : ComponentBinder<TMP_Text, float, RuntimeTMPTextFormatValueBinder> | ||
{ | ||
public override bool NeedUpdate => true; | ||
public string Text; | ||
|
||
public override RuntimeTMPTextFormatValueBinder CreateDataBinder() | ||
{ | ||
var dataBinder = new RuntimeTMPTextFormatValueBinder | ||
{ | ||
Target = Target, | ||
Context = Context, | ||
Direction = Direction, | ||
Key = Key, | ||
Text = Text | ||
}; | ||
|
||
return dataBinder; | ||
} | ||
|
||
public override void Reset() | ||
{ | ||
Text = "{0:F2}"; | ||
} | ||
} | ||
|
||
public class RuntimeTMPTextFormatValueBinder : DataBinder<TMP_Text, float> | ||
{ | ||
public override bool NeedUpdate => true; | ||
public string Text; | ||
|
||
public override float Value | ||
{ | ||
get => _value; | ||
set | ||
{ | ||
_value = value; | ||
var str = string.Format(Text, _value); | ||
Target.text = str; | ||
} | ||
} | ||
|
||
private float _value; | ||
} | ||
|
||
#if UNITY_EDITOR | ||
|
||
[CustomEditor(typeof(TMPTextFormatValueBinder)), CanEditMultipleObjects] | ||
public class TMPTextFormatValueBinderEditor : ComponentBinderEditor<TMP_Text, float, RuntimeTMPTextFormatValueBinder> | ||
{ | ||
public TMPTextFormatValueBinder Binder => target as TMPTextFormatValueBinder; | ||
protected SerializedProperty TextProperty; | ||
|
||
public override void OnEnable() | ||
{ | ||
base.OnEnable(); | ||
TextProperty = serializedObject.FindProperty(nameof(Binder.Text)); | ||
} | ||
|
||
public override void DrawBody() | ||
{ | ||
EditorGUILayout.PropertyField(TextProperty); | ||
} | ||
} | ||
|
||
#endif | ||
} |
11 changes: 11 additions & 0 deletions
11
Extension/TextMeshPro/Script/TMPTextFormatValueBinder.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
#if UNITY_EDITOR | ||
using UnityEditor; | ||
#endif | ||
|
||
namespace Aya.DataBinding | ||
{ | ||
[AddComponentMenu("Data Binding/Text Format Value Binder")] | ||
public class TextFormatValueBinder : ComponentBinder<Text, float, RuntimeTextFormatValueBinder> | ||
{ | ||
public override bool NeedUpdate => true; | ||
public string Text; | ||
|
||
public override RuntimeTextFormatValueBinder CreateDataBinder() | ||
{ | ||
var dataBinder = new RuntimeTextFormatValueBinder | ||
{ | ||
Target = Target, | ||
Context = Context, | ||
Direction = Direction, | ||
Key = Key, | ||
Text = Text | ||
}; | ||
|
||
return dataBinder; | ||
} | ||
|
||
public override void Reset() | ||
{ | ||
Text = "{0:F2}"; | ||
} | ||
} | ||
|
||
public class RuntimeTextFormatValueBinder : DataBinder<Text, float> | ||
{ | ||
public override bool NeedUpdate => true; | ||
public string Text; | ||
|
||
public override float Value | ||
{ | ||
get => _value; | ||
set | ||
{ | ||
_value = value; | ||
var str = string.Format(Text, _value); | ||
Target.text = str; | ||
} | ||
} | ||
|
||
private float _value; | ||
} | ||
|
||
#if UNITY_EDITOR | ||
|
||
[CustomEditor(typeof(TextFormatValueBinder)), CanEditMultipleObjects] | ||
public class TextFormatValueBinderEditor : ComponentBinderEditor<Text, float, RuntimeTextFormatValueBinder> | ||
{ | ||
public TextFormatValueBinder Binder => target as TextFormatValueBinder; | ||
protected SerializedProperty TextProperty; | ||
|
||
public override void OnEnable() | ||
{ | ||
base.OnEnable(); | ||
TextProperty = serializedObject.FindProperty(nameof(Binder.Text)); | ||
} | ||
|
||
public override void DrawBody() | ||
{ | ||
EditorGUILayout.PropertyField(TextProperty); | ||
} | ||
} | ||
|
||
#endif | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.