Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Input.Touches - Simple Gesture Solution

Discussion in 'Assets and Asset Store' started by Song_Tan, Apr 28, 2012.

  1. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    FrontPage.png

    Introducing "Input.Touches", a low cost, easy to use helper library for Unity3 touch (and mouse) input.

    Input.Touches uses event system to signal various input event. Letting you focus on dealing with your actual code instead of juggling with various input.

    • Supported input event:
      - single finger: short tap, long tap, multi-tap, charge(timed-pressed), drag, swipe
      - multi-finger: short tap, long tap, multi-tap, charge(timed-pressed), drag.
      - special gesture: pinch, rotate
    • Support concurrent input (2 or more input type at the same time) for most events. The exception are multi-finger drag, pinch and rotate.
    • Uses event system, keep things simple.
    • Support both JS and C#.
    • Tested and works on PC and iOS device.
    • Various example scene with documented code in both JS and C#.
    • Compatible and supported by Playmaker.
    • Comes with support of a dedicated developer. :)
    Feel free to download and try out the demo. Please visit here for more information.

    Input.Touches is now available on AssetStore, link here. Feel free to comment or pm me if you have any question.


    * Please note that you will need some scripting knowledge to use this library.
    * Please note that this framework only works on hardware that is supported by unity by default.
     
    Last edited: Apr 3, 2017
  2. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Just another shameless bump now that the package is now live on AssetStore. Thanks again for reading.
     
  3. twitchfactor

    twitchfactor

    Joined:
    Mar 8, 2009
    Posts:
    356
    So, is this a code-once solution? I'm looking for something easy to use, that doesn't require me to re-write or juggle input schemes between platforms (PC/Mac vs. iOS). It also has to support JS and be well-documented (as you've already stated, just calling it out).
     
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    This should work just fine switching from PC to Mac to device. I myself does that quite often and I understand it's quite a pain trying to maintain input code for build across all platforms.

    I dont have an extensive example of js but I do include a simple demonstration of how to use the event system using js. I think I have a rather comprehensive documentation and example code. But I'm happy to take any feedback and make the necessary amendment. You can be sure that customer satisfaction is my first concern.
     
  5. milkhall

    milkhall

    Joined:
    May 24, 2012
    Posts:
    1
    This solution supports multi-touch operation of Windows7?
     
  6. ShawnMcCoo1

    ShawnMcCoo1

    Joined:
    Dec 26, 2011
    Posts:
    39
    Question, is multi-touch possible in the flash player?
     
  7. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @milkhall, This framework uses only unity default touch input functionality. As far as I know it does not support multi-touch on window7. So the answer is no.

    @Shawn, The framework is very much device and system dependant. If the input device is supported by unity, then yes. Pardon me but I'm not sure what device and system you are refering to. My understand is flash player are not available on iOS device, which this framework is developed and tested on. I imagine it should work just fine on an android device. However if you other desktop based touch input device, then unfortunately the answer is no.
     
  8. HeyGuys

    HeyGuys

    Joined:
    May 24, 2012
    Posts:
    21
    Would the code works across iOS, Android, and PC (Unity Simulator)?
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @HeyGuys, Yes, it should be able to do just that.
     
  10. abbc

    abbc

    Joined:
    Mar 12, 2011
    Posts:
    52
    Hi. The RTS camera demo in your package does not work as well as the web demo. When I move camera with right mouse button, the camera only moves slightly, while on the web demo it works perfectly. I tried to increase panSpeedModifier to 1000, still no luck.
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @abbc, I dont seem to have that problem, both on my window pc and mac. Can you please let me know platform are you running on? It would help tremendously if you could just sent me your package so I can take a closer look.
     
  12. abbc

    abbc

    Joined:
    Mar 12, 2011
    Posts:
    52
  13. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    I've just bought this, tried on Windows and Android. Curently, there is no problem for me. The RTSdemo just worked out of the box. The only problem with the RTSdemo is that the camera does not rotate around the "target" object, instead it rotates around its parent. Therefore the "target" slot is a bit confusing, since it's not used at all.

    Anyway, thanks for this simple and effective tool.... very well worth the price.
     
    Last edited: May 25, 2012
  14. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Thanks for the feedback regarding the RTSdemo. I'll make sure that I remedy that in the next update.

    Appreciate the kind words you put in. :)
     
  15. GamaGui

    GamaGui

    Joined:
    Apr 21, 2012
    Posts:
    15
    This looks useful. Just bought it. Hope to try it out soon!
     
  16. Gooms9

    Gooms9

    Joined:
    Dec 17, 2011
    Posts:
    31
    None of the complicated taps seem to be working. I'm using the latest version of unity. I open your tap demo scene, and the only one in there that seems to work is the drag one. Is there anything else I need to do to get them to work?
     
  17. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @Grooms, I have pm you. Could you plase respond so I can help you to sort out the issue. Thanks.
     
  18. delstrega

    delstrega

    Joined:
    Apr 22, 2012
    Posts:
    14
    I had the same issue, it seems things got commented out (the whole code for detecting in editor).

    Easy fix though:
    In TapDetector.cs in line 115 remove the "//" so that

    #if (!UNITY_IPHONE !UNITY_ANDROID) //|| UNITY_EDITOR

    becomes

    #if (!UNITY_IPHONE !UNITY_ANDROID) || UNITY_EDITOR


    EDIT:
    I just realized that SwipeDetector.cs has the same issue. Just change line 132 the same way.
    EDIT 2:
    Changing SwipeDetector.cs the way I described f*cks up the SwipeDetector-Demo completely. It says it always detects a swipe as soon as you click somewhere in the editor. The sphere moves erratically when moving the mouse while fire1 is held down.
    EDIT 3:
    Added " (!UNITY_EDITOR)" in line 46 in TapDetector.cs and line 75 in SwipeDetector.cs and now it's working fine.

    Hope that helps
     
    Last edited: May 27, 2012
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @delstrega, Thanks alot for the elaborate modification. I really appreaciate it. The issue where some of the input are not working are cuased by the target platform selection. The mouse Input wouldnt work properly when the target platform is set to iOS or Andriod.

    I'm quite aware of this. The lines of code such as

    Code (csharp):
    1. #if (!UNITY_IPHONE  !UNITY_ANDROID) || UNITY_EDITOR
    and

    Code (csharp):
    1. #if UNITY_IPHONE || UNITY_ANDROID
    are there to prevent mouse and touch input to be detected simultaneously. The reason is unity would detech mouse input as a finger touch and vive versa. However the detection of touch input as mouse would only applied if the target platform is set to iOS. Without this platform depandant compilation, the mouse input detection would mess up the touch input when running on device.

    By default, those purposefully coded restriction prevent mouse input to work when the platform is set to mobile. The reason I made it so is that I would expect developer to be more keen on testing their mobile build via touch using device or Unity Remote. delstrega's is a vaible solution which would enable mouse input to work when the platform is set to iOS or android, however in doing so the touch input can only tested when running on a device, which of course prevent the usage of unity remote.

    TLDR: The default code will only allow touch input but not mouse input in mobile platform. Hope this clear up the issue.
     
  20. delstrega

    delstrega

    Joined:
    Apr 22, 2012
    Posts:
    14
    I see now, so that's why you did it this way. Since I don't use Unity Remote that much, I hadn't actually noticed that it wouldn't work correctly the way I "fixed" the scripts. But to be honest, it was kinda odd seeing the provided examples not working in the editor using mouse input.

    Thanks for the clarification! :)


    EDIT: I thought the dragging in TapDemo was kinda strange too (in Editor) so I played around with the code some more. Here's the fix for that:

    General.cs line 17: add " (!UNITY_EDITOR)" and the dragging works fine.

    (Mind songtan's previous post though!)
     
    Last edited: May 27, 2012
  21. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @kicki2k, sent a pm your way. :)
     
  22. Menace03

    Menace03

    Joined:
    Apr 25, 2011
    Posts:
    5
    Song,

    I have the same issue..

    Thx.
     
  23. simone007

    simone007

    Joined:
    Oct 30, 2008
    Posts:
    221
    A review: great component, easy to use, works perfectly
     
  24. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @simone007, Thanks for the kind word! Appreaciated that!

    Anyway, this is just a quick announcement that a new version has been submitted to the AssetStore. With some bug fix and a revision to the touch/mouse conflict problem. The new version should be able to handle both mouse and touch input without any complication regardless of the platform.

    For more information, please follow this link.

    I'll post again when the new version is live on AssetStore. Thanks for your support!
     
  25. franticnick

    franticnick

    Joined:
    Jun 1, 2012
    Posts:
    2
    Good that is on sale but shame it's only 0% off :)
     
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @franticnick, Indeed, thanks for the notice. I just found that out myself. It appears that the update has cause some issue. I'm not sure if it's temporary reset following the update or a glitch on AssetStore but it's certain not my intention. I'll check with AssetStore team and try to resolve it.

    Sorry for all the inconvenience.
     
  27. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Normal service has been resumed. The package is now back to 50% discount at $10!
     
  28. franticnick

    franticnick

    Joined:
    Jun 1, 2012
    Posts:
    2
    Thanks. Just bought it :)
     
  29. simone007

    simone007

    Joined:
    Oct 30, 2008
    Posts:
    221
    On Suggestions: could you possibly include mousewheel detection?

    In my game I need it to developm a Zoom-in/Zoom-out movement in both iOS (Pinch) and PC (MouseWheel) environments.
     
  30. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Mouse-wheel detection is very simple really. By default, it's just a one liner.

    Code (csharp):
    1. Input.GetAxis("Mouse ScrollWheel");
    The function call returns a value which can be used as zoom direction/speed. The simplicity is the reason why I didn't include it in the package. I thought it would be counter intuitive to use an event system to do something that can be achievable by 1 line of code.

    But should you wish, I'm happy to add the functionality for you. Let me know.
     
  31. parkerdc

    parkerdc

    Joined:
    Aug 2, 2011
    Posts:
    10
    I got the swipe to work perfectly and I have 100 objects and how do I add the single tap to each one?

    BTW: The link in your documentation goes to blog that does not work.
     
    Last edited: Jun 3, 2012
  32. kicki2k

    kicki2k

    Joined:
    May 16, 2012
    Posts:
    5
    hi, song

    The last time that there was a bug in your inputtouches.
    But it was misleading.
    My Android devices in this version of the kernel has been updated.
    Certainly the problem was the kernel version of Android devices.
    Version 0.9 still being inputtouches normally RTSCam / OrbitCam the rotation of the works.
    I'm sorry.
    your Inputtouches is simple and perfect!.
     
    Last edited: Jun 3, 2012
  33. helioxfilm

    helioxfilm

    Joined:
    Apr 23, 2008
    Posts:
    259
    Dooes this solution do more than FingerGestures?
     
  34. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @parkerdc,
    I'm not really sure what are you really trying to do. Could you please elaborate more? Perhaps you can send me a pm or email.


    @kicki2k, Thanks for the clarification. Glad it works fine.


    @helioxfilm, That I wouldnt say. Honestly I'm not sure what's FingerGestures is fully capable of. But from what I know, FingerGestures seems to be a more comprehensible and and better established package. But of course it cost more.
     
  35. Aranir

    Aranir

    Joined:
    May 23, 2011
    Posts:
    16
    Exactly the same question I have, as I already bought finger gestures I am a little hesitant.

    Somehow I have problems exporting my project when I use finger gestures, does your product work well with the flash export?
     
  36. albertwang

    albertwang

    Joined:
    Feb 21, 2012
    Posts:
    12
    hi song,

    Just bought the plugin, nice work and it's easy to use.

    When I was trying it, I guess I found there might be a little mistake in the code which would cause some problem in rotation, when I look into dualfingerdetector.cs, in the Update() function:


    Shouldn't it be

    as I guess you intend to initialize the member variable instead of creating another temp one....


    Let me know if it's the case or not, thanks!
     
  37. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @aranir, I've just ran a very quick test (out from usual work place this few days, dont have my usual setup). it seem unity flash doesn't like the c# event system and give me a bunch of errors. Which is strange considered I've other project that works just fine. So unfortunately I'll have to say at least for now, that Input.Touches is not compatible with unity flash.

    @albert, you are absolutely right. Thanks a bunch for pointing that out! I'll remedy that in an update asap.
     
  38. dasbin

    dasbin

    Joined:
    Jan 14, 2012
    Posts:
    261
    Hi,

    I bought your asset, very useful and nice code, thanks!

    What I really wanted to use it for, though, is a type of swipe-detection that doesn't seem to be supported. I was wondering if it might be possible to walk me through a small modification of the swipe algorithm so it does the following.

    I am trying to detect a swipe that doesn't necessarily begin with a unique finger-down. In other words, the player controls an on-screen touch joystick like normal, but every now and then will also add a fast "swipe" motion across the screen *without* having lifted the finger from the joystick. He might even chain together multiple fast swipes across the screen without ever lifting the finger. It is really just a distance and speed detection I am looking for. (ie: if speed > x distance > y, then swipe=true). Don't even care about reading any of the normal variables off the swipe, just want to know that it happened at all.
    As it is now, your swipe detection can only happen once and seemingly requires a unique touch at the start and a lift at the end.

    Any ideas on how to make this work?

    Thanks very much, and sorry for the hassle.
     
  39. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Thanks for your custom and your kind word. yours is an interesting suggestion. Please give me sometime and I'll see if there's anything I can do. Please understand that this might take a few days as I have other commitment that I must attend to first. But I promise I'll look into it. Thanks for understanding. :)
     
  40. konoha

    konoha

    Joined:
    Jun 12, 2012
    Posts:
    1
    Hi, song

    I think that onSwipeE() happens to 2 times only once.

    SwipeDetector.cs (line 115)
    if(swipeState==_SwipeState.None){

    The second time, swipeState value is _SwipeState.End .

    Thank you.
     
    Last edited: Jun 12, 2012
  41. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I'm not sure what exactly you are trying to point out but I've just checked, swipe detection logic is working fine at the moment.

    I'm however in the middle of the process of reviewing the code to integrate the swipe input dashbin suggested. When that is done, that would be the time when next update is out. Most of the code may well be reworked by then.
     
  42. dasbin

    dasbin

    Joined:
    Jan 14, 2012
    Posts:
    261
    Thanks so much, songtan.
     
  43. S37H

    S37H

    Joined:
    Apr 1, 2012
    Posts:
    25
    Hi Songtan! This package is great! I was wondering if there's a possibility of support for the two finger tap, two finger double tap, and two finger charge with the mouse buttons? I'm using this for a PC game and could benefit a lot from that functionality. Or if you suggest a method of doing so with the current package instead that would be great as well.

    Thanks!
     
  44. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @Frip, Thanks for using the library. I've sent a pm your way.
     
  45. Anxox

    Anxox

    Joined:
    Oct 29, 2011
    Posts:
    30
    Hi Sogtan,

    First off, thanks for the tool. Easy to use, nice job. I am having a bit of an issue with the swipe gestures. It works fine on the first swipe but if you continuously swipe left and right, Sometimes it misses some. Why would that be? If I swipe 10 times right with a Debug.Log, Its only called 7 times.

    Is there some kind of yield return new Wait, that is holding it back or some condition that would cause some of the calls to happen but not others? I see the problem in the editor and thought it might be the mouse but when I launched it in the iPhone I am having the same issue.

    I need to be able to swipe back to back and have every swipe angle counted. Thank you in advance Songtan.
     
  46. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Thanks for pointing that out. I'm well aware of the issue, I'm working on a fix on that. It should be fixed in the next update.
     
  47. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
    I can't manage to get OnTouchDown and OnTouchUp working, I get this error

    Operator '-' cannot be used with a left hand side of type 'function(UnityEngine.Vector2): void' and a right hand side of type 'function(UnityEngine.Vector2): void'.

    and

    Operator '+' cannot be used with a left hand side of type 'function(UnityEngine.Vector2): void' and a right hand side of type 'function(UnityEngine.Vector2): void'.

    here is my script

    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. var rightButton : GameObject;
    5. var leftButton : GameObject;
    6.  
    7. static var direction : int = 0;
    8. static var jump : int = 0;
    9.  
    10.  
    11. function OnEnable(){
    12.     Gesture.OnTouchDown += onTouchDown;
    13.     Gesture.OnTouchUp += onTouchUp;
    14.     Gesture.onSwipeE += OnSwipe;
    15. }
    16.  
    17. function OnDisable(){
    18.     Gesture.OnTouchDown -= onTouchDown;
    19.     Gesture.OnTouchUp -= onTouchUp;
    20.     Gesture.onSwipeE -= OnSwipe;
    21. }
    22.  
    23. function OnSwipe(sw : SwipeInfo){
    24.     Debug.Log("Swipe Angle: " + sw.angle.ToString());
    25.     if(sw.angle != 0){
    26.         jump = 1;
    27.     }
    28. }
    29.  
    30. function onTouchDown(pos : Vector2){
    31.     var ray : Ray = Camera.main.ScreenPointToRay(pos);
    32.     var hit : RaycastHit;
    33.     if(Physics.Raycast(ray, hit, Mathf.Infinity)){
    34.         if(hit.collider.transform == rightButton){
    35.             direction = 1;
    36.         }
    37.        
    38.         if(hit.collider.transform == leftButton){
    39.             direction = -1;
    40.         }
    41.     }
    42. }
    43.  
    44. function onTouchUp(pos : Vector2){
    45.    
    46. }
    47.  
     
  48. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Just some spelling error, should have been:

    Code (csharp):
    1.  
    2. function OnEnable(){
    3.     Gesture.onTouchDownE += onTouchDown;
    4.     Gesture.onTouchUpE += onTouchUp;
    5.     Gesture.onSwipeE += OnSwipe;
    6. }
    7.  
    8. function OnDisable(){
    9.     Gesture.onTouchDownE -= onTouchDown;
    10.     Gesture.onTouchUpE -= onTouchUp;
    11.     Gesture.onSwipeE -= OnSwipe;
    12. }
    13.  
    please note it's onTouchDownE, not OnTouchDown. The same goes for another error onTouchUpE.


    Also in your code

    Code (csharp):
    1.  
    2. if(hit.collider.transform == rightButton){
    3.  
    you are comparing transform against gameObject since rightButton is declared as gameObject. It should have been:

    Code (csharp):
    1.  
    2. if(hit.collider.gameObject == rightButton){
    3.  
     
    Last edited: Jun 15, 2012
  49. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
    Tahnk you. I'll try your code but I follow your documentation and:

    public static event Action<Vetor2> onTouchDown
    - fired when a touch first initiated. The screen position where the touch occurs is passed. Multiple instances of this event can be fired simultaneously if there are more than 1 touch on screen.
     
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Ops my bad. >.< It seems like there are spelling errors in my documentation. Thanks for pointing that out.