Search Unity

[Released] iOS 3D Touch Plugin & Touch Radius Input Plugin (plug&play)

Discussion in 'Assets and Asset Store' started by Raimis, Oct 2, 2015.

  1. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160

    This plugin is a way to integrate iOS 3D touch (pressure touch) or touch radius into your game before Unity officially supports this feature (please note that Unity 5.2.3f1 added pressure and maximumPossiblePressure properties to Touch class). No Objective-c skills needed, no changes to Unity player. Simply add plugin files to your project and get touches on C# side as you would by using Input.touches.

    Very few allocations and very fast performance thanks to binary serialization/deserialization of touch data. No strings allocations or other memory hungry operations.

    Be first to deploy games for iPhone 6s / iPhone 6s Plus and iPad Pro.



    Features:

    • Full documented source code
    • Full support for iOS 3D Touch API (including iPencil pressure support)
    • Full support for iOS Touch Radius
    • Backwards compatibility to work on iOS 5 and above
    • No objective-c knowledge required - touch data is provided as list of C# objects
    • Easy to understand, documented example project displaying all the features and fallback methods
    • InputManager class to easily handle native touch, unity touch and mouse inputs at the same time



    Compatibility:
    • Works on all iOS devices
    • iOS 5 and above for position and delta position data
    • iOS 8 and above for touch radius data
    • iOS 9 and above for 3d touch data (requires hardware support)
    • Unity 4.6 Pro
    • Unity 5 Free and Pro

    Considerations:
    • Unity documentation states that managed-to-unmanaged calls are CPU intensive on iOS and should be limited to one call per frame. For best performance this plugin uses 1 call of this type per frame. Since only new hardware is supporting 3d touch and you can disable plugin on older devices no need to worry, but I think it's important to mention this.

    Support and feedback:

    • Use this thread to ask questions - I'm more than happy to answer them.
    • Send invoice number to support@pinstudios.com (with subject "iOS 3D Touch Plugin") to subscribe to beta downloads of future releases.
    • If you need urgent help, send requests to support@pinstudios.com
    • Your feedback is highly appreciated so don't hesitate to send it to support email too!


    FAQ:

    1. Does Plugin support Unity 4.6?

    Yes it does. However since plugin contains Objective-C code it requires Unity 4.6 Pro. It works with both - free and paid - versions of Unity 5.

    2. Does Plugin support touch radius?
    Yes, it supports touch radius since version 1.2.

    3. Why is value for maxForce is 6.6666667 and not 1?
    This was decided by apple. I assume that this value will change in the future for other devices that will support 3D touch (including iPad Pro with iPencil). You can assume that force value of 1f is the force of the average touch. Using normalized force value is wrong, because when maxForces will start to differ you won't have a clear reference for what is "pressure of the regular touch".


    4. Is there a way to trigger the haptic feedback?
    Unfortunately Apple doesn't provide such API.

    5. How can I test 3D touch on iPhone Simulator?
    Unfortunately You can't. At the moment iPhone simulator doesn't support 3d touch.

    6. Isn't this supported by Unity?

    Unity added partial support for 3D Touch in 5.2.3f1. Older versions do not support it and plugin is the only way to add 3d touch to games built using those versions of Unity. This plugin has few other advantages:
    1) Touch radius support
    2) Ability to determine if 3D touch or Touch Radius is supported on current device
    3) Callback for event when user switches 3D Touch on or off in accessibility settings
    I think that this plugin is no longer required for majority of Unity developers, however it may be life saver for those very few who still need it.
     
    Last edited: Apr 12, 2016
    Gozdek likes this.
  2. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Last edited: Oct 17, 2015
  3. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Added FAQ section in the first post.
     
  4. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Plugin version 1.2.2 went live today.

    This version adds official support for Unity 4.6 Pro and Touch Radius. Improvements in code comments, documentation and fixes to the bugs that were found within last few weeks.
     
  5. Nitin_CMLABS

    Nitin_CMLABS

    Joined:
    Jul 10, 2015
    Posts:
    15
    Is it possible to implement the pressure touch on App Icon, like we did on Notes App and Instagram App Icons in iPhone 6S & 6S+?
     
  6. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Hello, the short answer is "not with this plugin". This plugin focuses on exposing touch pressure / radius inside the app.

    Static shortcuts are defined in info.plist file in the xcode project, dynamic properties can be added via code, but it's not available in this plugin.
     
  7. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    Hi! Have you tested your plugin on Unity 5.2.2?
     
  8. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Hello, sorry for such late reply. I haven't, is there something wrong with that version of Unity? I would check into it. Plugin works fine with all versions from 4.6.2 - 5.2.1p2. Looking forward to hearing from you.
     
    Last edited: Nov 3, 2015
  9. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Hello @ina, I have tested the plugin today and it works fine with unity 5.2.2p2. I suppose you just wanted to make sure that everything works rather than reporting a problem. Hope this helps.
     
  10. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Watch out for copycat plugins appearing on the store using same color scheme and same icons as this plugin. Being copied means that this plugin has to be good! :)
     
  11. mrbenn

    mrbenn

    Joined:
    May 1, 2015
    Posts:
    13
    We have been using this plugin fine with iOS 8 and 9, but have run into an issue with iOS7. We are getting this crash consistently:
    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UnityView traitCollection]: unrecognized selector sent to instance

    With the partial stack:
    -[AlternativeInput getForceTouchState] (AlternativeInputUnity.mm:197)
    +[AlternativeInput getForceTouchState] (AlternativeInputUnity.mm:64)
    ForceTouchPlugin_GetForceTouchState_m9693 (Bulk_Assembly-CSharp_8.cpp:15714)

    Any ideas?
     
  12. mrbenn

    mrbenn

    Joined:
    May 1, 2015
    Posts:
    13
    Just noticed there is an update, does this fix it?
     
  13. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Yes, this was fixed in 1.2 which is available for ~2 weeks now. Version 1.2 fixes few important bugs so it's important to upgrade to 1.2.

    When you update, please note that there's an option for Touch Radius in 1.2 and that ForceTouchState enum value OldiOS chanded to IncompatibleOS. This is the only refactoring needed when you migrate to 1.2+. Hope this helps.
     
    Last edited: Nov 10, 2015
  14. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    Has iPencil support been tested?
     
  15. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    This plugin will report iPencil pressure and maxpressure like it does with 3d touch. Codewise pencil is just another touch with additional set of properties therefore it wasn't explicitly tested. Please note that this plugin only reports pressure for the pencil, and not other pencil related properties like estimated touches and tilt.
     
  16. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    Do you plan to include tilt?
     
  17. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    TL;DR I don't think I will add other pencil properties to this plugin to keep it as lightweight and as easy to use as possible.

    Pencil API is much more difficult than tilt & pressure. Pencil has these extra properties:
    altitudeAngle Property (New in iOS 9.1)
    azimuthAngleInView
    azimuthUnitVectorInView
    estimatedProperties
    estimationUpdateIndex
    estimatedPropertiesExpectingUpdates
    (see https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITouch_Class/ for explanations what each of them mean)

    Implementing this API partially doesn't make sense and implementing it fully (including estimated properties) would most likely change the workflow of the plugin. Pencil workflow will most likely require more CPU power (even if just a little) and add complexity to usage (you can't simply do plugin.getnativetouches() any more because you need to differentiate estimated touches from confirmed ones). Therefore, since many of customers who buy this plugin only need 3d touch, making plugin less suitable for them wouldn't be a smart move.

    I am considering to create a separate plugin for iPencil with an option to upgrade from this plugin. The new plugin might have 2 packages in it - one for 3d touch only, the other for pencil and 3d touch.
     
  18. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    Would be interested in the Pencil plugin - there does not appear to be one so far
     
  19. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Thank you for letting me know. This of course encourages to work on one even if it will only have very limited sales (due to what I believe very low demand).
     
  20. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    I'd be fine paying $100 for it :) - if it is the only Apple Pencil plugin in the store, I am sure you will get more sales - especially if it is priced reasonably.

    Especially if it's out by next week when the Apple Pencil is released!
     
  21. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    I am considering ipad pro plugin, but only if I will find iPad PRO for rent. Buying ipad for this is way too expensive (and I doubt that this plugin could have more than 5 lifetime sales). API is much more complicated and apple docs are awful at explaining how things work. I would need a device while working on it. I will let you know if I start developing the plugin.
     
  22. Nitin_CMLABS

    Nitin_CMLABS

    Joined:
    Jul 10, 2015
    Posts:
    15
    @Raimis

    how to do that in info.plist.?
    And how to add dynamic properties, Could you please elaborate it in details?
     
  23. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Hey @Nitin_CMLABS, I'm not sure if it's the best thread to discuss this. Here's a nice tutorial on how 3d touch shortcuts work in iOS http://iostuts.io/2015/10/08/how-to-add-quick-actions/. The biggest problem you will face is that you will have to modify AppDelegate.m that is generated by Unity. The next challenge will be to notify unity about the shortcut that was triggered. Nothing undoable though. Hope this helps.

    EDIT: I guess I have the vision on how that could work nicely with Unity workflow. I might work on plugin for that on weekend. Will keep anyone interested in that posted.
     
    Last edited: Nov 26, 2015
  24. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
  25. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
  26. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    If you would've read the FAQ above, you would've known that it's impossible at the given time.
     
  27. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    It seems that native apps can trigger that "single-bump" haptic...
     
  28. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
  29. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
  30. SwabbyNat74

    SwabbyNat74

    Joined:
    Oct 27, 2014
    Posts:
    17
    Hmm, oddly enough, your plugin is capturing the Force variable in iOS, where the Unity Input.isForceAvailable is always coming back false on an iPad Pro, and true on an iPhone 6s/6splus. Is it possible to mix your Plugin with the native touch so i can still receive the data from Azimuth and Altitude for the pencil when available on top of your force touch plugin?
     
  31. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Sure you can, though I'm not convinced yet that you need it. I suppose you refer to flag Input.touchPressureSupported? If so, it will return false on iPad Pro. To detect iPad Pro you should use Input.stylusTouchSupported. I suppose Unity will report force correctly and it's just confusion with the flags you used. Hope this helps.

    EDIT: Though i'd be really interested in seeing how they detect stylus, since there's no API in apple that would offer same functionality. The only solutions i'm able to find require hardcoded device names/resolutions. Previously resolution solution was ok (though it was obvious it was temporary), but now there's ipad supporting stylus that has same resolution as previous gen ipads.
     
    Last edited: Mar 23, 2016
  32. SwabbyNat74

    SwabbyNat74

    Joined:
    Oct 27, 2014
    Posts:
    17
    I've opened a bug report with Unity on this one. Even without the check for touchPressureSupported, the pressure comes back as "1" at all times on the iPad Pro, which is definitely not right. I wrote a quick swift based iOS test, and i can get the pressure working, and the call is no different than the 6s/6splus, so i know its supposed to work. The other issue is that it needs to work with both Pencil and with a finger, back and forth.

    I think they're looking possibly at the touch radius for the stylus support? It always comes back at a value of very small radius proportions, much smaller than i can get with even trying to with my pinky finger.
     
  33. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Thanks for the further info. After the first pencil touch event you can tell if it's a pencil by checking touch type property which will be ".stylus" (swift), but before the first touch ever happens there's no public API (that i'm able to find) to check whether the device supports apple pencil.

    Are you aware of the fact that iPad Pro does not have 3d touch and only supports pencil pressure? Finger will always report 1 on that device. I've seen your ad in the forums, so good luck with that project. If you send your email to info@pinstudios.com with invoice number, I can add you to mailing list to receive new releases as soon as I create them.

    In next release I'm making touches reported by plugin use same id's as fingerId reported by unity, which will allow me use UITouch class extensions to make API more user friendly. This way you will be able to use my plugin to get pressure and then when Unity fixes the bug you'll only have to change one property in your code to make everything work.

    EDIT: found a hack that unity might be using to check pencil support here: http://stackoverflow.com/questions/32542250/detect-whether-apple-pencil-is-connected-to-an-ipad-pro. If for some reason the link becomes obsolete in the future, they simply check for BT device named Apple Pencil to be connected.
     
    Last edited: Mar 24, 2016
  34. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    I have submitted version 1.3 for store review today. It will have Peek and Pop example scene and it will support extension methods for Touch class.
     
  35. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    1.3 is available now.
     
  36. Jee-Hyunho

    Jee-Hyunho

    Joined:
    Mar 16, 2015
    Posts:
    5
    ForceTouchState is "Unavailable" and SupportsForceTouch() returns false on iPad Pro.
    But the documents and comment's in code said ForceTouchState will return "Available" and SupportsForceTouch() will return true on "iPad Pro".
    You may need to correct the docs or change the function correctly.

    BTW, I could get correct infomation of pressure through GetForce() and GetMaxForce() with iPencil.
    GetMaxForce: 4.17

    [Environments]
    iOS 3D Touch & Touch Radius Input Plugin v1.3
    Unity 5.4.1f
    Device: iPad Pro
     
  37. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Hello Jee-Hayunho, sorry for such a late reply. My notification settings were broken :(. Thank you very much for your input. I haven't purchased iPad Pro myself therefore this problem remained unnoticed until now. I am currently working on v1.4 and I will probably move documentations to Google Drive to make such fixes faster (submitting to asset store takes roughly 1 week :().
     
  38. fr330n

    fr330n

    Joined:
    Mar 1, 2017
    Posts:
    1
    Hi Raimis.
    My compiles using your scripts are failed.
    warning CS0618: `ForceTouchPlugin.GetNativeTouches()' is obsolete: `User Touch class extension methods instead (Touch.GetForce(), Touch.GetMaxForce(), Touch.GetRadius(), Touch.GetRadiusTolerance()'

    Could you please update your scripts with new version that will work with Unity 5.5.2f1

    Thanks
     
  39. jimboyte

    jimboyte

    Joined:
    Feb 25, 2013
    Posts:
    23
    Is this asset unsupported? If so, are there any alternatives?