Easytouch and ngui usage experience

Source: Internet
Author: User

Today, I will write two commonly used plug-ins in unity3d: easytouch and ngui. The versions I used are easytouch 3.1.1 and ngui 3.6.0 respectively. The following are my learning experiences on these two versions.

1. easytouch

Easytouch is a plug-in for the touch screen. It provides a virtual touch button, which consists of three parts: a joystick, a button, and a touch response.

1.1 easytouch joystick

This joystick controls the movement of the objects you want to control by sliding your fingers in the joystick area. When your fingers move to the joystick, you can use the variables of the movingjoystick class to obtain the movement sensitivity. Of course, there are also a lot on the tutorial network, which is not detailed here, but a simple description of the main process. When using this function, you must first add an event function: easyjoystick. on_joystickmove + = onjoystickmove; onjoystickmove is the function name and must be implemented by yourself. The prototype of this function must be void onjoystickmove (movingjoystick move), which receives a variable of movingjoystick, you can move. joystickaxis. X and move. joystickaxis. Y gets the moving distance between the left and right sides. Here, X corresponds to the X axis in unity3d (left and right movement direction), and y object's Z axis in unity3d (forward and backward direction ), in this way, we can control the movement of objects. Using a joystick to control an object also has other methods. You can assign a value to the object that needs to be moved directly through the Inspector panel without writing code. I have never used it, so I won't talk about it here.

1.2 easytouch button

Easytouch also provides buttons. You can directly create a button through the operation, and specify the corresponding event and the texture of the button.

Easytouch provides two interfaces: normal texture and active texture, which are the texture of the buttons when the buttons are pressed.

The easytouch button is also very convenient to add events. Find the receiver object in the Inspector panel and drag the object you want to receive the message here, then, write the function name in the down method name (without parentheses). When you press the button, it will search for the function in the script of the recipient object you specified, then execute.

However, the disadvantage of easytouch is that the appearance of the button is specified by texture. If you want to add text on the button, or you can only re-load the new texture to transform the text above the game. You can use resource to load the new texture. load function. You can use the following code. Note that the first parameter in resource. load is the texture name. You can find the texture in the resources directory under assets. You can use ongui, ngui, or the texture of your own PS button to add text to the button.

EasyButtonName.ActiveTexture = Resources.Load("ActiveTexturePath", typeof(Texture2D)) as Texture2D;

1.3 easytouch

The main function of easytouch is to provide the touch behavior of fingers on the screen, including pressing, double-clicking, long-pressing, and dragging. I used slide, that is, sliding my fingers on the screen to control the rotation of the camera.

Easytouch needs to be added to the function that triggers the slide operation. on_swipestart and easytouch. on_swipe and easytouch. the on_swipeend method indicates the start, center, and end methods of the sliding operation. If you do not need to start or end the sliding operation, you can also choose not to add them. The prototype of these methods is void onswipe (gesture). The number of slides can be obtained through gesture. deltaposition. X and gesture. deltaposition. X.

  Finally, let's talk about a bug in easytouch in this version:This bug occurs when one hand uses a joystick and the other is slide on the screen to control the camera's angle of view. This bug occurs on mobile phones: when you open the control joystick hand, you find that the joystick is not reset, but stuck on the edge of the joystick area, and the controlled objects are still moving. It is difficult to reproduce the problem on the computer because the computer only has one mouse point, which generally does not trigger this bug. Therefore, this bug is very strange when it occurs on the mobile phone, I don't know why. How to reproduce on the computer: Move the joystick with the mouse, hold down the mouse, do not move, and then press the ctrl key (such as setting), the screen will show a yellow dot, move the mouse while holding the mouse. The unity3d Console window is displayed with a red letter indicating the error: nullreferenceexception: object reference not set to an instance of an object.

After searching, we found a solution:

Replace line 1193:

1 gesture.isHoverReservedArea = IsTouchReservedArea( fingers[twoFinger0].fingerIndex) || IsTouchReservedArea( fingers[twoFinger1].fingerIndex);

By

1 if (fingers[twoFinger0] != null){2     gesture.isHoverReservedArea = IsTouchReservedArea( fingers[twoFinger0].fingerIndex);3 }4 if (fingers[twoFinger1] != null){5     gesture.isHoverReservedArea = gesture.isHoverReservedArea || IsTouchReservedArea( fingers[twoFinger1].fingerIndex);6 }

And replace line 1181 1182:

1 gesture.pickCamera = fingers[twoFinger0].pickedCamera;2 gesture.isGuiCamera = fingers[twoFinger0].isGuiCamera;

By

1 if (fingers[twoFinger0] != null){2     gesture.pickCamera = fingers[twoFinger0].pickedCamera;3     gesture.isGuiCamera = fingers[twoFinger0].isGuiCamera;4 }5 else if (fingers[twoFinger1] != null){6     gesture.pickCamera = fingers[twoFinger1].pickedCamera;7     gesture.isGuiCamera = fingers[twoFinger1].isGuiCamera;             8 }

You can also click the URL above to view his reply directly. Easytouch writes it here first. Next we will briefly introduce the ngui usage experience.

2. ngui

Ngui is used to create the UI. Why not use the ongui provided by unity3d? It is said on the Internet that the ongui will be called multiple times within one frame, resulting in very low efficiency, especially when it comes to the mobile platform, it is even more obvious that I have not done a very complex UI, and I still feel this way, but to adapt to the mobile platform, I still learned ngui.

For the new ngui version, the entire interface, operations, and usage have changed a lot. Many online tutorials cannot keep up with the version changes. Here, I can only find out what I have learned, let's take a rough look at the process of making the ngui button.

To create an ngui, You can first create a 2D or 3D interface by clicking the button shown in.

After you click 2D ui or 3D UI, the UI root or UI root (3D) will appear in hierarchy. Here we take 2D as an example. 3D is complicated. The UI root contains a camera that is used to display the UI. We can control the camera's culling Mask by setting it to only display the layer we specify for the UI root and the following sub-objects, then let main camera not display these layers, so that you may see multiple UIS in the game. Next, create a panel under the UI root and place a group of buttons on the panel to facilitate unified management. If you do not want to create a panel, you can also. Create a Sprite and add the ngui-provided button script (used to set the corresponding button and display it as uibutton) and box Collider (used for corresponding clicks) to the object ), one way to set the response function of the button is to drag an object here. After dragging an object, meshod will be displayed under policy, you can select a public method defined in the script of this object as the corresponding function,The public method must be used.Otherwise, it cannot be found in the method.

You can create a label to create the text on the button. Of course, buttons can also have various animations. For more information, see ngui's built-in example, which provides many examples.

In addition, for anchor, the old ngui version needs to put the buttons or objects under an anchor. It is not used in the new version. Anchors has been integrated in many ngui scripts, as shown below, you can set the location in this way.

Today, let's write so much about ngui, which is easy to write. If there are any errors in this article, please correct them.

 

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.