-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Made NonNativeKeyboard touchable #7611
Changes from all commits
199ae59
9f5f831
5850336
e97553f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.MixedReality.Toolkit.Input; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace Microsoft.MixedReality.Toolkit.Experimental.UI | ||
{ | ||
/// <summary> | ||
/// Adds touch events to the NonNativeKeyboard buttons (and a tap sound) | ||
/// </summary> | ||
public class NonNativeKeyboardTouchAssistant : MonoBehaviour | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a summary and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Summary, okay, but it's already on the prefab, as suggested by @provencher in the Slack channel. You are not going to add this thing to anything - at most you are going to disable it. At least, that was my idea |
||
{ | ||
[SerializeField] | ||
private AudioClip clickSound = null; | ||
|
||
private AudioSource clickSoundPlayer; | ||
|
||
private void Start() | ||
{ | ||
var capabilityChecker = CoreServices.InputSystem as IMixedRealityCapabilityCheck; | ||
|
||
if(capabilityChecker != null && capabilityChecker.CheckCapability(MixedRealityCapability.ArticulatedHand)) | ||
{ | ||
EnableTouch(); | ||
} | ||
} | ||
|
||
private void EnableTouch() | ||
{ | ||
clickSoundPlayer = gameObject.AddComponent<AudioSource>(); | ||
clickSoundPlayer.playOnAwake = false; | ||
clickSoundPlayer.spatialize = true; | ||
clickSoundPlayer.clip = clickSound; | ||
var buttons = GetComponentsInChildren<Button>(); | ||
foreach (var button in buttons) | ||
{ | ||
var ni = button.gameObject.EnsureComponent<NearInteractionTouchableUnityUI>(); | ||
ni.EventsToReceive = TouchableEventType.Pointer; | ||
button.onClick.AddListener(PlayClick); | ||
} | ||
} | ||
|
||
private void PlayClick() | ||
{ | ||
if (clickSound != null) | ||
{ | ||
clickSoundPlayer.Play(); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to make this script run at edit time. No need to add these components at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not like this a very heavy procedure and I am not quite a fan of modifying things at edit time. Messing with the internals of the keyboard changes the scene permanently, not sure if I would like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess my preference is to simply permanently modify the prefab, rather than having a modifier that adds it. I understand both perspectives though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a downside to just updating the prefab to contain all the relevant
NearInteractionTouchableUnityUI
and audioclip components? And leaving them there regardless of if touch is supported? Especially if this script is already being added to the prefab by defaultThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might not always want this, and this way it's easy to disable it.