Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- public class AnimationCurveRelay : MonoBehaviour
- {
- public AnimationCurve SignalCurve;
- public float Signal = 0;
- public float HighSignal = 1;
- public float LowSignal = 0;
- public UnityEvent OnHighSignal, OnLowSignal;
- public bool IsHigh;
- public void SetSignal(float v)
- {
- Signal = SignalCurve.Evaluate(v);
- UpdateSignal();
- }
- private void UpdateSignal(bool force = false)
- {
- if ((force || !IsHigh) && Signal >= HighSignal) {
- IsHigh = true;
- OnHighSignal.Invoke();
- }
- if ((force || IsHigh) && Signal <= LowSignal)
- {
- IsHigh = false;
- OnLowSignal.Invoke();
- }
- }
- private void Start()
- {
- UpdateSignal(true);
- }
- }
- ---
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GlobalCycleManager : MonoBehaviour
- {
- public AnimationCurve curve;
- public float Scale = 1;
- public float V = 0;
- public FloatEvent OnValue;
- // Update is called once per frame
- void Update()
- {
- V = curve.Evaluate(Time.timeSinceLevelLoad * Scale);
- OnValue.Invoke(V);
- }
- }
- [System.Serializable]
- public class FloatEvent : UnityEvent<float> { }
Add Comment
Please, Sign In to add comment