Beispiel #1
0
    void Update()
    {
        //the code below is only executed on devices supporting 3d touch
        if (!supportsForceTouch)
        {
            return;
        }

        //if down and touch is not mouse
        if (down && (touchId != -1))
        {
            //use scale to provide visual feedback.
            //this is not crucial, because popup provides better visual feedback
            var t = ForceTouchPlugin.GetTouchExtraData(touchId);             //is the same as Input.GetTouch(touchId).GetExtraData();
            this.gameObject.transform.localScale = Vector3.one * Mathf.Lerp(1f, 1.2f, Mathf.Clamp(t.force / (t.maxforce / 2f), 0f, 1f));

            //code above could be replaced with this as well, but above call has fewer function calls and is JUST A BIT more efficient
            //var t = Input.GetTouch (touchId);
            //this.gameObject.transform.localScale = Vector3.one * Mathf.Lerp (1f, 1.2f, Mathf.Clamp (t.GetForce() / (t.GetMaxForce() / 2f), 0f, 1f));

            popup.SetForce(t.force, t.maxforce);
        }
    }
Beispiel #2
0
 /// <summary>
 /// Extension method for Touch class. Used to retrieve radius tolerance of this touch. Radius tolerance is differs among devices.
 /// </summary>
 /// <returns>Touch radius tolerance.</returns>
 /// <b>Example</b>
 /// <code>
 /// Input.touches[0].GetRadiusTolerance();
 /// </code>
 public static float GetRadiusTolerance(this Touch touch)
 {
     return(ForceTouchPlugin.GetTouchExtraData(touch.fingerId).radiusTolerance);
 }
Beispiel #3
0
 /// <summary>
 /// Extension method for Touch class. Used to retrieve maximum possible force of this touch. MaxForce might be different for different devices.
 /// </summary>
 /// <returns>Maximum possible force of this touch.</returns>
 /// <b>Example</b>
 /// <code>
 /// Input.touches[0].GetMaxForce();
 /// </code>
 public static float GetMaxForce(this Touch touch)
 {
     return(ForceTouchPlugin.GetTouchExtraData(touch.fingerId).maxforce);
 }
Beispiel #4
0
 /// <summary>
 /// Extension method for Touch class. Used to retrieve force and radius data.
 /// </summary>
 /// <returns>NativeTouchExtraData object for this touch containing force and radius data</returns>
 /// <b>Example</b>
 /// <code>
 /// Input.touches[0].GetExtraData();
 /// </code>
 public static NativeTouchExtraData GetExtraData(this Touch touch)
 {
     return(ForceTouchPlugin.GetTouchExtraData(touch.fingerId));
 }