123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System;
- using UnityEngine;
- namespace Leap.Unity
- {
- public class HandFader : MonoBehaviour
- {
- protected virtual float GetUnsmoothedConfidence()
- {
- return this._handModel.GetLeapHand().Confidence;
- }
- protected virtual void Awake()
- {
- this._handModel = base.GetComponent<HandModel>();
- this._renderer = base.GetComponentInChildren<Renderer>();
- this._fadePropertyBlock = new MaterialPropertyBlock();
- this._renderer.GetPropertyBlock(this._fadePropertyBlock);
- this._fadePropertyBlock.SetFloat("_Fade", 0f);
- this._renderer.SetPropertyBlock(this._fadePropertyBlock);
- }
- protected virtual void Update()
- {
- float unsmoothedConfidence = this.GetUnsmoothedConfidence();
- this._smoothedConfidence += (unsmoothedConfidence - this._smoothedConfidence) / this.confidenceSmoothing;
- float num = this.confidenceCurve.Evaluate(this._smoothedConfidence);
- this._renderer.enabled = (num > 0.005f);
- this._renderer.GetPropertyBlock(this._fadePropertyBlock);
- this._fadePropertyBlock.SetFloat("_Fade", this.confidenceCurve.Evaluate(this._smoothedConfidence));
- this._renderer.SetPropertyBlock(this._fadePropertyBlock);
- }
- public float confidenceSmoothing = 10f;
- public AnimationCurve confidenceCurve;
- protected HandModel _handModel;
- protected float _smoothedConfidence;
- protected Renderer _renderer;
- protected MaterialPropertyBlock _fadePropertyBlock;
- private const float EPISLON = 0.005f;
- }
- }
|