Search Unity

[RELEASED] Easy Touch

Discussion in 'Assets and Asset Store' started by Hedgehog-Team, May 8, 2012.

  1. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Just a little thing I didn' t understand very well (my bad english) You do the test on a touchscreen or mouse in window seven ?
     
  2. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    420
    I am testing with a Windows 8.1 touchscreen tablet in the desktop with the build set to : UNITY_STANDALONE_WIN. The mouse works perfectly to select (it uses the simpleTap to convert the mouse click to a tap gesture), it is only when touching the screen with my finger that the tap does not work unless I hold my finger down.
     
  3. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    I understand better, we are facing a problem because Unity doesn't support the touch under Window 7 8 and EasyTouch uses Unity.... So I can't debug something that Unity doesn't support...

    Packages for touch on Window 8 7 are available on the store, or solution "hack" solutions are present on the WEB. But nothing is 100% reliable

    I really sorry for that, I'm waiting you on skype if you want
     
  4. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    420
    Yes, Unity does in fact support touch on Windows 8 standalone, that is why plugins like NGUI, FingerGestures and even most of EasyTouch work just fine. What it doesn't support is multi-touch twist gestures. Otherwise regular tap/drag gestures work 100% reliably. Unity translate the touch input in win8 (and maybe win7, I don't know) into a mouse click. So all you need to do is add code that in Standalone Win builds receive the Input.GetMouseButtonUp(0) event and convert that into a touch event.

    To fix this in my project, I didn't want to mess with EasyTouch code at the moment so I just disabled the simpletap gesture (on standalone builds) and added an Input.GetMouseButtonUp(0) that does the same thing. It works perfectly and detects the taps from my win 8 tablet. Simple solution for a simpletap :)

    Maybe something in the :
    public Finger GetMouseTouch(int fingerIndex,Finger myFinger){

    function in EasyTouchInput.cs could be tweaked to allow this fake touch input to work correctly.
     
  5. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    420
    Ok so I've looked into the EasyTouch code and discovered why touch on Windows desktop doesn't work well, it's because Unity converts the tap into a mouse click but it does it all in one frame. So in one frame all three events are fired:

    Input.GetMouseButton(0)
    Input.GetMouseButtonUp(0)
    Input.GetMouseButtonDown(0)

    So when the getTouchCount function is called on the first mouse event frame it will return a touch count, but because the MouseButtonUp occurs on the same frame there is no more touch count on any following frames, so EasyTouch never exits out of the touch BEGAN state because it only checks for the mousebuttonup on subsequent frames.

    I'm not sure if this is the best fix for this as you know your own code much better Nicolas, but what I did was add !Input.GetMouseButtonUp(0)) to the if statement in public Finger GetMouseTouch(..) function inside EasyTouchInput.cs at line 87:

    if (Input.GetMouseButton(0) !Input.GetMouseButtonUp(0)){

    This way GetMouseTouch will return the Finger with an ENDED touchphase if it receives a tap on standalone windows touchscreen builds.

    The rest of the functions like dragging, swiping, etc.. seem to work as well (rotate doesn't work, but I know that is a more complex issue).

    If you have any better suggestions on where to place this or can add it into an update that would be great as you'll gain another platform that your plugin supports. I'm happy to explain this over Skype as well if you prefer.
     
  6. Lockwood

    Lockwood

    Joined:
    Dec 24, 2013
    Posts:
    5
    Mismatched serialization in the builtin class 'Mesh'. (Read 560 bytes but expected 561 bytes)

    anyone know why I'm getting this error? I have nothing else on the scene only easytouch.

    Edit: Found the answer just after my post. here is any one else is also looking for it. http://www.blitz3dfr.com/teamtalk/index.php?topic=148.msg561#msg561
     
    Last edited: Mar 14, 2014
  7. WPCJack

    WPCJack

    Joined:
    Mar 15, 2013
    Posts:
    26
    Hey Guys,

    Great plugin, we use it in all our projects. One request though. We use this in combination with a lot of other tools, prime31, unibill, analytics etc... and having multiple plugins folders causes us headaches. Could you guys please use the root folder for the plugins folder?

    Cheers,
     
  8. XCO

    XCO

    Joined:
    Nov 17, 2012
    Posts:
    380
    Hello HedgeHog Team I am a HUGE fan of your stuff, Like HUGE!!!

    I was wondering if this VJ is compatible with PLAYMAKER ? I don't program and need a VJ so badly :-O

    If it is not would you consider bringing PlayMaker support ? Thanx HH Team I really really love everything you make!! (And I cant wait to show you the big game im working on with your assets) :D
     
  9. johnnydj

    johnnydj

    Joined:
    Apr 20, 2012
    Posts:
    211
    I'm trying to figure out how to access the coordinates of the joystick, because I'm trying to make an object face towards the direction, where the joystick is held.
    That is impossible from the GUI so I have to access the coordinates, because the rotate option from the GUI just makes the object rotate without stopping.
    Can anyone help out?
     
  10. lovelyazka

    lovelyazka

    Joined:
    Feb 27, 2014
    Posts:
    2
    hi .. cau help me with this problem ?

    im use a simple script

    Code (csharp):
    1.  
    2.     function On_SimpleTap( gesture:Gesture)
    3.     {
    4.         Debug.Log("TAP!");
    5.     }
    6.  
    7.  
    but have error like this ..

    The name 'Gesture' does not denote a valid type ('not found').

    i see you're post. i was move plugin folder on easytouch to root project. but im using easytouch for my apps augmented reality using vuforia. and have same folder is plugin. how do you think? any reference? helpp me. :sad: :sad:
     
  11. vinchenc0o

    vinchenc0o

    Joined:
    Dec 11, 2013
    Posts:
    4
    Hi,


    I have some issues when the next level loads.... The player keeps moving and the only way to stop it is to touch anywhere on the screen. Can you please advise?
    I've tried resetting the joystick but with no luck.
     
  12. vinchenc0o

    vinchenc0o

    Joined:
    Dec 11, 2013
    Posts:
    4
    One more thing: is it possible to disable the movement while Easy Button is pressed?
     
  13. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi vinchencOo

    Can you tell me what is your version, because I already fixed something like that

    I don't understand your second question
     
  14. vinchenc0o

    vinchenc0o

    Joined:
    Dec 11, 2013
    Posts:
    4
    Hi,

    I've managed to fix that issue myself, thanks anyway.

    Regarding my second point: I would like to stop moving the player when the button is pressed since it's performing a melee attack. The workaround is to set joystick.speed.x = 0 and joystick.speed.y = 0 while I am pressing the button but I thing there might be an easier or better way.

    Thanks in advance!
     
  15. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    It's good way , if the player keep the joystick on
     
  16. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    if i remember good on last version bouton get option for reserved arena ? no
     
  17. Backward-pieS

    Backward-pieS

    Joined:
    Feb 7, 2013
    Posts:
    20
    Hi Hedgehog Team,

    I'm having a serious problem while dragging a gameObject in a touch screen game. If I touch near enough to the finger doing the dragging, the object jumps to the nearby touch. I've put code into my gameObject to ignore any subsequent touches and base its position on the gesture whose finger index matches initial touch, but that doesn't help.

    I also tried turning off the colliders for the gameObject, so no other touches could interact with it, but that didn't help.

    Then I took a look at the EasyTouch sample scene called "MultiFingers" and found the same dragging issue there as well.

    Do you have any ideas on how to fix this?

    Thanks,
    Jason
     
  18. Backward-pieS

    Backward-pieS

    Joined:
    Feb 7, 2013
    Posts:
    20
    I should note, if I move the gameObject with the second touch, then release it, the gameObject will snap back to the proper touch, which I don't understand...

    I thought, maybe the second touch is close enough that the mobile device doesn't know which touch point should be associated with the original index. But if releasing the second touch returns the gameObject to the original touch, doesn't that imply the code/device never lost that original touch's association with the correct index?

    Probably the most important/troubling concern is that it is possible to break the gameObject behavior with the second touch: sometimes it will get stuck in place, its drag cancelled but Drag_End hasn't (I think) been called, and touching it again gets no response.
     
    Last edited: Apr 11, 2014
  19. josessito

    josessito

    Joined:
    Feb 14, 2014
    Posts:
    57
    Hi Hedgehog Team, I wanted to know if there is a way to access the swipe/drag "minimum speed threshold" ( the minimum speed after which the gesture is recognized as a drag/swipe instead of a touch). I'm not sure if this is implemented by easy-touch, Unity or the mobile OS, but if there is a way to access and modify this value, I would really like to know.
    This is a great product!
    Thanks!
     
  20. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hello hedgehog
    i try to use joystick class, to play my own animation, in the joystickEvent.cs i try to add two animation on the x axis by adding this

    void On_JoystickMove( MovingJoystick move){


    if (move.joystickName == "Move_Turn_Joystick"){

    //
    if (Mathf.Abs(move.joystickAxis.y)>0 Mathf.Abs(move.joystickAxis.y)<0.5){
    animation.CrossFade("walk");

    }
    else if (Mathf.Abs(move.joystickAxis.y)>=0.5){
    animation.CrossFade("run");
    }

    if (Mathf.Abs(move.joystickAxis.x)>0 Mathf.Abs(move.joystickAxis.x)<0.5){
    animation.CrossFade("walk");

    }
    else if (Mathf.Abs(move.joystickAxis.y)>=0.5){
    animation.CrossFade("run");
    }
    }
    }


    but that doesnt seem to play.
    any idea?

    thanks
     
  21. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi all,

    Sorry for delay.

    Backward pieS
    Can you check taht you have Unity Remote set to false.

    josessito
    This data does not exist, but you can calculate when you receive the message, with member of gesture classe

    toto2003
    You have subscribed to the mesage?

    The name of your joystick is correct?

    If you add debug.log (..) is that they appear ?
     
  22. Backward-pieS

    Backward-pieS

    Joined:
    Feb 7, 2013
    Posts:
    20
    If I have Unity Remote unchecked, I can only use one touch at a time. Our game is multi-touch so it needs to be on to test that.
     
  23. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi,

    On what platform you made ​​your test?
     
  24. Backward-pieS

    Backward-pieS

    Joined:
    Feb 7, 2013
    Posts:
    20
    I'm building for Android. My test tablet is a recently purchased Samsung Nexus 10.

    I ran another test, and am starting to think the the multi-touch problems are exacerbated by Unity Remote:

    I ran some touch count tests using Unity Remote and Unity's own Input.touchCount and I'm getting errant numbers of counts. One time it even reported 32 touches when I put all ten fingers on the screen. This also triggers an error in EasyTouch.cs line 625 (I'm assuming EasyTouch never expects more than 10 touches).

    When I put a build of the game on the tablet and played it directly, the touches were much more reliable, though not perfect (it happened once that the tablet would briefly report 4 touches then drop to 0 even though I hadn't lifted any fingers). I'm assuming EasyTouch pulls data from the Input class, so there's probably nothing you can do about that.

    I put the same build of the game on my Samsung Galaxy 3, and found that it was far easier (than on the tablet) to 'hijack' a game piece being dragged by touching near it. On the tablet, the second finger must be up against the first finger to affect the game piece. On the phone, there can be a visible gap between the fingers, yet I still affect the piece.

    Based on the differences between devices, I'm thinking these are somewhat unavoidable hardware issues.
     
    Last edited: Apr 18, 2014
  25. VictorDDP

    VictorDDP

    Joined:
    Apr 22, 2014
    Posts:
    5
    Hi Team, how I can keep pressed a button?
    For example, press once to turn on a light and the button is keep press until I press again to turn off the light.
    Thanks!
     
  26. Jojo-Batista

    Jojo-Batista

    Joined:
    Dec 5, 2012
    Posts:
    32
    Hello. Sorry to bother you, but I'm having an issue and I can't seem to find a way to solve it. I have a joystick on the left, an easy touch button on the right, and a sprite with a collider that works as a button . When I'm moving with the joystick, or if I mantain the easy touch button pressed, my button stops working. Do you know why could something like this happen?
     
  27. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    how to Remove unused Asset from this plugin?

    I am using only EasyButton in my game with my own textures. In the build, it seems that
    EasyPlay package is introducing several unused expensive textures:
    Used Assets, sorted by uncompressed size:
    1.0 mb 4.1% Assets/EasyTouch/Plugins/Resources/RadialJoy_Area.png
    682.7 kb 2.8% Assets/EasyTouch/Plugins/Resources/RadialJoy_Dead.png
    341.4 kb 1.4% Assets/EasyTouch/Example/C# Example/_Materials_ressources/GlowDisk01.png
    341.4 kb 1.4% Assets/EasyTouch/Example/C# Example/_Materials_ressources/Ring01.png
    256.1 kb 1.0% Assets/EasyTouch/Plugins/Resources/RadialJoy_Touch.png

    I've noticed that your code referencing these files in scripts. If I remove these files, I start getting exceptions - file not found in editor. I believe these unused assets should not be included in released build. What's the best way to get rid of unused asset from this plugin?
     
  28. Backward-pieS

    Backward-pieS

    Joined:
    Feb 7, 2013
    Posts:
    20
    I've encountered a couple of serious issues I wanted to document...

    First, if you place a first touch (touch index 0), add a second touch (touch index 1), then lift the first touch, using EasyTouch.GetFingerPosition(1) does not return the correct values for the second touch. It works fine if I lift the second touch and keep the first, but fails if earlier touches end before additional touches. I worked around this by using Unity's Input class, but wanted to let you know.

    Second, and maybe I'm using it improperly, but if I call EasyTouch.GetCurrentPickedObject(i) it kills that gesture object. I was using it in one class to check if a specific object was being dragged, starting with this assignment:

    GameObject pickedObject = EasyTouch.GetCurrentPickedObject(i); // Then I checked if 'pickedObject' was null and, if not, its name

    I verified that as long as that line of code was present, the actual touched object would have its drag cancelled after a single frame. I found a workaround, but I'm wondering why doing this corrupted the touch (I never changed 'pickedObject' - I only checked its data). If there is a proper way to use this method please let me know.
     
  29. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi all,

    VictorDDP
    You can simply do that with a boolean on your code, and check this boolean on the update method

    Jojo Batista
    How do you manage your bouton, on witch platform do you test it ?

    lilboylost
    To reduce your build size, remove example folder...these texture are used on example.

    Backward pieS
    Unity necessarily do not still returned 0 for the first touch and 1 for the second, so it is very important that you capture the finger index on Touchstart.This phenomenon is more common on android platform.

    If you're sure of your touch index, is it possible that you send an example with this issue ?
     
  30. jococo

    jococo

    Joined:
    Dec 15, 2012
    Posts:
    232
    Is there a way to get the identity (name/tag) of the button I just touched?
     
  31. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi Jococo,

    Off course, you must register to an easybutton event, and each events are sent with button name.

    Example :

    Code (csharp):
    1.     void OnEnable(){
    2.         EasyButton.On_ButtonUp += On_ButtonUp; 
    3.     }
    4.  
    5.     void On_ButtonUp (string buttonName)
    6.     {
    7.         if (buttonName=="Exit"){
    8.             Application.LoadLevel("StartMenu");
    9.         }
    10.     }
     
  32. Jojo-Batista

    Jojo-Batista

    Joined:
    Dec 5, 2012
    Posts:
    32
    It happens at least in android, web and in the editor.
    And it's a sprite, with a sphere collider. And a simple script that does something in the OnMouseDown() method

    Here is the configuration for the Easy Touch

    $easytouch.PNG

    Edit: I'm not using NGUI. I left it like that because I was trying t make this work haha :)
    Edit 2 : I just stumble upon something that might be useful. If I press my button and the easy touch button (but pressing my button 1st, and with alt simulating the second touch in the easy touch button, it works)
     
    Last edited: Apr 28, 2014
  33. VictorDDP

    VictorDDP

    Joined:
    Apr 22, 2014
    Posts:
    5
    I'm having other issue, when I use:

    public EasyJoystick MyJoystick;

    blablabla

    h = MyJoystick.JoystickAxis.x("Horizontal");
    v = MyJoystick.JoystickAxis.y("Vertical");

    I receive the following messages:

    The member `UnityEngine.Vector2.x' cannot be used as method or delegate.
    The member `UnityEngine.Vector2.y' cannot be used as method or delegate.
     
  34. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Hey h.Team.

    I am using Easy Touch + Joystic + Button..

    I have few issues which I need your feedback on.

    1. I am using Easy touch to detect pinch gesture to do screen zoom in and out. Now, when I use Easy joystick , I have managed to figure out till that when my touch is over the joystick , it doesn't detect my pinch. (used reserved area tick box) but problem is as soon as my finger moves a bit away from the joystick and I am using Button to fire stuff, it detects as pinch and I have this sudden unwanted pinch detection. I want to try and add extra reserved area to make the pinch detect only on the area I want it to , but I just can't figure out how this EasyTouch.AddReservedGuiArea(Rect); works... I ave tried to enter all sort of values into different rect area , but nothing seems to actually do anything. I need more detailed explanation about how to use reserved area. The doc says it is "or rect origin on top left" so if my rect is (0,0,500,500) will it make half of my screen reserved area for screen size 1000x100 ? (I thought this was the case, but not...)

    2. Another issue with using Easy joystick with other GUI program such as Daikon gui. Use NGUI compatibility actually works well for Easy touch with Daikon GUI. But with joystick, it loses joystick movement if I press any Daikon GUI buttons. I understand that NGUI compatibility is precisely for this purpose where touch isn't detected over the other GUI program such as NGUI or Daikon GUI, but it removes all touch input so my finger is still trying to move the joystick it won't do it. In nutshell, how can I combine use of Joystick and other GUI's buttons etc.? ( I don't want to use EasyButton for everything...)

    Thanks.

    and please approve my account on your official forum. ID : Castor
     
  35. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi all,

    VictorDDP
    Just this : h = MyJoystick.JoystickAxis.x;

    castor76
    1- Look at multilayer example where there is reservedarea example and setup. If you can't do it with the example, let me

    2- Do you have setup the new auto-select properties where you can add camera ?
     
  36. josessito

    josessito

    Joined:
    Feb 14, 2014
    Posts:
    57
    Hi Hedgehog Team. I already asked this in Questions but since I'm using easy touch I might asked it here. It is not an easy touch problem, just an implementation issue, so I'm sorry if this is not the place for this.

    Hi! I'm having a problem.
    I need to drag an object on the screen (x and y position). I'm dragging it with touch, but that's not the issue. The object needs to be dragged from the position of the touch, not it's center, also, the object's movement might be restricted by a radius and/or limited to move along an axis (x or y) and finally, if the finger leaves the circle defined by the radius, the object must keep following its relative position without getting out the radius.

    To do this I'm using the code pasted below. It works like this: It creates an empty object in the position of the touch (dragMarker) and then it sets this dragMarker as the parent of the object to drag. Then, I update the postion of the dragMarker to track the touch. This works fine, but when I apply the radial restrictions things go wrong.

    I believe that if I change the restriction radius (maxMovementRadius) to take into account the radial distance between the objects position (transform.position) and the dragMarker's position I can fix this, but I'm not sure how to do this (image). There may be a better approach to all this tough...

    I'm using easy touch and there are some other functianlities in the code. You don't need to pay attention to the update function. Also, SetX and SetY are just custom extensions to transform that basically do what they say. (I have pasted those methods at the end of the code, but they would not work like that).

    Thanks and sorry for the length of the question.

    Code (csharp):
    1.  
    2.  using UnityEngine;
    3.     using System.Collections;
    4.    
    5.     /// <summary>
    6.     /// Put this script on the object you want to be able to drag.
    7.     /// It must be on the Touchable,the Floor or the Enemy layer.
    8.     /// EasyTouch must be in the project.
    9.     /// </summary>
    10.     [AddComponentMenu("Utilities/Dragable Object")]
    11.     public class DragableObject : MonoBehaviour
    12.     {
    13.    
    14.         /// <summary>
    15.         /// Allowed movement radius. If 0, the movement is free.
    16.         /// </summary>
    17.         public float maxMovementRadius;
    18.         public bool lockXPosition;
    19.         public bool lockYPosition;
    20.         public float movementDamp = 10f;
    21.         public bool useAndDestroy = false;
    22.         public int maxPosibleUses = 1;
    23.        
    24.        
    25.         [Range(0f,1f)]
    26.         public float alpha = 1;
    27.    
    28.         private GameObject dragMarker;
    29.         private Vector3 origPosition = Vector3.zero;
    30.         private Vector3 origPositionMark = Vector3.zero;
    31.         private bool used = false;
    32.        
    33.         private int usesCount = 0;
    34.         private Color newColor = new Color();
    35.         private ParticleSystem pufParticles;
    36.         private LineRenderer lineRenderer;
    37.    
    38.         void OnEnable()
    39.         {
    40.             EasyTouch.On_Drag += On_Drag;
    41.             EasyTouch.On_DragStart += On_DragStart;
    42.             EasyTouch.On_DragEnd += On_DragEnd;
    43.         }
    44.    
    45.         void OnDisable()
    46.         {
    47.             UnsubscribeEvent();
    48.         }
    49.    
    50.         void OnDestroy()
    51.         {
    52.             UnsubscribeEvent();
    53.         }
    54.    
    55.         void UnsubscribeEvent()
    56.         {
    57.             EasyTouch.On_Drag -= On_Drag;
    58.             EasyTouch.On_DragStart -= On_DragStart;
    59.             EasyTouch.On_DragEnd -= On_DragEnd;
    60.         }
    61.    
    62.         void Awake()
    63.         {      
    64.              
    65.             //save the original position of the object
    66.             origPosition = transform.position;
    67.             Debug.Log("Original position: " + origPosition);
    68.             newColor = renderer.material.color;
    69.             pufParticles = transform.Find("PufParticles").GetComponent<ParticleSystem>();
    70.            
    71.         }
    72.    
    73.         void Update()
    74.         {
    75.            
    76.             newColor.a = alpha;
    77.             renderer.material.color = newColor;
    78.            
    79.             if (useAndDestroy)
    80.             {          
    81.                 if (PlayerController.ONOBJECT == gameObject)
    82.                 {
    83.                     used = true;  
    84.                 }
    85.                 // if this conditions are meet it measn that the player has been over this object,
    86.                 //but it is not here anymore. So if it is used object, it will increment the uses count until
    87.                 // it reachs tha max number of uses and it destroy itself            
    88.                 if (PlayerController.ONOBJECT!= gameObject  used)
    89.                 {
    90.                     used = false;
    91.                     usesCount++;
    92.                    
    93.                     if(usesCount >= maxPosibleUses)
    94.                     {
    95.                         SelfDestruct();
    96.                     }
    97.                 }
    98.             }
    99.         }
    100.    
    101.         // At the drag beginning
    102.         void On_DragStart(Gesture gesture)
    103.         {
    104.            
    105.             // Verification that the action on the object
    106.             if (gesture.pickObject == gameObject)
    107.             {
    108.                 //play sound
    109.                 //play visual queue
    110.                 dragMarker = new GameObject("Drag Marker");
    111.                 dragMarker.transform.position = gesture.GetTouchToWordlPoint(transform.position.z, worldZ: true);
    112.                 dragMarker.transform.rotation = Quaternion.identity;
    113.                
    114.                 gameObject.transform.parent = dragMarker.transform;
    115.                 origPositionMark = dragMarker.transform.position;
    116.                 Debug.Log("Drag Start. Marker Orig Position: " + origPositionMark);
    117.             }
    118.         }
    119.    
    120.         // During the drag
    121.         void On_Drag(Gesture gesture)
    122.         {
    123.             if (gesture.pickObject == gameObject)
    124.             {
    125.    
    126.                 if (PlayerController.ONOBJECT != gameObject)
    127.                 {
    128.                                    
    129.                     Vector3 position = gesture.GetTouchToWordlPoint(transform.position.z, worldZ: true);
    130.                     Vector3 targetPos = Vector3.zero;
    131.                      
    132.                     targetPos.x = lockXPosition ? origPositionMark.x : position.x;
    133.                     targetPos.y = lockYPosition ? origPositionMark.y : position.y;
    134.                  
    135.                     if (maxMovementRadius != 0)
    136.                     {
    137.                         //this radious should be the magnited of the vector that starts in origPosition and ends in the marker???
    138.                         if (Vector3.Distance(origPosition, position) < maxMovementRadius)
    139.                         {
    140.                             dragMarker.transform.SetX(Mathf.Lerp(dragMarker.transform.position.x, targetPos.x, Time.deltaTime * movementDamp));
    141.                             dragMarker.transform.SetY(Mathf.Lerp(dragMarker.transform.position.y, targetPos.y, Time.deltaTime * movementDamp));
    142.                             Debug.Log("In radious");
    143.    
    144.                         }
    145.                         else
    146.                         {
    147.                             Debug.Log("out of radious");
    148.    
    149.                             Vector3 newPos = position - origPosition;
    150.                             newPos.Normalize();                                                                                  
    151.                             newPos *= maxMovementRadius;
    152.                             newPos += origPosition;
    153.    
    154.                             newPos.x = lockXPosition ? origPositionMark.x : newPos.x;
    155.                             newPos.y = lockYPosition ? origPositionMark.y : newPos.y;
    156.    
    157.                             dragMarker.transform.position = newPos;
    158.    
    159.                             ;
    160.                         }
    161.                     }
    162.                     else
    163.                     {
    164.                         dragMarker.transform.SetX(Mathf.Lerp(dragMarker.transform.position.x, targetPos.x, Time.deltaTime * movementDamp));
    165.                         dragMarker.transform.SetY(Mathf.Lerp(dragMarker.transform.position.y, targetPos.y, Time.deltaTime * movementDamp));
    166.    
    167.                     }
    168.                 }
    169.             }
    170.         }
    171.    
    172.         // At the drag end
    173.         void On_DragEnd(Gesture gesture)
    174.         {
    175.             //play sound
    176.             //play visual queue
    177.             transform.parent = null;
    178.             Destroy(dragMarker);
    179.         }
    180.    
    181.         void SelfDestruct()
    182.         {
    183.             pufParticles.Play();
    184.             alpha = 0;
    185.             collider2D.enabled = false;
    186.         }
    187.     }
    188.    
    189.     //extensiond
    190.    
    191.     public static class TransformExtensions
    192.     {
    193.         public static void SetX(this Transform t, float n)
    194.         {
    195.             t.position = new Vector3(n, t.position.y, t.position.z);
    196.         }
    197.    
    198.         public static void SetY(this Transform t, float n)
    199.         {
    200.             t.position = new Vector3(t.position.x, n, t.position.z);
    201.         }
    202.    
    203.         public static void SetZ(this Transform t, float n)
    204.         {
    205.             t.position = new Vector3(t.position.x, t.position.y, n);
    206.         }
    207.    
    208.     }
    209.  
    210.  
    $problem.png
     
  37. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi,

    It seems very complex...You don't need to create an empty object, you have to manage a relative position,( look at image manipulation example, where you can drag an object not relative to his center)

    I don't quite understand your second point ( sorry for my bad english), the radius, just to test the radius relative to the length of drag (it doesn't work?)
     
  38. josessito

    josessito

    Joined:
    Feb 14, 2014
    Posts:
    57
    Hi Hedgehog. Yes! I don't know what was I thinking! I took the most needlessly complicated approach. After I used the deltaPostion approach things got easier for me to understand. The code is much cleaner and simple. Here it is, if someone needs it. You can use it to drag an object and you can set a maximum radius movement(0 = unlimited) and/or and axis restriction.
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. /// <summary>
    6. /// Put this script on the object you want to be able to drag.
    7. /// It must be on the Touchable,the Floor or the Enemy layer.
    8. /// EasyTouch must be in the project.
    9. /// </summary>
    10. [AddComponentMenu("Utilities/Dragable Object")]
    11.  
    12. public class DragableObject : MonoBehaviour
    13. {
    14.  
    15.     /// <summary>
    16.     /// Allowed movement radius. If 0, the movement is free.
    17.     /// </summary>
    18.     public float maxMovementRadius;
    19.     public bool lockXPosition;
    20.     public bool lockYPosition;
    21.     public float movementDamp = 10f;
    22.  
    23.     private Vector3 deltaPosition;
    24.     private Vector3 origPosition = Vector3.zero;
    25.    
    26.    
    27.  
    28.     void OnEnable()
    29.     {
    30.         EasyTouch.On_Drag += On_Drag;
    31.         EasyTouch.On_DragStart += On_DragStart;
    32.         EasyTouch.On_DragEnd += On_DragEnd;
    33.     }
    34.  
    35.     void OnDisable()
    36.     {
    37.         UnsubscribeEvent();
    38.     }
    39.  
    40.     void OnDestroy()
    41.     {
    42.         UnsubscribeEvent();
    43.     }
    44.  
    45.     void UnsubscribeEvent()
    46.     {
    47.         EasyTouch.On_Drag -= On_Drag;
    48.         EasyTouch.On_DragStart -= On_DragStart;
    49.         EasyTouch.On_DragEnd -= On_DragEnd;
    50.     }
    51.  
    52.     void Awake()
    53.     {    
    54.         //save the original position of the object
    55.         origPosition = transform.position;
    56.         Debug.Log("Original position: " + origPosition);
    57.              
    58.     }
    59.  
    60.     void Update()
    61.     {
    62.                          
    63.     }
    64.  
    65.     // At the drag beginning
    66.     void On_DragStart(Gesture gesture)
    67.     {  
    68.         // Verification that the action on the object
    69.         if (gesture.pickObject == gameObject)
    70.         {
    71.                                  
    72.             Vector3 position = gesture.GetTouchToWordlPoint(transform.position.z, worldZ: true);          
    73.             //here it is stored the delta betwwen thr touch and the objecs center position
    74.             deltaPosition = position - transform.position;
    75.  
    76.         }
    77.     }
    78.  
    79.     // During the drag
    80.     void On_Drag(Gesture gesture)
    81.     {
    82.         if (gesture.pickObject == gameObject)
    83.         {
    84.  
    85.             if (PlayerController.ONOBJECT != gameObject)
    86.             {
    87.                                
    88.                 Vector3 position = gesture.GetTouchToWordlPoint(transform.position.z, worldZ: true);
    89.                 Vector3 targetPos = Vector3.zero;
    90.                  
    91.                 targetPos.x = lockXPosition ? origPosition.x : position.x - deltaPosition.x;
    92.                 targetPos.y = lockYPosition ? origPosition.y : position.y - deltaPosition.y;
    93.              
    94.                 if (maxMovementRadius != 0)
    95.                 {
    96.                      
    97.                     if (Vector3.Distance(origPosition, (position-deltaPosition)) < maxMovementRadius)
    98.                     {
    99.                        
    100.                         transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * movementDamp);
    101.  
    102.                     }
    103.                     else
    104.                     {
    105.                        
    106.                         Vector3 newPos = position - deltaPosition - origPosition;
    107.                         newPos.Normalize();                                                                                  
    108.                         newPos *= maxMovementRadius;
    109.                         newPos += origPosition;
    110.  
    111.                         newPos.x = lockXPosition ? origPosition.x : newPos.x;
    112.                         newPos.y = lockYPosition ? origPosition.y : newPos.y;        
    113.                        
    114.                         transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * movementDamp);
    115.                     }
    116.                 }
    117.                 else
    118.                 {                                        
    119.                     transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * movementDamp);
    120.                 }
    121.             }
    122.         }
    123.     }
    124.  
    125.     // At the drag end
    126.     void On_DragEnd(Gesture gesture)
    127.     {
    128.         //play sound
    129.         //play visual queue
    130.    
    131.     }
    132.  
    133.    
    134. }
    135.  
     
  39. Jojo-Batista

    Jojo-Batista

    Joined:
    Dec 5, 2012
    Posts:
    32
    Hey, sorry to disturb you again. But I couldn't solve this issue yet :/ any news? thanks!
     
  40. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Jojo , Can you send to me an example, thank you
     
  41. henriquefaria

    henriquefaria

    Joined:
    Sep 17, 2013
    Posts:
    31
    Ara controller presets (3rd person controller, perspective platformer, etc) included in this asset?
     
  42. henriquefaria

    henriquefaria

    Joined:
    Sep 17, 2013
    Posts:
    31

    No one??
     
  43. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi,

    There aren't any preset, but you can do all your want
     
  44. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    What is the recommended way to Pan a Camera using Easytouch?

    I want the camera to follow the pan position, but I want it to slowly stop moving after the pan ends...

    I was using gesture.swipeVector but it have huge differences on different platforms !

    Any example or suggestion?
     
  45. josessito

    josessito

    Joined:
    Feb 14, 2014
    Posts:
    57
    Hi HedgeHog, I have a problem. I'm trying to set up multiple buttons but I have an issue and the documentation is not helping me.

    I have two buttons in the screen, one is called Reset, the other Items. The problem is that when I press any button, the " void On_ButtonPress(string Reset)" method gets called. How can I differentiate between this specific button (the "Reset" button) and the other buttons to check which one was pressed. (something in the lines of the gesture.pickObject mehod). If there is not something like that, how should I do this.

    This script is not in the button, but on another empty game object.

    Code (csharp):
    1.  
    2. public class GameManager : MonoBehaviour {
    3.        
    4.  
    5.     void OnEnable()
    6.     {
    7.         EasyButton.On_ButtonPress += On_ButtonPress;
    8.        
    9.     }
    10.  
    11.     void OnDisable()
    12.     {
    13.         UnsubscribeEvent();
    14.     }
    15.  
    16.     void OnDestroy()
    17.     {
    18.         UnsubscribeEvent();
    19.     }
    20.  
    21.     void UnsubscribeEvent()
    22.     {
    23.  
    24.       EasyButton.On_ButtonPress -= On_ButtonPress;
    25.     }
    26.            
    27.     void On_ButtonPress(string Reset)
    28.     {
    29.      
    30.         Application.LoadLevel(Application.loadedLevel);
    31.        
    32.     }
    33.  
    34.  
    35. }
    36.  
     
  46. talyon

    talyon

    Joined:
    Nov 15, 2013
    Posts:
    3
    hello to all
    i hope that here is the right thread.
    I bought your assets, but I found some problems in creating a joystick to shoot (Minigore controller, a simple dualstickshooter) have any ideas on how it can set the whole thing in a simple way.

    This is the script that work whit Xbox 360 joystick and keyboard
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class Boundary
    6. {
    7.     public float xMin, xMax, yMin, yMax;
    8. }
    9.  
    10.  
    11. public class dualStickShooter : MonoBehaviour
    12. {
    13.     public Boundary boundary;
    14.     public float speed;
    15.  
    16.     public GameObject bullet;
    17.     public float bulletSpeed;
    18.     public float shootDelay;
    19.  
    20.     private bool canShoot = true;
    21.  
    22.     void Update ()
    23.     {
    24.         Vector3 moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical"), 0.0f);
    25.         transform.position += moveDirection * speed * Time.deltaTime;
    26.            
    27.         if((Input.GetAxis ("FireHorizontal") != 0.0f || Input.GetAxis ("FireVertical")!= 0.0f)  canShoot)
    28.         {
    29.             Vector3 shootDirection = new Vector3 (Input.GetAxis ("FireHorizontal"), Input.GetAxis ("FireVertical"), 0.0f).normalized;
    30.             GameObject bulletInstace = Instantiate (bullet, transform.position, Quaternion.LookRotation (shootDirection)) as GameObject;
    31.             bulletInstace.rigidbody.AddForce (shootDirection * bulletSpeed, ForceMode.VelocityChange);
    32.             canShoot = false;
    33.             Invoke ("ShootDelay",shootDelay);
    34.         }  
    35.  
    36.         rigidbody.position = new Vector3
    37.             (
    38.                 Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
    39.                 Mathf.Clamp (rigidbody.position.y, boundary.yMin, boundary.yMax),
    40.                 0.0f
    41.                 );
    42.     }
    43.  
    44.     void ShootDelay()
    45.     {
    46.         canShoot = true;
    47.     }
    48. }
    49.  
     
    Last edited: May 16, 2014
  47. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    @EasyButton
    How do I position EasyPosition using global GUI co-ordinates (0,1) instead of pre-defined positions with offset?

    Currently, Easy button gives me an option to position:
    Top/middle/bottom-left/middle/right and add offset in Pixels.

    Offset is dependent on device resolution. I've another GUIElement which I want to place next to EasyButton but EasyButton being pixel specific changes it's position on iphone vs ipad. Say, I want to place:
    Easy Button at position (0.2, 0.5) - Middle of screen, 20% of left. How would I do that without setting screen pixels dynamically?


    Thanks
     
  48. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi All,

    Wagenheimer
    use swipe vector, vector length and consider the execution time

    josessito
    The string parameter of On_ButtonPress is the name of your button, so you have to test this string to know witch button is pressed

    talyon
    You have to replace Input.GetAxis("your direction") by :

    public EasyJoystick myJoy1;
    public EasyJoystick myJoy2;

    void Update(){
    if (myJoy.JoystickAxis.x ....
    }

    lilboylost
    EasyButton and EasyJoystick, use a virtual screen of size 1024x768 which is not dependent on the resolution of the device. The position and scale are already manage for you....
     
  49. josessito

    josessito

    Joined:
    Feb 14, 2014
    Posts:
    57
    Hi Hedgehog. Thanks! Great support as always. I would rate you with 6 stars if I could.
    I have two short follow up questions. First I want to know how to make it so that when I touch the button nothing else gets touched (i believe it has something to do with reserved area but I can't figure it out). Second, How can I access the active texture, I want some of my buttons the act more like an on off switch, but the "active texture" will switch back to the "normal texture" once the finger is lifted (I'm just asking if there is some quick method for this, because I believe I could probably replace the "normal texture" from script) Thanks again!
     
  50. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    Thanks. Yes, it's size is relative. But I am not able to position it relative to screen size.
    How would I manage the position? Easybutton seems to ignore transform.position. How can I place:
    Easy Button at position (0.2, 0.5) - Middle of screen, 20% from left?