Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections.Generic;
- public class AnimatorEventSystem {
- public float triggerTheshold = 0.8f; // event curve will never reach 1
- private Animator avatar;
- private Dictionary<int, bool> eventState;
- public AnimatorEventSystem(Animator anim) {
- avatar = anim;
- eventState = new Dictionary<int, bool>();
- }
- public void Update() {
- // proceed events
- if (avatar) {
- foreach (KeyValuePair<int, bool> e in eventState) {
- if (avatar.GetFloat(e.Key) < triggerTheshold) {
- eventState[e.Key] = false;
- }
- }
- }
- }
- public bool CheckEvent(int hash) {
- if (avatar) {
- if (!eventState.ContainsKey(hash)) {
- eventState.Add(hash, false);
- }
- bool result = (!eventState[hash] && (avatar.GetFloat(hash) > triggerTheshold));
- if (result)
- eventState[hash] = true;
- return result;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement