-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
Added convertors so you can bind ReactiveProperty types which are not a direct match to the underlying bindee, also added toggle bindings and added some more examples.
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace BindingsRx.Convertors | ||
{ | ||
public interface IConvertor<T1, T2> | ||
{ | ||
T1 From(T2 value); | ||
T2 From(T1 value); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace BindingsRx.Convertors | ||
{ | ||
public class TextToIntConvertor : IConvertor<string, int> | ||
{ | ||
public string From(int value) | ||
{ return value.ToString(); } | ||
|
||
public int From(string value) | ||
{ | ||
int output; | ||
int.TryParse(value, out output); | ||
return output; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace BindingsRx.Convertors | ||
{ | ||
public class TextToDoubleConvertor : IConvertor<string, double> | ||
{ | ||
public string From(double value) | ||
{ return value.ToString(); } | ||
|
||
public double From(string value) | ||
{ | ||
double output; | ||
double.TryParse(value, out output); | ||
return output; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace BindingsRx.Convertors | ||
{ | ||
public class TextToFloatConvertor : IConvertor<string, float> | ||
{ | ||
public string From(float value) | ||
{ return value.ToString(); } | ||
|
||
public float From(string value) | ||
{ | ||
float output; | ||
float.TryParse(value, out output); | ||
return output; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using UniRx; | ||
|
||
namespace BindingsRx.Extensions | ||
{ | ||
public static class IReactivePropertyExtensions | ||
{ | ||
public static ReactiveProperty<string> ToTextualProperty<T>(this IReactiveProperty<T> nonStringProperty) | ||
{ return nonStringProperty.Select(x => x.ToString()).ToReactiveProperty(); } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
using System; | ||
using BindingsRx.Filters; | ||
using BindingsRx.Generic; | ||
using BindingsRx.UI; | ||
using UniRx; | ||
using UnityEngine; | ||
|
||
namespace BindingsRx.GameObjects | ||
{ | ||
public static class MonobehaviourExtensions | ||
public static class MonoBehaviourExtensions | ||
{ | ||
public static IDisposable BindEnabledTo(this MonoBehaviour input, IReactiveProperty<bool> property, BindingTypes bindingType = BindingTypes.Default, params IFilter<bool>[] filters) | ||
{ return GenericBindings.Bind(() => input.enabled, x => input.enabled = x, property, bindingType, filters).AddTo(input); } | ||
|
||
public static IDisposable BindActiveTo(this MonoBehaviour input, Func<bool> getter, Action<bool> setter, BindingTypes bindingType = BindingTypes.Default, params IFilter<bool>[] filters) | ||
public static IDisposable BindEnabledTo(this MonoBehaviour input, Func<bool> getter, Action<bool> setter, BindingTypes bindingType = BindingTypes.Default, params IFilter<bool>[] filters) | ||
{ return GenericBindings.Bind(() => input.enabled, x => input.enabled = x, getter, setter, bindingType, filters).AddTo(input); } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using BindingsRx.Filters; | ||
using BindingsRx.Generic; | ||
using UniRx; | ||
using UnityEngine.UI; | ||
|
||
namespace BindingsRx.UI | ||
{ | ||
public static class ToggleExtensions | ||
{ | ||
public static IDisposable BindToggleTo(this Toggle input, IReactiveProperty<bool> property, BindingTypes bindingType = BindingTypes.Default, params IFilter<bool>[] filters) | ||
{ return GenericBindings.Bind(() => input.isOn, x => input.isOn = x, property, bindingType, filters).AddTo(input); } | ||
|
||
public static IDisposable BindToggleTo(this Toggle input, Func<bool> getter, Action<bool> setter, BindingTypes bindingType = BindingTypes.Default, params IFilter<bool>[] filters) | ||
{ return GenericBindings.Bind(() => input.isOn, x => input.isOn = x, getter, setter, bindingType, filters).AddTo(input); } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.