Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using MalbersAnimations.Scriptables;
- using UniRx;
- using UnityEngine;
- namespace AnimalSimulator.PaintMode.UI
- {
- [Serializable]
- public class RangedSetting : IDisposable
- {
- [SerializeField] private FloatVar _value;
- [SerializeField] private float _min = 0.01f;
- [SerializeField] private float _max = 1.0f;
- public float Value => LerpValue(_value);
- public static implicit operator float(RangedSetting setting) =>
- setting.Value;
- private IDisposable _disposable;
- public void Construct(Action<float> onValueChanged)
- {
- _disposable = Observable
- .FromEvent<float>(
- h => _value.OnValueChanged += h,
- h => _value.OnValueChanged -= h)
- .Subscribe(value => onValueChanged(LerpValue(value)));
- }
- private float LerpValue(float value) =>
- Mathf.Lerp(_min, _max, value);
- public void Dispose() =>
- _disposable?.Dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment