SW 중심대학 OSS GIT 서버 새로운 리포
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.

50 lines
1.4 KiB

5 years ago
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.XR.Interaction.Toolkit;
  6. /// <summary>
  7. /// Special script that work with the XRExclusiveSocket script. This allow to define a SocketType and if that SocketType
  8. /// does not match the XRExclusiveSocket SocketType, this won't be accepted by the socket as a valid target
  9. /// </summary>
  10. [RequireComponent(typeof(XRBaseInteractable))]
  11. public class SocketTarget : MonoBehaviour
  12. {
  13. public string SocketType;
  14. public XRInteractableEvent SocketedEvent;
  15. public bool DisableSocketOnSocketed;
  16. void Awake()
  17. {
  18. var interactable = GetComponent<XRBaseInteractable>();
  19. interactable.onSelectEntered.AddListener(SelectedSwitch);
  20. }
  21. public void SelectedSwitch(XRBaseInteractor interactor)
  22. {
  23. var socketInteractor = interactor as XRExclusiveSocketInteractor;
  24. if(socketInteractor == null)
  25. return;
  26. if(SocketType != socketInteractor.AcceptedType)
  27. return;
  28. if (DisableSocketOnSocketed)
  29. {
  30. //TODO : find a better way, delay feel very wrong
  31. StartCoroutine(DisableSocketDelayed(socketInteractor));
  32. }
  33. SocketedEvent.Invoke(interactor);
  34. }
  35. IEnumerator DisableSocketDelayed(XRExclusiveSocketInteractor interactor)
  36. {
  37. yield return new WaitForSeconds(0.5f);
  38. interactor.socketActive = false;
  39. }
  40. }