void Update() { //Check through all desired buttons to see if any have been released /*for (int i = 0; i < buttonsTracked.Count; i++) * { * if (device.GetPressDown(buttonsTracked[i])) * { * Debug.Log("Hemos presionado el boton " + buttonsTracked[i].ToString()); * } * }*/ EVRButtonId[] pressKeys = pressDownObjects.Keys.ToArray(); for (int i = 0; i < pressKeys.Length; i++) { //If tracked button is released if (device.GetPressUp(pressKeys[i])) { //Get all tracked objects in that button's "pressed" list List <FenrirInteractableObject> releaseObjects = pressDownObjects[pressKeys[i]]; for (int j = 0; j < releaseObjects.Count; j++) { //Send button release through to interactable script releaseObjects[j].ButtonPressUp(pressKeys[i], this); } //Clear pressDownObjects[pressKeys[i]].Clear(); currentHeldObject = null; } } }
private void OnTriggerEnter(Collider other) { //If rigidbody's object has interactable item scripts, iterate through them FenrirInteractableObject[] interactables = other.GetComponents <FenrirInteractableObject>(); for (int i = 0; i < interactables.Length; i++) { FenrirInteractableObject interactable = interactables[i]; interactable.TriggerEnter(this); } if (other.attachedRigidbody != null) { } }
void OnTriggerStay(Collider collider) { //If collider has a rigid body to report to if (collider.attachedRigidbody != null) { //If rigidbody's object has interactable item scripts, iterate through them FenrirInteractableObject[] interactables = collider.attachedRigidbody.GetComponents <FenrirInteractableObject>(); if (interactables.Length > 0) { for (int i = 0; i < interactables.Length; i++) { if (!interactables[i].isStatic) { currentHeldObject = interactables[i]; } } } for (int i = 0; i < interactables.Length; i++) { FenrirInteractableObject interactable = interactables[i]; for (int b = 0; b < buttonsTracked.Count; b++) { //If a tracked button is pressed EVRButtonId button = buttonsTracked[b]; if (device.GetPressDown(button)) { //If we haven't already sent the button press message to this interactable //Safeguard against objects that have multiple colliders for one interactable script if (!pressDownObjects.ContainsKey(button) || !pressDownObjects[button].Contains(interactable)) { //Send button press through to interactable script interactable.ButtonPressDown(button, this); //Add interactable script to a dictionary flagging it to recieve notice //when that same button is released if (!pressDownObjects.ContainsKey(button)) { pressDownObjects.Add(button, new List <FenrirInteractableObject>()); } pressDownObjects[button].Add(interactable); } } } } } }