The Easytouch of Unity3d plug-in research

Source: Internet
Author: User
Tags getmessage

But when we developed the mobile game, found that using Input.getmousebuttondown method is not available, how to do?

Although Unity3d also has a touch screen approach, but the cost is too high to use, what to click, double-clicking on these features are packaged by themselves.

Below we say the next easytouch this plugin, it will all touch screen gestures, have been written.

And Easytouch also supports Ngui, which is very convenient to use.

Next, we will learn more about how this plugin can be used in our projects.

First of all, we import Easytouch plug-in, here I am using 3.0 version, may be some old, I did not update, but the general function is actually fully capable.

Steps to create Easytouch:

1. Here I use the C # script, JS I'm not quite familiar with.

2. You will see a easytouch in the scene when you are done.

3. Create a new C # script to implement simple touchscreen logic, note here that Easytouch supports testing under the editor without sending it to the real machine. This also greatly simplifies the work of developers. So personally strongly recommend this plugin.

We are named Touchtest,

Using unityengine;using System.collections;public class Touchtest:monobehaviour {//Subscribe to Eventsvoid OnEnable () { Easytouch.on_touchstart + = on_mytouchstart;//start On_touchstart monitoring, that is, finger touch screen, will trigger the On_mytouchstart method execution}// Unsubscribevoid ondisable () {easytouch.on_touchstart-= on_mytouchstart;//Remove listener}//unsubscribevoid OnDestroy () { Easytouch.on_touchstart-= on_mytouchstart;//Remove monitor}//Touch start eventpublic void On_mytouchstart (Gesture Gesture) { Debug.Log ("Touch in" + gesture.position);//print touch to screen coordinates Vector2}}

After writing the code, we create a new Gameobject and assign the script to the object.

Start the demo and observe the effect.

As a general step, we found that we were just testing a on_touchstart, encapsulating a lot of gestures in the Easytouch API:

On_cancel (Gesture Gesture)
Occurs when the system cancelled tracking for the touch, as if (for example) the user puts the device to her face.
On_cancel2fingers (Gesture Gesture)
Occurs when the touch count was no longer egal to 2 and different to 0, after the begining of a and fingers gesture.
On_touchstart (Gesture Gesture)
Occurs when a finger touched the screen.
On_touchdown (Gesture Gesture)
Occurs as the touch is active.
On_touchup (Gesture Gesture)
Occurs when a finger is lifted from the screen.
On_simpletap (Gesture Gesture)
Occurs when a finger were lifted from the screen, and the time elapsed since the beginning of the touch are less than
The time required for the detection of a long tap.
On_doubletap (Gesture Gesture)
Occurs when the number of taps was egal to 2 in a short time.
On_longtapstart (Gesture Gesture)
Occurs when a finger is touching the screens, but hasn ' t moved since the time required for the detection of a long tap.
On_longtap (Gesture Gesture)
Occurs as the touch is active after a Longtapstart
On_longtapend (Gesture Gesture)
Occurs when a finger were lifted from the screen, and the time elapsed since the beginning of the touch are more than
The time required for the detection of a long tap.
On_dragstart (Gesture Gesture)
Occurs when a drag start. A drag is a swipe on a Pickable object
On_drag (Gesture Gesture)
Occurs as the drag is active.
On_dragend (Gesture Gesture)
Occurs when a finger that raise the drag event, was lifted from the screen.
On_swipestart (Gesture Gesture)
Occurs when swipe start.
On_swipe (Gesture Gesture)
Occurs as the swipe is active.
On_swipeend (Gesture Gesture)
Occurs when a finger that raise the swipe event, was lifted from the screen.
On_touchstart2fingers (Gesture Gesture)
Like On_touchstart, but for a 2 fingers gesture.
On_touchdown2fingers (Gesture Gesture)
Like On_touchdown, but for a 2 fingers gesture.
On_touchup2fingers (Gesture Gesture)
Like On_touchup, but for a 2 fingers gesture.
On_simpletap2fingers (Gesture Gesture)
Like On_simpletap, but for a 2 fingers gesture.
On_doubletap2fingers (Gesture Gesture)
Like On_doubletap, but for a 2 fingers gesture.
On_longtapstart2fingers (Gesture Gesture)
Like On_longtapstart, but for a 2 fingers gesture.
On_longtap2fingers (Gesture Gesture)
Like On_longtap, but for a 2 fingers gesture.
On_longtapend2fingers (Gesture Gesture)
Like On_longtapend, but for a 2 fingers gesture.
On_twist (Gesture Gesture)
Occurs when a twist gesture start
On_twistend (Gesture Gesture)
Occurs as the twist gesture is active.
On_pinchin (Gesture Gesture)
Occurs as the twist in gesture is active.
On_pinchout (Gesture Gesture)
Occurs as the pinch out gesture is active.
On_pinchend (Gesture Gesture)
Occurs when the 2 fingers that raise the pinch event, is lifted from the screen.
On_dragstart2fingers (Gesture Gesture)
Like On_dragstart, but for a 2 fingers gesture.
On_drag2fingers (Gesture Gesture)
Like On_drag, but for a 2 fingers gesture.
On_dragend2fingers (Gesture Gesture)
Like On_dragend2fingers, but for a 2 fingers gesture.
On_swipestart2fingers (Gesture Gesture)
Like On_swipestart, but for a 2 fingers gesture.
On_swipe2fingers (Gesture Gesture)
Like On_swipe, but for a 2 fingers gesture.
On_swipeend2fingers (Gesture Gesture)
Like On_swipeend, but for a 2 fingers gesture.

Here I do not test each one, interested in children's shoes can go to the official demo to see.

Then let's take a look at Easytouch's property sheet:

Enable EasyTouch-------> Whether EasyTouch is enabled, otherwise all touchscreen effects disappear.

Enable Unity remote--------> Whether Unity Remote is enabled, this is what it is, he is unity development of mobile game aids, is to install the app or apk on your phone, and then through

The data cable is connected to your computer, and when your unity wants to build it, he will automatically test it on your phone, without having to build it and send it to your phone, then turn on the test.

This is the little stuff:

Broadcast Messages--------------------> whether to start unity inside the SendMessage mechanism, not familiar with the child shoes of their own research, in fact, good understanding.

is to send a message to a sibling, calling a method named MethodName on all Monobehaviour on the game object, such as in the Test1.cs script, we have a method:

GetMessage (String str) {  print ("Receive message:" +STR);//print received message      }

And then inside the Test2.cs, we call

string s = "Send Message"; SendMessage ("GetMessage", s);

You will receive a message when you run.

Okay, let's go back to Easytouch and see the parameters.

Ohter Receiver------------------> Assigns an object that allows you to send the message directly to the object.

Joysticks & Buttons---------------> Whether to start joysticks (virtual remote) (This our later study) & Buttons (button)

The Easytouch of Unity3d plug-in research

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.