Advertisement
Pro_Unit

AnimCurveExample

Sep 24th, 2022
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System;
  2.  
  3. using UniRx;
  4.  
  5. using UnityEngine;
  6.  
  7. namespace UtilityAIExample
  8. {
  9.     public class AnimCurveExample : MonoBehaviour
  10.     {
  11.         [SerializeField] [RangeReactiveProperty(0.0f, 1.0f)]
  12.         private FloatReactiveProperty _time;
  13.  
  14.         [SerializeField] private Factor _bestFactor;
  15.  
  16.         [SerializeField] private Factor[] _factors;
  17.  
  18.         private void Start() =>
  19.             _time.Subscribe(OnTimeChanged);
  20.  
  21.         private void OnTimeChanged(float time)
  22.         {
  23.             int bestFactorIndex = 0;
  24.  
  25.             for (int i = 1; i < _factors.Length; i++)
  26.             {
  27.                 float currentFactorValue = _factors[i].Evaluate(time);
  28.                 float bestFactorValue = _factors[bestFactorIndex].Evaluate(time);
  29.  
  30.                 if (currentFactorValue > bestFactorValue)
  31.                     bestFactorIndex = i;
  32.             }
  33.  
  34.             _bestFactor = _factors[bestFactorIndex];
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement