comparison Orchestland/Assets/LeapMotion/Scripts/Utils/DisconnectionNotice.cs @ 1:f7675884f2a1

Add Orchestland project
author Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2015 23:09:20 +0900
parents
children
comparison
equal deleted inserted replaced
0:347d21cdfc22 1:f7675884f2a1
1 /******************************************************************************\
2 * Copyright (C) Leap Motion, Inc. 2011-2014. *
3 * Leap Motion proprietary. Licensed under Apache 2.0 *
4 * Available at http://www.apache.org/licenses/LICENSE-2.0.html *
5 \******************************************************************************/
6
7 using UnityEngine;
8 using System.Collections;
9 using Leap;
10
11 /**
12 * Tracks the connection state of the Leap Motion hardware. If the device is unplugged
13 * or otherwise not detected, the script fades in a GUITexture object which should communicate
14 * the problem to the user.
15 */
16 public class DisconnectionNotice : MonoBehaviour {
17
18 /** The speed to fade the object alpha from 0 to 1. */
19 public float fadeInTime = 1.0f;
20 /** The speed to fade the object alpha from 1 to 0. */
21 public float fadeOutTime = 1.0f;
22 /** The easing curve. */
23 public AnimationCurve fade;
24 /** A delay before beginning the fade-in effect. */
25 public int waitFrames = 10;
26 /** An alternative image to use when the hardware is embedded in a keyboard or laptop. */
27 public Texture2D embeddedReplacementImage;
28 /** The fully on texture tint color. */
29 public Color onColor = Color.white;
30
31 private Controller leap_controller_;
32 private float fadedIn = 0.0f;
33 private int frames_disconnected_ = 0;
34
35 void Start() {
36 leap_controller_ = new Controller();
37 SetAlpha(0.0f);
38 }
39
40 void SetAlpha(float alpha) {
41 GetComponent<GUITexture>().color = Color.Lerp(Color.clear, onColor, alpha);
42 }
43
44 /** The connection state of the controller. */
45 bool IsConnected() {
46 return leap_controller_.IsConnected;
47 }
48
49 /** Whether the controller is embedded in a keyboard or laptop.*/
50 bool IsEmbedded() {
51 DeviceList devices = leap_controller_.Devices;
52 if (devices.Count == 0)
53 return false;
54 return devices[0].IsEmbedded;
55 }
56
57 void Update() {
58 if (embeddedReplacementImage != null && IsEmbedded()) {
59 GetComponent<GUITexture>().texture = embeddedReplacementImage;
60 }
61
62 if (IsConnected())
63 frames_disconnected_ = 0;
64 else
65 frames_disconnected_++;
66
67 if (frames_disconnected_ < waitFrames)
68 fadedIn -= Time.deltaTime / fadeOutTime;
69 else
70 fadedIn += Time.deltaTime / fadeInTime;
71 fadedIn = Mathf.Clamp(fadedIn, 0.0f, 1.0f);
72
73 SetAlpha(fade.Evaluate(fadedIn));
74 }
75 }