ShortResponseInstructions.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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
  23. {
  24. public class ShortResponseInstructions : MonoBehaviour
  25. {
  26. // Instructions label
  27. [Header("UI Settings")]
  28. [SerializeField] private Text _instructionsLabel;
  29. // Handles shape changes
  30. private ShortResponseColorHandler _handler;
  31. [Header("Text Settings")]
  32. private string _shapeMissingText = "Say a phrase to select a shape such as 'Select Cube'.";
  33. private string _shapeSelectedText = $"{SHAPE_KEY} Selected. Say a color to set the [SHAPE]'s color.";
  34. private const string SHAPE_KEY = "[SHAPE]";
  35. // Add delegates
  36. private void OnEnable()
  37. {
  38. if (_handler == null)
  39. {
  40. _handler = gameObject.GetComponent<ShortResponseColorHandler>();
  41. }
  42. ShapeSelected(null);
  43. if (_handler != null)
  44. {
  45. _handler.OnShapeSelected += ShapeSelected;
  46. }
  47. }
  48. // Remove delegates
  49. private void OnDisable()
  50. {
  51. if (_handler != null)
  52. {
  53. _handler.OnShapeSelected -= ShapeSelected;
  54. }
  55. }
  56. // Shape selected
  57. private void ShapeSelected(Renderer newShape)
  58. {
  59. if (newShape == null)
  60. {
  61. _instructionsLabel.text = _shapeMissingText;
  62. }
  63. else
  64. {
  65. string shapeName = newShape.gameObject.name;
  66. _instructionsLabel.text = _shapeSelectedText.Replace(SHAPE_KEY, shapeName);
  67. }
  68. }
  69. }
  70. }