2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
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.

62 lines
2.1 KiB

5 years ago
  1. using HTC.UnityPlugin.ColliderEvent;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ShowMenuOnClick : MonoBehaviour
  5. , IColliderEventClickHandler
  6. , IColliderEventPressEnterHandler
  7. , IColliderEventPressExitHandler
  8. {
  9. public GameObject effectMenu;
  10. public ControllerManagerSample controllerManager;
  11. [SerializeField]
  12. private ColliderButtonEventData.InputButton m_activeButton = ColliderButtonEventData.InputButton.Trigger;
  13. public Transform buttonObject;
  14. public Vector3 buttonDownDisplacement;
  15. private Vector3 buttonOriginPosition;
  16. private bool menuVisible = false;
  17. private HashSet<ColliderButtonEventData> pressingEvents = new HashSet<ColliderButtonEventData>();
  18. public ColliderButtonEventData.InputButton activeButton { get { return m_activeButton; } set { m_activeButton = value; } }
  19. private void Start()
  20. {
  21. buttonOriginPosition = buttonObject.position;
  22. SetMenuVisible(menuVisible);
  23. }
  24. public void SetMenuVisible(bool value)
  25. {
  26. menuVisible = value;
  27. effectMenu.gameObject.SetActive(value);
  28. controllerManager.rightLaserPointerActive = value;
  29. controllerManager.leftLaserPointerActive = value;
  30. controllerManager.UpdateActivity();
  31. }
  32. public void OnColliderEventClick(ColliderButtonEventData eventData)
  33. {
  34. if (pressingEvents.Contains(eventData) && pressingEvents.Count == 1)
  35. {
  36. SetMenuVisible(!menuVisible);
  37. }
  38. }
  39. public void OnColliderEventPressEnter(ColliderButtonEventData eventData)
  40. {
  41. if (eventData.button == m_activeButton && eventData.clickingHandlers.Contains(gameObject) && pressingEvents.Add(eventData) && pressingEvents.Count == 1)
  42. {
  43. buttonObject.position = buttonOriginPosition + buttonDownDisplacement;
  44. }
  45. }
  46. public void OnColliderEventPressExit(ColliderButtonEventData eventData)
  47. {
  48. if (pressingEvents.Remove(eventData) && pressingEvents.Count == 0)
  49. {
  50. buttonObject.position = buttonOriginPosition;
  51. }
  52. }
  53. }