Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UniRx;
- using UnityEngine;
- namespace UtilityAIExample
- {
- public class AnimCurveExample : MonoBehaviour
- {
- [SerializeField] [RangeReactiveProperty(0.0f, 1.0f)]
- private FloatReactiveProperty _time;
- [SerializeField] private Factor _bestFactor;
- [SerializeField] private Factor[] _factors;
- private void Start() =>
- _time.Subscribe(OnTimeChanged);
- private void OnTimeChanged(float time)
- {
- int bestFactorIndex = 0;
- for (int i = 1; i < _factors.Length; i++)
- {
- float currentFactorValue = _factors[i].Evaluate(time);
- float bestFactorValue = _factors[bestFactorIndex].Evaluate(time);
- if (currentFactorValue > bestFactorValue)
- bestFactorIndex = i;
- }
- _bestFactor = _factors[bestFactorIndex];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement