Tanoda
DisconnectionNotice.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using System.Collections;
11using Leap;
12
13namespace Leap.Unity{
21 public class DisconnectionNotice : MonoBehaviour {
22
24 public float fadeInTime = 1.0f;
26 public float fadeOutTime = 1.0f;
28 public AnimationCurve fade;
30 public int waitFrames = 10;
32 public Color onColor = Color.white;
33
34 private Controller leap_controller_;
35 private float fadedIn = 0.0f;
36 private int frames_disconnected_ = 0;
37 private UnityEngine.UI.Image _image;
38
39 void Start() {
40 leap_controller_ = new Controller();
41 if (_image == null) { _image = GetComponent<UnityEngine.UI.Image>(); }
42 SetAlpha(0.0f);
43 }
44
45 void SetAlpha(float alpha) {
46 if (_image != null) { _image.color = Color.Lerp(Color.clear, onColor, alpha); }
47 }
48
50 bool IsConnected() {
51 return leap_controller_.IsConnected;
52 }
53
54 void Update() {
55
56 if (IsConnected())
57 frames_disconnected_ = 0;
58 else
59 frames_disconnected_++;
60
61 if (frames_disconnected_ < waitFrames)
62 fadedIn -= Time.deltaTime / fadeOutTime;
63 else
64 fadedIn += Time.deltaTime / fadeInTime;
65 fadedIn = Mathf.Clamp(fadedIn, 0.0f, 1.0f);
66
67 SetAlpha(fade.Evaluate(fadedIn));
68 }
69 }
70}
UnityEngine.Color Color
Definition: TestScript.cs:32
The Controller class is your main interface to the Leap Motion Controller.
bool IsConnected
Reports whether this Controller is connected to the Leap Motion service and the Leap Motion hardware ...