Search Unity

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,993
    Can you be more specific? Do you want the scene as it's? There's a sphere in the swipe demo and a trail when user swipe, which one you are refering to as the indicator? And do you need a metric value of the location on screen or...?

    I'm afraid you will have to direct that question to the playmaker team as I myself is not familiar with it. Actually they have just asked me for an update so they can incoporate all the feature of InputTouches. So if anything is missing, an update is probably on the way to fix that.
     
  2. gamedivision

    gamedivision

    Joined:
    Nov 4, 2012
    Posts:
    47
    I can use a get property and set property in playmaker that lets me store variables,game objects,ect from exposed variables and game objects in the inspector,none of the touch events are exposed, you have swipe and tap but not touch position,so if I hold my finger down on the screen that type of event
     
  3. johnny12345

    johnny12345

    Joined:
    Oct 8, 2012
    Posts:
    45
    so can you expose these or not,all im after is the finger position on the screen
     
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yes you can get the finger position on screen as long as there's one on screen regardless of swipe and tap event. It's an event of it's own that should fire along with swipe and tap event.. From what I can gather from PlayerMaker support website, the particular event should be "INPUT TOUCHES / ON". I hope this is helpful enough.
     
  5. gamedivision

    gamedivision

    Joined:
    Nov 4, 2012
    Posts:
    47
    I can only access the INPUT TOUCHES / ON event not the actual position thanks anyway
     
  6. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm afraid you have to address the question to the PlayMaker team. Although I can show you how to get the information via code, I really have no idea how PlayMaker operates and how to get the information from the event. Sorry for being noe much help here.
     
  7. Hrvatss

    Hrvatss

    Joined:
    Oct 26, 2012
    Posts:
    9
    does it suppport android devices?
     
  8. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    It should. As long as the device is supported by unity.
     
  9. gamedivision

    gamedivision

    Joined:
    Nov 4, 2012
    Posts:
    47
    Sorted thanks,it's because I needed to call a global event INPUT TOUCHES/ON then use the get position and store it in a vector2 :D
     
  10. meta87

    meta87

    Joined:
    Dec 31, 2012
    Posts:
    254
    I recently bought your component and am excited to get it working. I looked through your help and demos, but couldn't grasp how to implement something pretty simple. I'm using your DPad demo as reference. When I touch left arrow, I set a MoveDirection variable to -1. I want the MoveDirection variable to get set back to zero when the touch is over.

    In the PDF doc I see you mention While Touching and While Mouse but I don't see any reference to what the code is for that. I tried onWhileTouchE. If you could let me know that would be great! Thanks. (I'm using javascript)
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for the slow respond.

    I'm not sure where you read it but there's only onTouchE or onMouseE, not onWhileTouchE. And yes, both onTouchE and onMouseE will be fired every frame as long as the finger/mouse-button is held down. As in DPad demo, the event calls a function which set the appropriate direction and subsequently move the transform base on the direction.

    If you are looking for event which fired when the touch is ended, you are looking for onTouchUpE. Which will be fired when a touch is lifted. Hope this help.
     
  12. meta87

    meta87

    Joined:
    Dec 31, 2012
    Posts:
    254
    Thanks for the response. Your utility is working great! Can you answer another dumb question?

    In one your demos, you have a guitexture and use hittest to tell when it is touched. How would you do the same thing for a gameobject? So I want to test if a gameobject has been touched. Thanks!
     
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    There are plenty of example of detecting hit on gameObject in TapDemo.cs.

    Basically what you need to do is do a raycast using the position of the event. Please let me know if you need further explaination.
     
  14. Huffmann1

    Huffmann1

    Joined:
    Jan 29, 2013
    Posts:
    4
    Hello Songtan,

    I just recently bought your library and it looks like It will be very useful for my projects.

    I'v been trying to setup a simple Tap situation very similar to the TapDemo, but instead of MultiTap I am Using Either onTouchE or onTouchDownE:


    function OnEnable(){

    Gesture.onTouchE += OnTouch;

    }

    function OnTouch(pos:Vector2){

    var ray:Ray = Camera.main.ScreenPointToRay)(pos);
    var hit:RaycastHit;
    if(Physics.Raycast(ray, hit, Mathf.Infinity)){

    if(hit.collider.transform==TapObj){

    Next();

    }

    }


    I as I click or touch the TapObj I Get no response at all.


    Thanks for your help!
     
    Last edited: Jan 29, 2013
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for your purchase!

    From what I can gather, the issue is that you are using onTouch and trying to detech a mouse click. While onMouse can work for touch control (not in a very consistent manner), onTouch is designated for touch control only, it wont respond to mouse click. onTouch and onMouse is there for you to detect a raw mouse/touch input. If you want an event that could handle both mouse and touch input, you will need to resort of tap event.

    Also some minor note, there's a small error in the ray construction line. I suppose it's a typo but there's an addition ')' there. Finally make sure you are comparing the hit transform to a transform type. If tapObj is a gameObject, you will never be able to get a match.
     
  16. milox777

    milox777

    Joined:
    Sep 23, 2012
    Posts:
    195
    Is drag/swipe to look type of camera can be easily implemented with this? I mean something like you drag your finger on the right side of the screen, if you drag left or right the character rotates and camera follows him, and when you drag up down only camera rotates up and down and it has it''s movement clamped with specific angle values. I'm looking for something like this: https://www.youtube.com/watch?v=PRW01ygkmuE
     
  17. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    It's hard to say how easy or hard it's as it's very much relative to everyone knowledge of the code and mechanic. But it's what you need is certainly doable. In fact there are separate examples that do each of the individual function, one for the left-screen d-pad movement, and the other one for the right-screen camera angle rotation. It's not exactly like how it's in the video but with some modification it can do just that.
     
  18. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Hey there, i am interested in this plugin.

    - is there kind of a Documentation (Website, PDF, etc.) ?
    - Does it support PlayMaker?
     
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for your interest.

    There is a PDF file within the package with explanation of all the gesture supported, as well as their corresponding event and variables. All the examples in the demo is also included, along with commented scripts.

    As far as I know PlayMaker does support it. However I couldnt comment on how well it does that as I've no experience with PlayMaker. You can find more details in this link.
     
  20. HH_Gorgon

    HH_Gorgon

    Joined:
    Nov 8, 2012
    Posts:
    8
    Does this asset work with 3.5.6 or is it 4.0+ only? If we were to use it with 3.5.6 would you be able to offer any support?
     
  21. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    It should work with both Unity3 and Unity4. Just not flash.
     
  22. Mixality_KrankyBoy

    Mixality_KrankyBoy

    Joined:
    Mar 27, 2009
    Posts:
    737
    Enjoying the API, however I have an issue. We need to be able to do a standard drag on an item (working fine), but if/when the user taps the screen WHILE dragging the object we want the object to rotate. This is sort of working. By checking for a DRAG and Checking for the number of touches to = 2 we get it to rotate (we call that method that rotates the object) HOWEVER the second tap/touch ALWAYS ends the drag event!!! We do not want this, we want the user to be able to pick an object up, rotate it as needed, THEN drop it down by releasing the drag.....make sense?

    Any ideas? Bug in API? Bug in Unity? touch limitation?
     
  23. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    From your description it sounds like you are need to track 2 independant drag event simulataneously. Number of touch is not a good way to check if there's a second drag event. Instead, you should use the index of each dragInfo. Fyi, each drag event will be given a unique index, that is what you should use to track multiple indepandent drag event. You can refer to the example script TapDemo.cs to see how this is donw.

    As for why the the second touch ends an on-going drag event, I've never encounter this problem myself. The multi-drag mechanic in the TapDemo works just fine last time I test it so there should be nothing wrong with it. The only thing I can think of is that have you disable the "EnableMultiDrag" flag in DragDetector? Make sure it's enable or the any drag event will terminate as soon as there are more than 1 finger touching the screen.
     
  24. Mixality_KrankyBoy

    Mixality_KrankyBoy

    Joined:
    Mar 27, 2009
    Posts:
    737
    ""EnableMultiDrag" flag in DragDetector" - yep that was it. Though I think it is disabled by default as I never even noticed that option. Thanks it is working now.
     
  25. HH_Gorgon

    HH_Gorgon

    Joined:
    Nov 8, 2012
    Posts:
    8
    Hello, I have been trying to get the multi-touch drag working for the RTS camera, but have been having issues with the touch version working on Android(the pc mouse version worked great). I went back to the source and pushed your RTS demo scene to my device, and it was not working there either. After some debugging I found the following issue in DragDetector.cs:

    if(moving){
    for(int i=0; i<count-1; i++){
    Vector2 v1=Input.touches.deltaPosition.normalized;
    Vector2 v2=Input.touches[i+1].deltaPosition.normalized;
    normalizedSyncDif = Vector2.Dot(v1, v2);//my added debug code
    if(Vector2.Dot(v1, v2)<0.85f) sync=false;
    }
    }

    Basically my added float debug showed me that the Dot was always returning 0, making the sync always false. This causes all of the multiple finger drag events (ie, OnMFDragging) to be skipped.

    Any thoughts on the best solution?

    Edit: Looking into this further, it seems that the v1 vector for touch 0 is almost always returning 0,0. The other value looks like it is reporting properly
     
    Last edited: Feb 26, 2013
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm not really sure why. I did a bit of digging and the reason the value of vector1 is consistently zero could be your device doesnt support multi-touch. Can you please use following code to check if your device can read multiple-touch. You should be able to see all touches giving you meaningful reading when you have multiple finger on screen.

    Code (csharp):
    1.  
    2.         string text1="";
    3.         string text2="";
    4.         for(int i=0; i<Input.touchCount; i++){
    5.             text1+="touch"+i+" pos: "+Input.touches[i].position+"     ";
    6.             text2+="touch"+i+" delta: "+Input.touches[i].deltaPosition+"     ";
    7.         }
    8.         Debug.Log(text1);
    9.         Debug.Log(text2);
    10.  
     
  27. HH_Gorgon

    HH_Gorgon

    Joined:
    Nov 8, 2012
    Posts:
    8
    Thanks for looking into this further. It seems that it is an issue between my device (Samsung GT-P7510MA) and Unity. For whatever reason, it is not reporting the Input.touches[0].deltaPosition properly, but all the other multitouch data I looked at was present. I wrote a quick workaround that generated new deltas from the Input.touches[].position data (storing the previous frame's information, etc) and it is working great now.
     
  28. larryapple

    larryapple

    Joined:
    Mar 1, 2013
    Posts:
    7
    Hi, I just purchased Input.Touches and it has a name conflict with my Tasharen Network example code. It seems the name "Target" is a little bit too commonly used.
     
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for your purchase and thanks for letting me know. No surprise that everyone uses Target as class or variable name. It's not a big issue tho. You can fix the problem by changing the name of the script from Target.cs and Target.js to something else, like DemoTarget or InputTouchesTarget. Also you will need to change the name in line5 in Target.cs to fit your name. That's pretty much it.
     
  30. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    It'd be nice if when you did this:

    Gesture.onSomething +=

    It checked to see if the right script has been added to a "Gesture" gameObject so we can do everything from code.
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Fyi, all the gesture detection scripts are by default required by Gesture.cs. So all the right script is there, it's a matter of if they are enabled or disabled. The gesture script doesnt enabled or disable any of those in run time. It expect this is been fixed upon the scene starting. So if the scripts are enabled or disabled by run time, it's by a third party code event. Hence I dont see how I can create an event to listen to and relay another possible event that I dont know the source. Sure I could do so by polling method, but it's generally very inefficient and pointless for most user.

    Not sure if I get the right idea. If I have misunderstand your comment, please let me know.
     
  32. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    Here's how I'd achieve something like this, obviosuly there is more work involved in actually making the scripts not depend on each other (if they do).

    Code (csharp):
    1.  
    2.  
    3.  
    4.     public delegate void SwipeHandler(SwipeInfo sw);
    5.    
    6.     static Gesture instance;
    7.    
    8.     public static Gesture Instance
    9.     {
    10.         get
    11.         {
    12.             if (instance == null)
    13.             {
    14.                 instance = (Gesture) FindObjectOfType(typeof(Gesture));
    15.             }
    16.            
    17.             if (instance == null)
    18.             {
    19.                 instance = (Gesture) new GameObject("Gesture").AddComponent<Gesture>();
    20.             }
    21.            
    22.             return instance;
    23.            
    24.         }
    25.     }
    26.    
    27.    
    28.     static event SwipeHandler _onSwipeE;
    29.    
    30.     static bool swipeSetup = false;
    31.    
    32.     static void SetupSwipe()
    33.     {
    34.         if (!swipeSetup)
    35.         {
    36.             Gesture.Instance.gameObject.AddComponent<SwipeDetector>();
    37.             swipeSetup = true;
    38.         }
    39.     }
    40.    
    41.     static void DestroySwipe()
    42.     {
    43.         GameObject.Destroy(Gesture.Instance.gameObject.GetComponent<SwipeDetector>());
    44.         swipeSetup = false;
    45.     }
    46.    
    47.     public static event SwipeHandler onSwipeE
    48.     {
    49.        
    50.         add {
    51.            
    52.             SetupSwipe();
    53.            
    54.              _onSwipeE += value;
    55.            
    56.         }
    57.        
    58.         remove
    59.         {
    60.            
    61.              _onSwipeE -= value;
    62.    
    63.             if (_onSwipeE == null)
    64.             {
    65.                 DestroySwipe();
    66.             }
    67.            
    68.         }
    69.        
    70.     }
    71.  
     
    Last edited: Mar 2, 2013
  33. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    Ok the swipe one seemed to work with the code change, I just had to remove the require component stuff and change the event caller to this:

    Code (csharp):
    1. public static void Swipe(SwipeInfo sw){
    2.         if (_onSwipeE != null) { _onSwipeE(sw); }
    3.     }
    I didn't add any gesture or swipedetector components and it works just by doing:

    Code (csharp):
    1. Gesture.onSwipeE += delegate(SwipeInfo sw) {           
    2.             Debug.Log ("TEST");
    3.            
    4. } ;
    It does seem like a fair bit of work for very little gain so it's probably not worth it but I think I'll convert it all over if you don't think it's worth the hassle.

    I think I like prime31's UITookit style too much, I love being able to do everything from code without setting up stuff in the inspector.
     
    Last edited: Mar 2, 2013
  34. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    That's interesting. To be honest I dont know that this is possible. Thanks for the tip.

    However I dont think it's nessacery. The thing is there are certain parameter that is configurable on each of the script component. I think it's more intuitive to let them be visible in the inspector all time.
     
  35. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    Fair call, the only benefit would be a small performance boost for the detectors that don't get used so it's not going to affect many people.

    I'll make the changes and send you a copy in case you ever decide to go that way.
     
  36. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks alot in advance!
     
  37. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    Here's what I'm using, I haven't tested all the events but the ones I'm using seem to work well enough and the code is pretty straight forward.

    The only requirement is to remove the "Required Component" bits from Gesture.cs

    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5. using System.Collections.Generic;
    6.  
    7.  
    8. public static class GestureEx {
    9.  
    10.  
    11.     static Gesture instance;
    12.     static Dictionary<System.Type,List<object>> components = new Dictionary<System.Type,List<object>>();
    13.    
    14.     public static Gesture Instance
    15.     {
    16.         get
    17.         {
    18.             if (instance == null)
    19.             {
    20.                 instance = (Gesture) GameObject.FindObjectOfType(typeof(Gesture));
    21.             }
    22.            
    23.             if (instance == null)
    24.             {
    25.                 instance = (Gesture) new GameObject("Gesture").AddComponent<Gesture>();
    26.             }
    27.            
    28.             return instance;
    29.            
    30.         }
    31.     }
    32.    
    33.     static void Add<T>(object func)
    34.     {
    35.        
    36.         if (!components.ContainsKey(typeof(T)))
    37.         {
    38.            
    39.             components.Add(typeof(T),new List<object>());
    40.    
    41.             components[typeof(T)].Add(func);
    42.            
    43.             Instance.gameObject.AddComponent(typeof(T));
    44.        
    45.         }
    46.         else
    47.         {
    48.            
    49.             components[typeof(T)].Add(func);
    50.            
    51.         }
    52.        
    53.     }
    54.    
    55.     static void Remove<T>(object func)
    56.     {
    57.        
    58.         if (components.ContainsKey(typeof(T)))
    59.         {
    60.            
    61.             if (components[typeof(T)].Contains(func))
    62.             {
    63.                 components[typeof(T)].Remove(func);
    64.             }
    65.             else
    66.             {
    67.                
    68.                 for (int x = components[typeof(T)].Count-1; x >= 0; x --)
    69.                 {
    70.                    
    71.                     if (components[typeof(T)][x] == null)
    72.                     {
    73.                        
    74.                         components[typeof(T)].RemoveAt(x);
    75.                    
    76.                     }  
    77.                    
    78.                 }
    79.                
    80.             }
    81.            
    82.             if (components[typeof(T)].Count == 0)
    83.             {
    84.                
    85.                 GameObject.Destroy(Instance.gameObject.GetComponent(typeof(T)));
    86.                
    87.             }
    88.            
    89.         }
    90.        
    91.     }
    92.    
    93.     public static event Gesture.SwipingHandler onSwipingE
    94.     {
    95.        
    96.         add {
    97.            
    98.             Add<SwipeDetector>(value);
    99.            
    100.             Gesture.onSwipingE += value;
    101.            
    102.         }
    103.        
    104.         remove
    105.         {
    106.            
    107.             Remove<SwipeDetector>(value);
    108.            
    109.             Gesture.onSwipingE -= value;
    110.    
    111.         }
    112.        
    113.     }
    114.    
    115.     public static event Gesture.SwipeStartHandler onSwipeStartE
    116.     {
    117.        
    118.         add {
    119.            
    120.             Add<SwipeDetector>(value);
    121.            
    122.             Gesture.onSwipeStartE += value;
    123.            
    124.         }
    125.        
    126.         remove
    127.         {
    128.            
    129.             Remove<SwipeDetector>(value);
    130.            
    131.             Gesture.onSwipeStartE -= value;
    132.    
    133.         }
    134.        
    135.     }
    136.            
    137.     public static event Gesture.SwipeEndHandler onSwipeEndE
    138.     {
    139.        
    140.         add {
    141.            
    142.             Add<SwipeDetector>(value);
    143.            
    144.             Gesture.onSwipeEndE += value;
    145.            
    146.         }
    147.        
    148.         remove
    149.         {
    150.            
    151.             Remove<SwipeDetector>(value);
    152.            
    153.             Gesture.onSwipeEndE -= value;
    154.    
    155.         }
    156.        
    157.     }
    158.    
    159.     public static event Gesture.MultiTapHandler onMultiTapE
    160.     {
    161.        
    162.         add {
    163.            
    164.             Add<TapDetector>(value);
    165.            
    166.             Gesture.onMultiTapE += value;
    167.            
    168.         }
    169.        
    170.         remove
    171.         {
    172.            
    173.             Remove<TapDetector>(value);
    174.            
    175.             Gesture.onMultiTapE -= value;
    176.    
    177.         }
    178.        
    179.     }
    180.    
    181.     public static event Gesture.LongTapHandler onLongTapE
    182.     {
    183.        
    184.         add {
    185.            
    186.             Add<TapDetector>(value);
    187.            
    188.             Gesture.onLongTapE += value;
    189.            
    190.         }
    191.        
    192.         remove
    193.         {
    194.            
    195.             Remove<TapDetector>(value);
    196.            
    197.             Gesture.onLongTapE -= value;
    198.    
    199.         }
    200.        
    201.     }
    202.    
    203.     public static event Gesture.ChargeStartHandler onChargeStartE
    204.     {
    205.        
    206.         add {
    207.            
    208.             Add<TapDetector>(value);
    209.            
    210.             Gesture.onChargeStartE += value;
    211.            
    212.         }
    213.        
    214.         remove
    215.         {
    216.            
    217.             Remove<TapDetector>(value);
    218.            
    219.             Gesture.onChargeStartE -= value;
    220.    
    221.         }
    222.        
    223.     }
    224.    
    225.     public static event Gesture.ChargingHandler onChargingE
    226.     {
    227.        
    228.         add {
    229.            
    230.             Add<TapDetector>(value);
    231.            
    232.             Gesture.onChargingE += value;
    233.            
    234.         }
    235.        
    236.         remove
    237.         {
    238.            
    239.             Remove<TapDetector>(value);
    240.            
    241.             Gesture.onChargingE -= value;
    242.    
    243.         }
    244.        
    245.     }
    246.    
    247.     public static event Gesture.ChargeEndHandler onChargeEndE
    248.     {
    249.        
    250.         add {
    251.            
    252.             Add<TapDetector>(value);
    253.            
    254.             Gesture.onChargeEndE += value;
    255.            
    256.         }
    257.        
    258.         remove
    259.         {
    260.            
    261.             Remove<TapDetector>(value);
    262.            
    263.             Gesture.onChargeEndE -= value;
    264.    
    265.         }
    266.        
    267.     }
    268.    
    269.    
    270.     public static event Gesture.MFMultiTapHandler onMFMultiTapE
    271.     {
    272.        
    273.         add {
    274.            
    275.             Add<TapDetector>(value);
    276.            
    277.             Gesture.onMFMultiTapE += value;
    278.            
    279.         }
    280.        
    281.         remove
    282.         {
    283.            
    284.             Remove<TapDetector>(value);
    285.            
    286.             Gesture.onMFMultiTapE -= value;
    287.    
    288.         }
    289.        
    290.     }
    291.    
    292.     public static event Gesture.MFLongTapHandler onMFLongTapE
    293.     {
    294.        
    295.         add {
    296.            
    297.             Add<TapDetector>(value);
    298.            
    299.             Gesture.onMFLongTapE += value;
    300.            
    301.         }
    302.        
    303.         remove
    304.         {
    305.            
    306.             Remove<TapDetector>(value);
    307.            
    308.             Gesture.onMFLongTapE -= value;
    309.    
    310.         }
    311.        
    312.     }
    313.    
    314.     public static event Gesture.MFChargeStartHandler onMFChargeStartE
    315.     {
    316.        
    317.         add {
    318.            
    319.             Add<TapDetector>(value);
    320.            
    321.             Gesture.onMFChargeStartE += value;
    322.            
    323.         }
    324.        
    325.         remove
    326.         {
    327.            
    328.             Remove<TapDetector>(value);
    329.            
    330.             Gesture.onMFChargeStartE -= value;
    331.    
    332.         }
    333.        
    334.     }
    335.    
    336.     public static event Gesture.MFChargingHandler onMFChargingE
    337.     {
    338.        
    339.         add {
    340.            
    341.             Add<TapDetector>(value);
    342.            
    343.             Gesture.onMFChargingE += value;
    344.            
    345.         }
    346.        
    347.         remove
    348.         {
    349.            
    350.             Remove<TapDetector>(value);
    351.            
    352.             Gesture.onMFChargingE -= value;
    353.    
    354.         }
    355.        
    356.     }
    357.    
    358.     public static event Gesture.MFChargeEndHandler onMFChargeEndE
    359.     {
    360.        
    361.         add {
    362.            
    363.             Add<TapDetector>(value);
    364.            
    365.             Gesture.onMFChargeEndE += value;
    366.            
    367.         }
    368.        
    369.         remove
    370.         {
    371.            
    372.             Remove<TapDetector>(value);
    373.            
    374.             Gesture.onMFChargeEndE -= value;
    375.    
    376.         }
    377.        
    378.     }
    379.    
    380.     public static event Gesture.DraggingStartHandler onDraggingStartE
    381.     {
    382.        
    383.         add {
    384.            
    385.             Add<DragDetector>(value);
    386.            
    387.             Gesture.onDraggingStartE += value;
    388.            
    389.         }
    390.        
    391.         remove
    392.         {
    393.            
    394.             Remove<DragDetector>(value);
    395.            
    396.             Gesture.onDraggingStartE -= value;
    397.    
    398.         }
    399.        
    400.     }
    401.    
    402.     public static event Gesture.DraggingHandler onDraggingE
    403.     {
    404.        
    405.         add {
    406.            
    407.             Add<DragDetector>(value);
    408.            
    409.             Gesture.onDraggingE += value;
    410.            
    411.         }
    412.        
    413.         remove
    414.         {
    415.            
    416.             Remove<DragDetector>(value);
    417.            
    418.             Gesture.onDraggingE -= value;
    419.    
    420.         }
    421.        
    422.     }
    423.    
    424.     public static event Gesture.DraggingEndHandler onDraggingEndE
    425.     {
    426.        
    427.         add {
    428.            
    429.             Add<DragDetector>(value);
    430.            
    431.             Gesture.onDraggingEndE += value;
    432.            
    433.         }
    434.        
    435.         remove
    436.         {
    437.            
    438.             Remove<DragDetector>(value);
    439.            
    440.             Gesture.onDraggingEndE -= value;
    441.    
    442.         }
    443.        
    444.     }
    445.    
    446.     public static event Gesture.MFDraggingStartHandler onMFDraggingStartE
    447.     {
    448.        
    449.         add {
    450.            
    451.             Add<DragDetector>(value);
    452.            
    453.             Gesture.onMFDraggingStartE += value;
    454.            
    455.         }
    456.        
    457.         remove
    458.         {
    459.            
    460.             Remove<DragDetector>(value);
    461.            
    462.             Gesture.onMFDraggingStartE -= value;
    463.    
    464.         }
    465.        
    466.     }
    467.    
    468.     public static event Gesture.MFDraggingHandler onMFDraggingE
    469.     {
    470.        
    471.         add {
    472.            
    473.             Add<DragDetector>(value);
    474.            
    475.             Gesture.onMFDraggingE += value;
    476.            
    477.         }
    478.        
    479.         remove
    480.         {
    481.            
    482.             Remove<DragDetector>(value);
    483.            
    484.             Gesture.onMFDraggingE -= value;
    485.    
    486.         }
    487.        
    488.     }
    489.    
    490.     public static event Gesture.MFDraggingEndHandler onMFDraggingEndE
    491.     {
    492.        
    493.         add {
    494.            
    495.             Add<DragDetector>(value);
    496.            
    497.             Gesture.onMFDraggingEndE += value;
    498.            
    499.         }
    500.        
    501.         remove
    502.         {
    503.            
    504.             Remove<DragDetector>(value);
    505.            
    506.             Gesture.onMFDraggingEndE -= value;
    507.    
    508.         }
    509.        
    510.     }
    511.    
    512.     public static event Gesture.PinchHandler onPinchE
    513.     {
    514.        
    515.         add {
    516.            
    517.             Add<DualFingerDetector>(value);
    518.            
    519.             Gesture.onPinchE += value;
    520.            
    521.         }
    522.        
    523.         remove
    524.         {
    525.            
    526.             Remove<DualFingerDetector>(value);
    527.            
    528.             Gesture.onPinchE -= value;
    529.    
    530.         }
    531.        
    532.     }
    533.    
    534.     public static event Gesture.RotateHandler onRotateE
    535.     {
    536.        
    537.         add {
    538.            
    539.             Add<DualFingerDetector>(value);
    540.            
    541.             Gesture.onRotateE += value;
    542.            
    543.         }
    544.        
    545.         remove
    546.         {
    547.            
    548.             Remove<DualFingerDetector>(value);
    549.            
    550.             Gesture.onRotateE -= value;
    551.    
    552.         }
    553.        
    554.     }
    555.    
    556.     public static event Gesture.TouchDownHandler onTouchDownE
    557.     {
    558.        
    559.         add {
    560.            
    561.             Add<BasicDetector>(value);
    562.            
    563.             Gesture.onTouchDownE += value;
    564.            
    565.         }
    566.        
    567.         remove
    568.         {
    569.            
    570.             Remove<BasicDetector>(value);
    571.            
    572.             Gesture.onTouchDownE -= value;
    573.    
    574.         }
    575.        
    576.     }
    577.    
    578.     public static event Gesture.TouchUpHandler onTouchUpE
    579.     {
    580.        
    581.         add {
    582.            
    583.             Add<BasicDetector>(value);
    584.            
    585.             Gesture.onTouchUpE += value;
    586.            
    587.         }
    588.        
    589.         remove
    590.         {
    591.            
    592.             Remove<BasicDetector>(value);
    593.            
    594.             Gesture.onTouchUpE -= value;
    595.    
    596.         }
    597.        
    598.     }
    599.    
    600.     public static event Gesture.TouchHandler onTouchE
    601.     {
    602.        
    603.         add {
    604.            
    605.             Add<BasicDetector>(value);
    606.            
    607.             Gesture.onTouchE += value;
    608.            
    609.         }
    610.        
    611.         remove
    612.         {
    613.            
    614.             Remove<BasicDetector>(value);
    615.            
    616.             Gesture.onTouchE -= value;
    617.    
    618.         }
    619.        
    620.     }
    621.  
    622.  
    623.    
    624.     public static event Gesture.Mouse1DownHandler onMouse1DownE
    625.     {
    626.        
    627.         add {
    628.            
    629.             Add<BasicDetector>(value);
    630.            
    631.             Gesture.onMouse1DownE += value;
    632.            
    633.         }
    634.        
    635.         remove
    636.         {
    637.            
    638.             Remove<BasicDetector>(value);
    639.            
    640.             Gesture.onMouse1DownE -= value;
    641.    
    642.         }
    643.        
    644.     }
    645.    
    646.     public static event Gesture.Mouse1UpHandler onMouse1UpE
    647.     {
    648.        
    649.         add {
    650.            
    651.             Add<BasicDetector>(value);
    652.            
    653.             Gesture.onMouse1UpE += value;
    654.            
    655.         }
    656.        
    657.         remove
    658.         {
    659.            
    660.             Remove<BasicDetector>(value);
    661.            
    662.             Gesture.onMouse1UpE -= value;
    663.    
    664.         }
    665.        
    666.     }
    667.    
    668.     public static event Gesture.Mouse1Handler onMouse1E
    669.     {
    670.        
    671.         add {
    672.            
    673.             Add<BasicDetector>(value);
    674.            
    675.             Gesture.onMouse1E += value;
    676.            
    677.         }
    678.        
    679.         remove
    680.         {
    681.            
    682.             Remove<BasicDetector>(value);
    683.            
    684.             Gesture.onMouse1E -= value;
    685.    
    686.         }
    687.        
    688.     }
    689.    
    690.    
    691.     public static event Gesture.Mouse2DownHandler onMouse2DownE
    692.     {
    693.        
    694.         add {
    695.            
    696.             Add<BasicDetector>(value);
    697.            
    698.             Gesture.onMouse2DownE += value;
    699.            
    700.         }
    701.        
    702.         remove
    703.         {
    704.            
    705.             Remove<BasicDetector>(value);
    706.            
    707.             Gesture.onMouse2DownE -= value;
    708.    
    709.         }
    710.    
    711.     }
    712.    
    713.     public static event Gesture.Mouse2UpHandler onMouse2UpE
    714.     {
    715.        
    716.         add {
    717.            
    718.             Add<BasicDetector>(value);
    719.            
    720.             Gesture.onMouse2UpE += value;
    721.            
    722.         }
    723.        
    724.         remove
    725.         {
    726.            
    727.             Remove<BasicDetector>(value);
    728.            
    729.             Gesture.onMouse2UpE -= value;
    730.    
    731.         }
    732.        
    733.     }
    734.    
    735.     public static event Gesture.Mouse2Handler onMouse2E
    736.     {
    737.        
    738.         add {
    739.            
    740.             Add<BasicDetector>(value);
    741.            
    742.             Gesture.onMouse2E += value;
    743.            
    744.         }
    745.        
    746.         remove
    747.         {
    748.            
    749.             Remove<BasicDetector>(value);
    750.            
    751.             Gesture.onMouse2E -= value;
    752.    
    753.         }
    754.        
    755.     }
    756.    
    757. }
    758.  
    759.  
    760.  
     
  38. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    Is there an easy way to cancel a gesture?

    I use UIToolkit but Input.Touches for swipes, rotations etc. When I tap on a button a swipe can sometime be activated, I'd like to be able to do

    Code (csharp):
    1.  
    2. Gesture.Cancel();
    3.  
    to cancel any touches that are currently being detected but haven't triggered anything.
     
  39. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    That is not supported I'm afraid. I'll try to see what I can do about it.

    At the mean time, what I would do is use a simple condition checking when an event is triggered. Say if the position is landed on top of an GUI element then ignore it.

    Alternatively you can adjust the value on SwipeDetector. Increase the minDistance to make sure that a simple tap or touch wouldnt trigger the swipe event.
     
  40. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    Odd question for you. Is there a gesture/swipe the could resemble a scratch motion? For example, the back and forth motion of scratching off a lottery card?


    thanks,
    B
     
  41. wagamama

    wagamama

    Joined:
    Feb 10, 2013
    Posts:
    8
    Hello I bought input and touch but I really don't know how to do Pinch?
    because in the demo didn't have that about pinch

    I need that move

    how it work?
    how to set up
     
  42. DarkSprite

    DarkSprite

    Joined:
    Oct 7, 2011
    Posts:
    81
    Sent you a PM
     
  43. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm terribly sorry for the delayed respond, folks. For some reason the notification system has not been working properly off late.

    @outtoplay,
    I'm afraid there's no default build in feature for what you need yet. But you can easily detect that by getting a series of swipe event which happened in the opposite direction. The swipe event does give indication of the swipe direction.

    @wagamama, there's a example for pinch event in both RTSCam and OrbitCam. Please check my respond to your pm.

    @DarkSprite, I've responded to your pm. :)
     
  44. BenQi

    BenQi

    Joined:
    Mar 18, 2013
    Posts:
    8
    HI I'm new to use input touches , i have a problerm that the RTS camera works fine on my Android 4.0 device, but the OnMFDragging() is not work on my Android 4.1 device, so i can't drag the camera use two fingers anymore, is the problerm in "Input touches" or in "Android 4.1" ?
     
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm afraid I've been informed that in some instance of android device doesnt register the delta-position of multi touch. I'm not sure if it's down to some specific device to the version of Android used. The device which this has known to occur is "Samsung GT-P7510MA". but keep in mind it could well be the versioning.

    The work around would be manually storing the position of the touches in each frame and calculate the delta-position in next. This of course, require some modification to the code. I can help you with that if you are not at all familier with it.
     
  46. BenQi

    BenQi

    Joined:
    Mar 18, 2013
    Posts:
    8
    thanks for your attention,our team make esay hand VR show for coal miners, and we use the Customized Devices,so we just pay attention to the easy action script, i'm learning the classes API and more functions. wait for your substitute code,and very thanks for your help.
     
  47. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I've sent a fix to you via pm, please check it out.
     
  48. BenQi

    BenQi

    Joined:
    Mar 18, 2013
    Posts:
    8
    very thanks for your helping, your code is useful when draging with 2 fingers, but only dragble on +X axis,, i checked the dragdetector.cs and change the two "-" to "+" in line 60 and 61 make it like the folwing:

    Code (csharp):
    1.                     Vector2 v1=(Input.touches[i].position + lastPoss[i]).normalized;
    2.                     Vector2 v2=(Input.touches[i+1].position + lastPoss[i+1]).normalized;
    and it works!! thanks.
     
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for letting me know. :)
     
  50. UnityCoder

    UnityCoder

    Joined:
    Dec 8, 2011
    Posts:
    534
    Hello songtan, i checked input.touch web player and it looks very impressive. Before buying i have a few question that its possible to drag multiple object at a time with multitouch. For example i am going to develop a puzzle game, so its possible that multiple multiple user play this drag and drop game on multitouch monitor on windows 7. I have a viewsonic multitouch monitor. In that webplayer only single touch drag and drop available.

    If yes then i would like to purchase it.