ActivateButton.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. * All rights reserved.
  4. *
  5. * Licensed under the Oculus SDK License Agreement (the "License");
  6. * you may not use the Oculus SDK except in compliance with the License,
  7. * which is provided at the time of installation or download, or which
  8. * otherwise accompanies this software in either electronic or hard copy form.
  9. *
  10. * You may obtain a copy of the License at
  11. *
  12. * https://developer.oculus.com/licenses/oculussdk/
  13. *
  14. * Unless required by applicable law or agreed to in writing, the Oculus SDK
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. using UnityEngine;
  21. using UnityEngine.UI;
  22. namespace Oculus.Voice.Demo.LightTraitsDemo
  23. {
  24. public class ActivateButton : MonoBehaviour
  25. {
  26. private bool _active = false;
  27. public AppVoiceExperience appVoiceExperience;
  28. private Text _buttonLabel;
  29. private void Awake()
  30. {
  31. _buttonLabel = GetComponentInChildren<Text>();
  32. }
  33. public void ToggleActive()
  34. {
  35. SetButtonActiveState(!_active);
  36. }
  37. public void SetButtonActiveState(bool newActiveState)
  38. {
  39. if (_active != newActiveState)
  40. {
  41. _active = newActiveState;
  42. if (_active)
  43. {
  44. _buttonLabel.text = "Listening";
  45. appVoiceExperience.Activate();
  46. }
  47. else
  48. {
  49. _buttonLabel.text = "Activate";
  50. appVoiceExperience.Deactivate();
  51. }
  52. }
  53. }
  54. }
  55. }