Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Add Wristwatch #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions Assets/Scripts/Wristwatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Globalization;
using Leap;

public class Wristwatch : MonoBehaviour
{
Controller controller = new Controller();
public UnityEngine.UI.Image i1;
public UnityEngine.UI.Image i2;
public UnityEngine.UI.Image i3;
public UnityEngine.UI.Image i4;
private string tm;
DateTime dt;
// Use this for initialization
void Start () {
dt = DateTime.Now;
}

// Update is called once per frame
void Update()
{
Vector3? wristPosition = GetWristPosition(controller.Frame());
if (wristPosition.HasValue)
{
UnityEngine.Debug.Log(wristPosition.Value.ToString());
ShowWatch();
UpdateWatch();
transform.localPosition = wristPosition.Value;
}
else
{
HideWatch();
}
}

private void ShowWatch()
{
i1.enabled = true;
i2.enabled = true;
i3.enabled = true;
i4.enabled = true;
}

private void HideWatch()
{
i1.enabled = false;
i2.enabled = false;
i3.enabled = false;
i4.enabled = false;
}

private void UpdateWatch ()
{
dt = DateTime.Now;
if (tm != dt.ToString ()) {
string strDate = dt.ToString("T", DateTimeFormatInfo.InvariantInfo);
i1.sprite = Resources.Load <Sprite>(strDate[3].ToString ());
i2.sprite = Resources.Load <Sprite>(strDate[4].ToString ());
i3.sprite = Resources.Load <Sprite>(strDate[6].ToString ());
i4.sprite = Resources.Load <Sprite>(strDate[7].ToString ());
tm = dt.ToString ();
}
}

private Vector3? GetWristPosition (Frame frame)
{
InteractionBox interactionBox = frame.InteractionBox;
Hand hand = frame.Hands.Leftmost;
if (!hand.IsValid) return null;
Vector wristPosition =
(interactionBox.NormalizePoint(hand.Arm.WristPosition, false)
+ new Vector(0.5f, 0f, 0.5f)) * 100.0f;
return new Vector3(wristPosition.x, wristPosition.y, wristPosition.z);
}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/Wristwatch.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading