HandFader.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using UnityEngine;
  3. namespace Leap.Unity
  4. {
  5. public class HandFader : MonoBehaviour
  6. {
  7. protected virtual float GetUnsmoothedConfidence()
  8. {
  9. return this._handModel.GetLeapHand().Confidence;
  10. }
  11. protected virtual void Awake()
  12. {
  13. this._handModel = base.GetComponent<HandModel>();
  14. this._renderer = base.GetComponentInChildren<Renderer>();
  15. this._fadePropertyBlock = new MaterialPropertyBlock();
  16. this._renderer.GetPropertyBlock(this._fadePropertyBlock);
  17. this._fadePropertyBlock.SetFloat("_Fade", 0f);
  18. this._renderer.SetPropertyBlock(this._fadePropertyBlock);
  19. }
  20. protected virtual void Update()
  21. {
  22. float unsmoothedConfidence = this.GetUnsmoothedConfidence();
  23. this._smoothedConfidence += (unsmoothedConfidence - this._smoothedConfidence) / this.confidenceSmoothing;
  24. float num = this.confidenceCurve.Evaluate(this._smoothedConfidence);
  25. this._renderer.enabled = (num > 0.005f);
  26. this._renderer.GetPropertyBlock(this._fadePropertyBlock);
  27. this._fadePropertyBlock.SetFloat("_Fade", this.confidenceCurve.Evaluate(this._smoothedConfidence));
  28. this._renderer.SetPropertyBlock(this._fadePropertyBlock);
  29. }
  30. public float confidenceSmoothing = 10f;
  31. public AnimationCurve confidenceCurve;
  32. protected HandModel _handModel;
  33. protected float _smoothedConfidence;
  34. protected Renderer _renderer;
  35. protected MaterialPropertyBlock _fadePropertyBlock;
  36. private const float EPISLON = 0.005f;
  37. }
  38. }