/// <summary> A (feedback) collider exits the detector. </summary> /// <param name="other"></param> protected virtual void OnTriggerExit(Collider other) { // Debug.Log("Letgo!"); if (this.modelToCheck != null) //we have access specific GameObjects { int index = ColliderIndex(other.gameObject); //Debug.Log("Releasing Index " + index); this.SetTouch(index, false); if (index > -1 && this.finger[index] <= 0) //check if we removed all fingers. { this.MarkTouching(this.modelToCheck.senseGlove, false); } } else //no access, so we need to check for scripts. { SenseGlove_Feedback script = other.GetComponent <SenseGlove_Feedback>(); if (script != null) { int index = script.GetIndex(); this.SetTouch(index, false); if (index > -1 && this.finger[index] <= 0) //check if we removed all fingers. { this.MarkTouching(script.handModel.senseGlove, false); } } } }
void OnTriggerExit(Collider col) { SenseGlove_Feedback touch = col.GetComponent <SenseGlove_Feedback>(); if (touch && touch.handModel) //must have a grabscript attached. { //SenseGlove_Debugger.Log("Collider Exits"); int scriptIndex = this.HandModelIndex(touch.handModel); if (scriptIndex < 0) { //SenseGlove_Debugger.Log("Something went wrong with " + this.gameObject.name); //it is likely the palm collider. } else { //belongs to an existing SenseGlove. if (ValidScript(touch)) { this.detectedColliders[scriptIndex]--; if (this.detectedColliders[scriptIndex] <= 0) { //raise release event. //SenseGlove_Debugger.Log("Escape!"); if (eventFired[scriptIndex] && !(this.singleGlove && this.detectedGloves.Count > 1)) //only fire if the last glove has been removed. { this.FireRemoveEvent(this.detectedGloves[scriptIndex]); } this.RemoveEntry(scriptIndex); } } } } }
/// <summary> Check if a collider is part of any SenseGlove_Handmodel. </summary> /// <param name="other"></param> /// <returns></returns> protected virtual bool PartOfHand(Collider other) { SenseGlove_Touch touchScript = other.GetComponent <SenseGlove_Touch>(); SenseGlove_Feedback feedbackScript = other.GetComponent <SenseGlove_Feedback>(); return(touchScript != null || feedbackScript != null); }
//-------------------------------------------------------------------------------------------------------------------------- // Collision Detection void OnTriggerEnter(Collider col) { SenseGlove_Feedback touch = col.GetComponent <SenseGlove_Feedback>(); if (touch && touch.handModel) //needs to have a grabscript attached. { int scriptIndex = this.HandModelIndex(touch.handModel); //#1 - Check if it belongs to a new or existing detected glove. if (scriptIndex < 0) { //Debug.Log("New Grabscript entered."); this.AddEntry(touch.handModel); scriptIndex = this.detectedGloves.Count - 1; } else { //Debug.Log("Another collider for grabscript " + scriptIndex); this.detectedColliders[scriptIndex]++; } //if no time constraint is set, raise the event immediately! if (this.activationTime <= 0 && this.detectedColliders[scriptIndex] == this.activationThreshold) { //Debug.Log("ActivationThreshold Reached!"); if (!(eventFired[scriptIndex]) && !(this.singleGlove && this.detectedGloves.Count > 1)) { this.OnGloveDetected(this.detectedGloves[scriptIndex]); this.eventFired[scriptIndex] = true; } } } }
/// <summary> A (feedback) collider exits the detector. </summary> /// <param name="other"></param> private void OnTriggerExit(Collider other) { // Debug.Log("Letgo!"); if (this.modelToCheck != null) //we have access specific GameObjects { int index = ColliderIndex(other.gameObject); //Debug.Log("Releasing Index " + index); this.SetTouch(index, false); } else //no acces, so we need to check for scripts. { SenseGlove_Feedback script = other.GetComponent <SenseGlove_Feedback>(); if (script != null) { this.SetTouch(script.GetIndex(), false); } } }
/// <summary> Set up the touchColliders to send force feedback back to the hand. </summary> protected virtual void SetupFeedbackColliders() { int n = this.touchColliders.Count > 5 ? 5 : this.touchColliders.Count; //ensure we have enough colliders. this.feedbackScripts = new SenseGlove_Feedback[n]; if (this.touchColliders.Count > 0) { for (int f = 0; f < this.feedbackScripts.Length; f++) { SenseGlove_Feedback feedbackCollider = this.touchColliders[f].GetComponent <SenseGlove_Feedback>(); if (feedbackCollider == null) { feedbackCollider = this.touchColliders[f].gameObject.AddComponent <SenseGlove_Feedback>(); } feedbackCollider.touch = this.touchColliders[f]; feedbackCollider.Setup(this); this.feedbackScripts[f] = feedbackCollider; } } }
/// <summary> A new (feedback) collider enters the detector. </summary> /// <param name="other"></param> protected virtual void OnTriggerEnter(Collider other) { // Debug.Log("Touche!"); if (this.modelToCheck != null) //we have access specific GameObjects { int index = ColliderIndex(other.gameObject); //Debug.Log("Touching Index " + index); this.SetTouch(index, true); this.MarkTouching(this.modelToCheck.senseGlove, true); } else //no acces, so we need to check for scripts. { SenseGlove_Feedback script = other.GetComponent <SenseGlove_Feedback>(); if (script != null && script.handModel != null) { this.SetTouch(script.GetIndex(), true); this.MarkTouching(script.handModel.senseGlove, true); } } }
private bool ValidScript(SenseGlove_Feedback touch) { return(this.detectionMethod == DetectionType.AnyFinger || (this.detectionMethod == DetectionType.SpecificFingers && this.ValidScript(touch.GetIndex()))); }