123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System;
- using UnityEngine;
- using UnityEngine.UI;
- namespace Leap.Unity
- {
- public class DisconnectionNotice : MonoBehaviour
- {
- private void Start()
- {
- this.leap_controller_ = new Controller();
- this.SetAlpha(0f);
- }
- private void SetAlpha(float alpha)
- {
- base.GetComponent<Image>().color = Color.Lerp(Color.clear, this.onColor, alpha);
- }
- private bool IsConnected()
- {
- return this.leap_controller_.IsConnected;
- }
- private bool IsEmbedded()
- {
- DeviceList devices = this.leap_controller_.Devices;
- return devices.Count != 0 && devices[0].IsEmbedded;
- }
- private void Update()
- {
- if (this.embeddedReplacementImage != null && this.IsEmbedded())
- {
- base.GetComponent<Image>().sprite = this.embeddedReplacementImage;
- }
- if (this.IsConnected())
- {
- this.frames_disconnected_ = 0;
- }
- else
- {
- this.frames_disconnected_++;
- }
- if (this.frames_disconnected_ < this.waitFrames)
- {
- this.fadedIn -= Time.deltaTime / this.fadeOutTime;
- }
- else
- {
- this.fadedIn += Time.deltaTime / this.fadeInTime;
- }
- this.fadedIn = Mathf.Clamp(this.fadedIn, 0f, 1f);
- this.SetAlpha(this.fade.Evaluate(this.fadedIn));
- }
- public float fadeInTime = 1f;
- public float fadeOutTime = 1f;
- public AnimationCurve fade;
- public int waitFrames = 10;
- public Sprite embeddedReplacementImage;
- public Color onColor = Color.white;
- private Controller leap_controller_;
- private float fadedIn;
- private int frames_disconnected_;
- }
- }
|