/// <summary>
    /// Get the SenseGlove_Touch of a specified collider. If none is present, create a new one.
    /// Then apply the desired settings. Returns null if no collider exists.
    /// </summary>
    /// <param name="C"></param>
    /// <returns></returns>
    private SenseGlove_Touch GetTouchScript(Collider C)
    {
        if (C != null)
        {
            C.isTrigger = true;
            SenseGlove_Touch script = C.gameObject.GetComponent <SenseGlove_Touch>();
            if (script == null)
            {
                script = C.gameObject.AddComponent <SenseGlove_Touch>();
            }
            script.touch = C;
            script.SetSourceScript(this);
            script.CreateDebugObject(this.debugColliderColor);
            script.SetDebugLevel(this.debugMode);

            //also add a rigidbody
            Rigidbody RB = C.gameObject.GetComponent <Rigidbody>();
            if (RB == null)
            {
                RB = C.gameObject.AddComponent <Rigidbody>();
            }
            RB.useGravity  = false;
            RB.isKinematic = true;

            return(script);
        }
        return(null);
    }
예제 #2
0
    /// <summary>
    /// Get the SenseGlove_Touch of a specified collider. If none is present, create a new one.
    /// Then apply the desired settings. Returns null if no collider exists.
    /// </summary>
    /// <param name="C"></param>
    /// <returns></returns>
    protected static SenseGlove_Touch GetTouchScript(Collider C, SenseGlove_GrabScript grabScript)
    {
        if (C != null)
        {
            C.isTrigger = true;
            SenseGlove_Touch script = C.gameObject.GetComponent <SenseGlove_Touch>();
            if (script == null)
            {
                script = C.gameObject.AddComponent <SenseGlove_Touch>();
            }
            script.touch = C;
            script.SetSourceScript(grabScript);

            //also add a rigidbody
            Rigidbody RB = C.gameObject.GetComponent <Rigidbody>();
            if (RB == null)
            {
                RB = C.gameObject.AddComponent <Rigidbody>();
            }
            RB.useGravity  = false;
            RB.isKinematic = true;

            return(script);
        }
        return(null);
    }
    /// <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);
    }
예제 #4
0
 /// <summary> Check if two SenseGlove_Touch scripts are touching the same object </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool IsTouching(SenseGlove_Touch other)
 {
     if (other == null)
     {
         SenseGlove_Debugger.LogError("Other is Null"); //If this occurs then our grabScript(s) aren't up to scratch.
     }
     else if (this.touchedObject != null && other.touchedObject != null)
     {
         return(GameObject.ReferenceEquals(this.touchedObject, other.touchedObject));
     }
     return(false);
 }
 /// <summary> Check if two SenseGlove_Touch scripts are touching the same object </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool IsTouching(SenseGlove_Touch other)
 {
     if (other == null)
     {
         SenseGlove_Debugger.Log("Other is Null");
     }
     else
     if (this.touchedObject != null && other.touchedObject != null)
     {
         return(GameObject.ReferenceEquals(this.touchedObject, other.touchedObject));
     }
     return(false);
 }
    /// <summary> Setup the proper scripts and colliders via code. </summary>
    /// <param name="touchColliders"></param>
    /// <param name="palmCollider"></param>
    /// <returns></returns>
    public bool Setup(List <List <Collider> > touchColliders, Collider palmCollider)
    {
        this.handPalm = this.GetTouchScript(palmCollider);
        bool hasPalm = this.handPalm != null;

        bool hasFinger = false, hasThumb = false;

        if (touchColliders != null)
        {
            int n = touchColliders.Count > 5 ? 5 : touchColliders.Count;
            this.touchScripts = new SenseGlove_Touch[n][];
            for (int f = 0; f < this.touchScripts.Length; f++)
            {
                int colliderAmount = 0;
                //count the amount of valid colliders
                for (int i = 0; i < touchColliders[f].Count; i++)
                {
                    if (touchColliders[f][i] != null)
                    {
                        colliderAmount++;
                    }
                }

                //Add only valid colliders!
                this.touchScripts[f] = new SenseGlove_Touch[colliderAmount];
                int colliderIndex = 0;
                for (int i = 0; i < this.touchScripts[f].Length; i++)
                {
                    if (touchColliders[f][i] != null)
                    {
                        this.touchScripts[f][colliderIndex] = GetTouchScript(touchColliders[f][i]);
                        if (f == 0 && this.touchScripts[f][i] != null)
                        {
                            hasThumb = true;
                        }
                        else if (this.touchScripts[f][i] != null)
                        {
                            hasFinger = true;
                        }
                        colliderIndex++;
                    }
                }
            }
        }

        //TODO : Verify the correct Settings.
        this.setupFinished = (hasThumb && hasFinger) || ((hasFinger || hasThumb) && hasPalm);
        return(this.setupFinished);
    }
 /// <summary>
 /// Get the SenseGlove_Touch of a specified collider. If none is present, create a new one.
 /// Then apply the desired settings. Returns null if the Collider is NULL.
 /// </summary>
 /// <param name="C"></param>
 /// <returns></returns>
 private SenseGlove_Touch GetTouchScript(Collider C)
 {
     if (C != null)
     {
         C.isTrigger = true;
         SenseGlove_Touch script = C.gameObject.GetComponent <SenseGlove_Touch>();
         if (script == null)
         {
             script = C.gameObject.AddComponent <SenseGlove_Touch>();
         }
         script.touch = C;
         script.SetSourceScript(this);
         return(script);
     }
     return(null);
 }
