Skip to content

Commit

Permalink
Add example scene using the UI Input Module
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwarph committed Jan 31, 2023
1 parent c5860b3 commit a0f20c0
Show file tree
Hide file tree
Showing 8 changed files with 10,275 additions and 14 deletions.
1,195 changes: 1,189 additions & 6 deletions XR_Keyboard/Assets/XR_Keyboard/Prefabs/QwertyKeyboard-Styled.prefab

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
Expand Up @@ -4079,7 +4079,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e760ca7c40cf60b4995aead978b7a749, type: 3}
m_Name:
m_EditorClassIdentifier:
nameField: {fileID: 1147911678}
firstNameField: {fileID: 1147911678}
lastNameField: {fileID: 0}
welcomeText: {fileID: 132656018}
--- !u!114 &751999733
MonoBehaviour:
Expand Down Expand Up @@ -4120,7 +4121,7 @@ MonoBehaviour:
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 0
m_PresetInfoIsWorld: 1
--- !u!223 &751999735
Canvas:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class FormScript : MonoBehaviour
{
public TMP_InputField nameField;
public TMP_InputField firstNameField;
public TMP_InputField lastNameField;
public TextMeshProUGUI welcomeText;
List<string> greetings = new List<string>()
{
Expand All @@ -20,13 +20,30 @@ public class FormScript : MonoBehaviour
public void Greet()
{
int r = Random.Range(0, greetings.Count);
if (nameField.text == "")
string playerName = "";

if (firstNameField == null )
{
return;
}
else
{
playerName = firstNameField.text;
}


if (lastNameField != null )
{
playerName += " " + lastNameField.text;
}

if (playerName == "")
{
welcomeText.text = "";
}
else
{
welcomeText.text = $"{greetings[r]} {nameField.text}!";
welcomeText.text = $"{greetings[r]} {playerName}!";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class KeyboardSpawner : MonoBehaviour
{
public GameObject KeyboardPrefabRoot;
public bool keyboardEnabledOnStart = false;
private bool keyboardActive = false;
protected bool keyboardActive = false;

// Start is called before the first frame update
public virtual void KeyboardStart()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Leap.Unity.Controllers;
using Leap.Unity.Interaction.Keyboard;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

namespace Leap.Unity.Interaction.Storage
{
public class RelativeToHeadKeyboardSpawner : KeyboardSpawner
{
public Transform head;
public Vector3 DistanceFromHead = new Vector3(0, -0.5f, 0.4f);
public Vector3 Angles;

private Vector3 targetLocation;
private Quaternion targetRotation;

private Coroutine moveToRoutine;

public override void SpawnKeyboard()
{
if (keyboardActive)
{
return;
}
else
{
keyboardActive = true;
}
KeyboardPrefabRoot.SetActive(keyboardActive);

}

public override void SpawnKeyboard(Transform currentlySelected)
{
SpawnKeyboard();
}

private void SetPosition()
{

Vector3 newPosition = head.position + (head.forward * DistanceFromHead.z);
newPosition.y = head.position.y + DistanceFromHead.y;

targetLocation = newPosition;

if (moveToRoutine != null)
{
StopCoroutine(moveToRoutine);
}
moveToRoutine = StartCoroutine("MoveToTarget");
}

private IEnumerator MoveToTarget()
{
while (Vector3.Distance(KeyboardPrefabRoot.transform.position, targetLocation) > 0.005f)
{
KeyboardPrefabRoot.transform.position = Vector3.Lerp(KeyboardPrefabRoot.transform.position, targetLocation, Time.deltaTime * 30);
KeyboardPrefabRoot.transform.rotation = Quaternion.Lerp(KeyboardPrefabRoot.transform.rotation, targetRotation, Time.deltaTime * 30);

Vector3 pos = KeyboardPrefabRoot.transform.position;
pos.y = head.position.y;
Vector3 forward = pos - head.position;
targetRotation = Quaternion.LookRotation(forward, Vector3.up);

yield return new WaitForEndOfFrame();
}
}
}
}

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

0 comments on commit a0f20c0

Please sign in to comment.