Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.5 KiB

  1. /************************************************************************************
  2. Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
  3. See SampleFramework license.txt for license terms. Unless required by applicable law
  4. or agreed to in writing, the sample code is provided AS IS WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied. See the license for specific
  6. language governing permissions and limitations under the license.
  7. ************************************************************************************/
  8. using UnityEngine;
  9. using UnityEngine.Assertions;
  10. namespace OculusSampleFramework
  11. {
  12. public class WindmillController : MonoBehaviour
  13. {
  14. [SerializeField] private GameObject _startStopButton = null;
  15. [SerializeField] float _maxSpeed = 10f;
  16. [SerializeField] private SelectionCylinder _selectionCylinder = null;
  17. private WindmillBladesController _bladesRotation;
  18. private InteractableTool _toolInteractingWithMe = null;
  19. private void Awake()
  20. {
  21. Assert.IsNotNull(_startStopButton);
  22. Assert.IsNotNull(_selectionCylinder);
  23. _bladesRotation = GetComponentInChildren<WindmillBladesController>();
  24. _bladesRotation.SetMoveState(true, _maxSpeed);
  25. }
  26. private void OnEnable()
  27. {
  28. _startStopButton.GetComponent<Interactable>().InteractableStateChanged.AddListener(StartStopStateChanged);
  29. }
  30. private void OnDisable()
  31. {
  32. if (_startStopButton != null)
  33. {
  34. _startStopButton.GetComponent<Interactable>().InteractableStateChanged.RemoveListener(StartStopStateChanged);
  35. }
  36. }
  37. private void StartStopStateChanged(InteractableStateArgs obj)
  38. {
  39. bool inActionState = obj.NewInteractableState == InteractableState.ActionState;
  40. if (inActionState)
  41. {
  42. if (_bladesRotation.IsMoving)
  43. {
  44. _bladesRotation.SetMoveState(false, 0.0f);
  45. }
  46. else
  47. {
  48. _bladesRotation.SetMoveState(true, _maxSpeed);
  49. }
  50. }
  51. _toolInteractingWithMe = obj.NewInteractableState > InteractableState.Default ?
  52. obj.Tool : null;
  53. }
  54. private void Update()
  55. {
  56. if (_toolInteractingWithMe == null)
  57. {
  58. _selectionCylinder.CurrSelectionState = SelectionCylinder.SelectionState.Off;
  59. }
  60. else
  61. {
  62. _selectionCylinder.CurrSelectionState = (
  63. _toolInteractingWithMe.ToolInputState == ToolInputState.PrimaryInputDown ||
  64. _toolInteractingWithMe.ToolInputState == ToolInputState.PrimaryInputDownStay)
  65. ? SelectionCylinder.SelectionState.Highlighted
  66. : SelectionCylinder.SelectionState.Selected;
  67. }
  68. }
  69. }
  70. }