예제 #8
0
    /// <summary> Create a primitive object representing this collider, that canbe turned on or off. </summary>
    /// <param name="touchCollider"></param>
    protected static DebugCollider CreateDebugObject(Collider touchCollider)
    {
        SenseGlove_Touch touchScr = touchCollider.GetComponent <SenseGlove_Touch>();
        GameObject       debugObj = null;
        Renderer         rend     = null;

        if (touchCollider != null)
        {
            if (touchCollider is CapsuleCollider)
            {
                debugObj = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            }
            else if (touchCollider is BoxCollider)
            {
                debugObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            }
            else if (touchCollider is SphereCollider)
            {
                debugObj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            }

            if (debugObj != null)
            {
                rend = debugObj.GetComponent <Renderer>();

                debugObj.transform.parent     = null;
                debugObj.transform.position   = touchCollider.transform.position;
                debugObj.transform.rotation   = touchCollider.transform.rotation;
                debugObj.transform.localScale = touchCollider.transform.lossyScale;
                debugObj.transform.parent     = touchCollider.transform;
                debugObj.name = "Debug Collider";

                //Destory the collider, creating only a rendered object.
                Collider C = debugObj.GetComponent <Collider>();
                if (C != null)
                {
                    GameObject.Destroy(C);
                }
                debugObj.SetActive(false); //disable by default?
            }
        }

        return(new DebugCollider(touchScr, rend));
    }
    /// <summary> Retrieve a list of all objects that CAN be grabbed this frame </summary>
    /// <returns></returns>
    public List <SenseGlove_Interactable> GetGrabObjects()
    {
        List <SenseGlove_Interactable> grabables = new List <SenseGlove_Interactable>();

        SenseGlove_Touch thumbTouches = null;

        //if (this.wantsGrab[0]) { thumbTouches = GetTouch(0); } //only if the thumb is used for grabbing
        thumbTouches = GetTouch(0); //the fingers can still override a thumb.wantsGrab()

        //The thumb and hand palm are touching the same object, and the thumb wants to grab something.
        if (thumbTouches != null && this.handPalm != null && wantsGrab[0] && thumbTouches.IsTouching(handPalm.TouchObject()))
        {
            if (thumbTouches.TouchedScript().fingerPalm)
            {
                grabables.Add(thumbTouches.TouchedScript());
            }
        }

        for (int f = 1; f < this.touchScripts.Length; f++)
        {
            if (this.wantsGrab[f]) //if the user wants to grab something with this finger
            {
                SenseGlove_Touch fingerTouches = this.GetTouch(f);
                if (fingerTouches != null) //we've found a touchScript and it is touching an Interactable :D
                {
                    //check thumb-finger
                    if (fingerTouches.TouchedScript().fingerThumb&& thumbTouches != null && fingerTouches.IsTouching(thumbTouches))
                    {
                        grabables.Add(fingerTouches.TouchedScript());
                    }
                    //check finger-palm
                    else if (fingerTouches.TouchedScript().fingerPalm&& handPalm.TouchObject() != null && fingerTouches.IsTouching(handPalm))
                    {
                        grabables.Add(fingerTouches.TouchedScript());
                    }
                    //TODO: check finger-finger
                    //TODO: check fingertip-MCP
                }
            }
        }
        return(grabables);
    }
예제 #10
0
 /// <summary> Called by SenseGlove_Touch when it touches an interactable. Informs this Interactable that it is no longer being touched </summary>
 /// <param name="touchScript"></param>
 public void UnTouchedBy(SenseGlove_Touch touchScript)
 {
     if (touchScript != null && touchScript.GrabScript != null)
     {
         int GI = GetTouchIndex(touchScript.GrabScript);
         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();
                 }
             }
         }
     }
 }
예제 #11
0
    //---------------------------------------------------------------------------------------------------------------------------------
    // Touch Methods

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

                if (this.touchedColliders.Count == 1) // Only for the first new script.
                {
                    this.OnTouched();
                }
            }
        }
    }
예제 #12
0
 /// <summary> Create a new instance of a DebugCollider. </summary>
 /// <param name="touch"></param>
 /// <param name="rend"></param>
 public DebugCollider(SenseGlove_Touch touch, Renderer rend)
 {
     this.renderer    = rend;
     this.touchScript = touch;
 }