3D Touch

Setup

Before you start:

  • Build Requirements:    
    iOS 10.0 SDK, Xcode 8.0
  • Runtime Requirements:    
    iOS 9.0 or later

 

First of all, you need to enable 3D Touch API with plugin settings.

The next setup step isn't required, but if you want to tune 3d touch recognition which will better fit your game, you are welcome to do so.

using SA.IOSNative.Gestures;
...

float forceTouchDelay = 0.5f;
float baseForceTouchPressure = 1f;
float triggeringForceTouchPressure = 2.5f;

ForceTouch.Instance.Setup (forceTouchDelay, baseForceTouchPressure, triggeringForceTouchPressure);

 

Events Handling

You may subscribe to the 3d touch events anytime, see the code snippet below:

SA.IOSNative.Gestures.ForceTouch.Instance.OnForceTouchStarted += () => {
	Debug.Log ("OnForceTouchStarted");
};

SA.IOSNative.Gestures.ForceTouch.Instance.OnForceChanged += (SA.IOSNative.Gestures.ForceInfo info) => {
	Debug.Log ("OnForceChanged: " + info.Force + " / " + info.MaxForce);
};

SA.IOSNative.Gestures.ForceTouch.Instance.OnForceTouchFinished += () => {
	Debug.Log ("OnForceTouchFinished");
};

App Menu

With iOS 3d touch you can add addition app launch options that will look similar to the ones on the screenshot below:

If you want to add and handle similar menu items for your app, you need to complete 3 simple steps.

1) Enable the App Events API. See the screenshot below:

2) Add menu items to your app using deploy settings:

3) Handle the menu items actions:

You can check if app has been launched with shortcut item by checking AppOpenshortcutItem value. (if a value is empty, app has been launched normally)

Debug.Log (SA.IOSNative.Gestures.ForceTouch.AppOpenshortcutItem);

In runtime you can subscribe to an OnAppShortcutClick action. See the code snippet below:

SA.IOSNative.Gestures.ForceTouch.Instance.OnAppShortcutClick += (string action) => {
	Debug.Log ("Menu Item With action: " + action + " was clicked");
};

 

 

P.S. Don't hesitate to ask in case you need any other additional to the 3D touch API.

https://stansassets.com/