示例#1
0
    //--------------------------------------------------------------------------------------------------------------------------
    // Collision Detection / Force Feedback

    #region Collision

    // Called when this object enters the collider of another object
    void OnTriggerEnter(Collider col)
    {
        if (this.touchedObject == null)
        {
            SenseGlove_Material     material     = col.GetComponent <SenseGlove_Material>();
            SenseGlove_Interactable interactable = col.GetComponent <SenseGlove_Interactable>();
            if (material || interactable)
            {
                // SenseGlove_Debugger.Log("Touching " + col.name + "; material = " + (material != null) + ", interactable = " + (interactable != null));
                this.touchedObject   = col.gameObject;
                this.touchedScript   = interactable;
                this.touchedMaterial = material;
                this.touchedDeform   = col.GetComponent <SenseGlove_MeshDeform>();

                if (this.handModel.forceFeedback == ForceFeedbackType.Simple && material)
                {
                    this.motorLevel = material.maxForce;
                }
                else if (this.handModel.forceFeedback == ForceFeedbackType.MaterialBased)
                {
                    this.FindForceDirection(col);
                    this.motorLevel = 0; //still 0 since OP == EO
                }

                if (material && material.hapticFeedback)
                {
                    this.buzzLevel = material.hapticMagnitude;
                    this.buzzTime  = material.hapticDuration;
                }
            }
        }
    }
    /// <summary> Attach a material script to this feedback script. </summary>
    /// <param name="material"></param>
    public void Attach(SenseGlove_Material material)
    {
        this.touchedMaterial = material;
        this.touchedObject   = material.gameObject;
        //this.touchedScript = this.touchedObject.GetComponent<SenseGlove_Interactable>();
        this.touchedDeform = this.touchedObject.GetComponent <SenseGlove_MeshDeform>();

        Collider[] cols = this.touchedObject.GetComponents <Collider>();
        if (cols.Length > 0)
        {
            this.touchedCollider = cols[0]; //one of the colliders as a refrence. Assumed that if one of them is disabled, all of the are.
        }
    }
示例#3
0
    //--------------------------------------------------------------------------------------------
    // Monobehaviour

    #region Monobehaviour

    // Use this for initialization
    protected virtual void Start()
    {
        this.wholeDeform   = this.wholeObject.GetComponent <SenseGlove_MeshDeform>();
        this.wholeMaterial = this.wholeObject.GetComponent <SenseGlove_Material>();
        this.wholeMaterial.MaterialBreaks += WholeMaterial_MaterialBreaks;
        this.wholeObject.SaveTransform();

        if (this.brokenObject)
        {
            this.brokenDeform   = this.brokenObject.GetComponent <SenseGlove_MeshDeform>();
            this.brokenMaterial = this.brokenObject.GetComponent <SenseGlove_Material>();
            this.brokenObject.SaveTransform();
        }

        this.UnBreak();
    }
示例#4
0
    // Called during a physics update.
    void FixedUpdate()
    {
        if (touch != null)
        {
            touch.isTrigger = true;
        }                                              //ensure the touch collider is always kinematic.

        if (this.touchedObject != null && !this.touchedObject.activeInHierarchy)
        {
            this.touchedObject   = null;
            this.touchedMaterial = null;
            this.touchedDeform   = null;
            this.motorLevel      = 0;
            this.dist            = 0;
        }
    }
    /// <summary> Detach the connected bject and its force feedback </summary>
    public void Detach()
    {
        if (this.touchedDeform != null)
        {
            this.touchedDeform.ResetMesh();
        }

        this.touchedObject   = null;
        this.touchedMaterial = null;
        this.touchedDeform   = null;
        this.touchedCollider = null;

        this.motorLevel = 0;
        this.buzzLevel  = 0;
        this.dist       = 0;
    }