| | | 1 | | using System; |
| | | 2 | | using System.Collections; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using UnityEngine; |
| | | 5 | | using UnityEngine.XR.Interaction.Toolkit; |
| | | 6 | | public class IfPuzzle : MonoBehaviour |
| | | 7 | | { |
| | | 8 | | [SerializeField] private Transform correctPiece; |
| | | 9 | | [SerializeField] private ifManager linkedIfManager; |
| | | 10 | | |
| | | 11 | | private XRSocketInteractor socket; |
| | | 12 | | |
| | 4 | 13 | | private void Awake() => socket = GetComponent<XRSocketInteractor>(); |
| | | 14 | | |
| | | 15 | | private void OnEnable() |
| | 4 | 16 | | { |
| | 4 | 17 | | if(socket == null) |
| | 2 | 18 | | { |
| | 2 | 19 | | socket = GetComponent<XRSocketInteractor>(); |
| | 2 | 20 | | } |
| | 4 | 21 | | if(socket != null) |
| | 2 | 22 | | { |
| | 2 | 23 | | socket.selectEntered.AddListener(ObjectSnapped); |
| | 2 | 24 | | socket.selectExited.AddListener(ObjectRemoved); |
| | 2 | 25 | | } |
| | 4 | 26 | | } |
| | | 27 | | |
| | | 28 | | private void OnDisable() |
| | 4 | 29 | | { |
| | 4 | 30 | | if (socket == null) |
| | 2 | 31 | | { |
| | 2 | 32 | | socket = GetComponent<XRSocketInteractor>(); |
| | 2 | 33 | | } |
| | 4 | 34 | | if (socket != null) |
| | 2 | 35 | | { |
| | 2 | 36 | | socket.selectEntered.RemoveListener(ObjectSnapped); |
| | 2 | 37 | | socket.selectExited.RemoveListener(ObjectRemoved); |
| | 2 | 38 | | } |
| | 4 | 39 | | } |
| | | 40 | | |
| | | 41 | | private void ObjectSnapped(SelectEnterEventArgs arg0) |
| | 0 | 42 | | { |
| | 0 | 43 | | var snappedObjectName = arg0.interactableObject; |
| | 0 | 44 | | if (snappedObjectName.transform.name == correctPiece.name) |
| | 0 | 45 | | { |
| | 0 | 46 | | linkedIfManager.correctPiece(); |
| | 0 | 47 | | } |
| | 0 | 48 | | } |
| | | 49 | | private void ObjectRemoved(SelectExitEventArgs arg0) |
| | 0 | 50 | | { |
| | 0 | 51 | | linkedIfManager.removedPiece(); |
| | 0 | 52 | | } |
| | | 53 | | } |