| | | 1 | | using BNG; |
| | | 2 | | using System.Collections; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using System.Diagnostics.CodeAnalysis; |
| | | 5 | | using UnityEngine; |
| | | 6 | | using UnityEngine.Events; |
| | | 7 | | using VRExplorer; |
| | | 8 | | public class ButtonVR : MonoBehaviour, ITriggerableEntity |
| | | 9 | | { |
| | | 10 | | [ExcludeFromCodeCoverage] public float TriggeringTime => 1.5f; |
| | | 11 | | [ExcludeFromCodeCoverage] public string Name => Str.Triggerable; |
| | | 12 | | |
| | | 13 | | [ExcludeFromCodeCoverage] |
| | | 14 | | public void Triggerring() |
| | | 15 | | { |
| | | 16 | | onPress?.Invoke(); |
| | | 17 | | } |
| | | 18 | | |
| | | 19 | | [ExcludeFromCodeCoverage] |
| | | 20 | | public void Triggerred() |
| | | 21 | | { |
| | | 22 | | onRelease?.Invoke(); |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | public GameObject button; |
| | | 26 | | public UnityEvent onPress; |
| | | 27 | | public UnityEvent onRelease; |
| | | 28 | | GameObject presser; |
| | | 29 | | bool isPressed; |
| | | 30 | | |
| | | 31 | | void Start() |
| | 8 | 32 | | { |
| | 8 | 33 | | isPressed = false; |
| | 8 | 34 | | } |
| | | 35 | | |
| | | 36 | | private void OnTriggerEnter(Collider other) |
| | 3 | 37 | | { |
| | 3 | 38 | | if(!isPressed) |
| | 3 | 39 | | { |
| | 3 | 40 | | button.transform.localPosition = new Vector3(-0.52f, 0.279f, -0.133f); |
| | 3 | 41 | | presser = other.gameObject; |
| | 3 | 42 | | onPress.Invoke(); |
| | 3 | 43 | | isPressed = true; |
| | 3 | 44 | | } |
| | 3 | 45 | | } |
| | | 46 | | |
| | | 47 | | private void OnTriggerExit(Collider other) |
| | 3 | 48 | | { |
| | 3 | 49 | | if(other.gameObject == presser) |
| | 3 | 50 | | { |
| | 3 | 51 | | button.transform.localPosition = new Vector3(-0.544f, 0.279f, -0.133f); |
| | 3 | 52 | | onRelease.Invoke(); |
| | 3 | 53 | | isPressed = false; |
| | 3 | 54 | | } |
| | 3 | 55 | | } |
| | | 56 | | |
| | | 57 | | public void SpawnSphere() |
| | 6 | 58 | | { |
| | 6 | 59 | | GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); |
| | 6 | 60 | | sphere.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); |
| | 6 | 61 | | sphere.transform.localPosition = new Vector3(-0.98f, -0.18f, 0.4f); |
| | 6 | 62 | | sphere.AddComponent<Rigidbody>(); |
| | 6 | 63 | | } |
| | | 64 | | } |