void OnTriggerExit(Collider col)
    {
        SG_BasicFeedback touch = col.GetComponent <SG_BasicFeedback>();

        if (touch && touch.linkedGlove)
        {
            //SG_Debugger.Log("Collider Exits");
            int scriptIndex = this.HandModelIndex(touch.linkedGlove);
            if (scriptIndex < 0)
            {
                //SG_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.
                        //SG_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);
                    }
                }
            }
        }
    }
Example #2
0
 /// <summary> Called by SG_Feedback when it touches an interactable. Informs this Interactable that it is no longer being touched </summary>
 /// <param name="touchScript"></param>
 public void UnTouchedBy(SG_BasicFeedback touchScript)
 {
     if (touchScript != null && touchScript.linkedGlove != null)
     {
         int GI = GetTouchIndex(touchScript.linkedGlove);
         if (GI > -1)
         {
             this.touchedColliders[GI] = this.touchedColliders[GI] - 1; //++ does not work reliably...
             if (this.touchedColliders[GI] < 1)                         //less than one remaining
             {
                 this.touchedScripts.RemoveAt(GI);
                 this.touchedColliders.RemoveAt(GI);
                 if (this.touchedScripts.Count < 1) //reduced the amount of touchedScripts to 0
                 {
                     this.OnUnTouched();
                 }
             }
         }
     }
 }
Example #3
0
    //---------------------------------------------------------------------------------------------------------------------------------
    // Touch Methods

    /// <summary> Called by SG_Feedback when it touches an interactable. Informs this Interactable that it is being touched. </summary>
    /// <param name="touchScript"></param>
    public void TouchedBy(SG_BasicFeedback touchScript)
    {
        if (touchScript != null && touchScript.linkedGlove != null)
        {
            int GI = GetTouchIndex(touchScript.linkedGlove);
            if (GI > -1)
            {
                this.touchedColliders[GI] = this.touchedColliders[GI] + 1; //++ does not work reliably...
            }
            else
            {
                this.touchedScripts.Add(touchScript.linkedGlove);
                this.touchedColliders.Add(1);

                if (this.touchedColliders.Count == 1) // Only for the first new script.
                {
                    this.OnTouched();
                }
            }
        }
    }
    //--------------------------------------------------------------------------------------------------------------------------
    // Collision Detection

    #region Collision

    void OnTriggerEnter(Collider col)
    {
        SG_BasicFeedback touch = col.GetComponent <SG_BasicFeedback>();

        if (touch && touch.linkedGlove) //needs to have a grabscript attached.
        {
            int scriptIndex = this.HandModelIndex(touch.linkedGlove);

            //#1 - Check if it belongs to a new or existing detected glove.
            if (scriptIndex < 0)
            {
                if (ValidScript(touch))
                {
                    //SG_Debugger.Log("New Grabscript entered.");
                    this.AddEntry(touch.linkedGlove);
                    scriptIndex = this.detectedGloves.Count - 1;
                }
            }
            else
            {
                if (ValidScript(touch))
                {
                    //SG_Debugger.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)
            {
                //SG_Debugger.Log("ActivationThreshold Reached!");
                if (!(eventFired[scriptIndex]) && !(this.singleGlove && this.detectedGloves.Count > 1))
                {
                    this.eventFired[scriptIndex] = true;
                    this.FireDetectEvent(this.detectedGloves[scriptIndex]);
                }
            }
        }
    }
 private bool ValidScript(SG_BasicFeedback touch)
 {
     return(this.detectionMethod == DetectionType.AnyFinger ||
            (this.detectionMethod == DetectionType.SpecificFingers && this.ValidScript(touch.handLocation)));
 }