Unity Ugui Message Transmission

Source: Internet
Author: User

The company is going to do one of these things.

A is the sliding area, the Scrollrect component.

B is a variety of options.

C is the option to pick up the mouse (or contact).

D is the drag-and-drop area.

That's probably the requirement.

Because B has a lot of entries, you can swipe to see them in a. If you want to select a B, you need to press B long enough to produce a new c after sufficient time. Drag to the D zone to release, then add a node to D. Other areas are canceled.

If the time to hold B is not long enough and the mouse (or contact) is moved, the current slide operation is responded by a, resulting in a sliding effect.

There is a problem with the transmission of the message.

Explain the 2 scenarios and their problems that you are using in your own process.

The functions involved are as follows:

Onpointerdown

Onpointerup

Ondrag

Put the final result here, you don't want to read, go straight to take things out.

The message resets the code.

Eventdata.pointerenter = m_scro.gameobject;eventdata.pointerpress = M_scro.gameobject;eventdata.rawpointerpress = m_ Scro.gameobject;eventdata.pointerdrag = M_scro.gameobject;m_scro.onbegindrag (EventData);

Scenario 1:

win7+unity531.

The 531 version that was used when it was first opened. Some tests have been done on this version. Get the following data:

  1. With EventTrigger, only the topmost UI can get input and call functions that EventTrigger set.
  2. If you do not use EventTrigger, you need to inherit some classes yourself. What classes you need can be queried in eventtrigger based on the functions you need. For example, you used the pointer up message in EventTrigger. Query Pointerup directly in the script category of the Unity document to find out which class the message is distributed from, inherit it, and rewrite the function yourself.
  3. If you do not use EventTrigger to work in a way that inherits the message class, does the UI respond with input from Raycast Target This option is determined. (The use of EventTrigger is not measured, because that can not meet the demand.) )
  4. when you are done with a UI, by default, all mouse (or contact) actions are received by the UI control, without any modifications or special handling. For example, in this control Onpointerdown, and then hold the mouse, the mouse to move to another UI, and then release,Onpointerup function is still called the Onpointerdown when the UI.
  5. If you inherit only the Onpointerdown and The Onpointerup function. the Onpointerup event is generated if the drag input is generated when the Onpointerdown enters .
  6. In the case of inheriting the message class and the above information, a can be dragged normally, even in the case of B. And the function of B shines in.
  7. The drag-and-drop action response function is OnDrop and follows the fourth rule. But if I want other controls to respond to OnDrop, just set the raycast target of the currently moving UI to false. (In fact, it is already a kind of news transmission)

Based on the above information, I did the first set of scenarios:

Roughly as follows:

    • When I press B, turn on a co-process (wait for 1s, long by time). If the Onpointerup is not processed before the process is reached, the process is destroyed. Succeeds, a C is generated, and the A setting is set to False to prevent a from moving when I move c.
    • The generated C is given to a global manager, which has a M_drag Gameobject object. When the object is not empty, the position of the object is updated in the update frame. Use this method to implement the drag.
    • Then set a OnDrop function for D. If the OnDrop function is called, the global manager is notified that C has been fetched and cleaned.
    • Global Manager to determine if there is no contact (using the Input.getmousebutton (0) function can meet this requirement, although there is an unexpected situation, but at least positive process OK), the destruction of M_drag

According to the above ideas, most of the situation has been solved. There is just one problem. The contact decision of the global manager is in the update. And the ondrop is triggered. Logic is ondrop after the response to do its own processing, and notifies the global manager to empty M_drag one to prevent being destroy. It is not known whether the current message processing is before or after the update. If the mouse contact has been released at the current frame and entered update first, the M_drag will be destroy by the update before OnDrop is triggered. If OnDrop is called first, you can ensure that it is normal.

At 531, the test results show that the input of the current frame is processed before the update, so the scenario is complete.

Merge code, the other side used 535, so I had to follow the rise, this one liter, bad. Drag the problem, dragged out to put it in.

A check, OnDrop ran to update after the execution went.

In this way, there is no suitable place to judge the release of the mouse (or contact). So I had to consider using Onpointerup good. But Onpointerup is called when the control is dragged, there is no chance or right place to generate the call of the Onpointerup function, and then some tests are done as follows:

    1. If only the Onpointerdown and Onpointerup functions are inherited. The Onpointerup event is generated if the drag input is generated when the Onpointerdown enters. However, if you inherit Ondrag again, you will enter the Ondrag event instead of the Onpointerup. The Onpointerup will be generated when the mouse bounces (or the contacts are released).

This is a supplement to article Fifth of the programme. Also joined Ondrag after gradually discovered, the middle also debugging for a long time, out a lot of trouble things.

With this one, it seems that everything is fine. So add, test, everything OK. Seems to be done. Then I find that a is no longer getting input when it is point to B. In other words, when I point to B, a cannot be slid. The drag message was passed to the B script.

Note: In this step, I did not try to close the Raycast target method to solve. There are 2 reasons:

    1. I need Onpointerup, and if it is off, Onpointerup will not respond because if you can pass drag to a by closing raycast target, then B is no longer getting input.
    2. I need to completely solve the problem of message transmission, in case there are other modules will also encounter similar situation?

So can not be avoided, considering the future may also be used, had to hard, must solve the problem of the transmission of the message.

Now there are 2 ideas:

    1. Get to the component I want to control, within the current UI, pass the input information to the component to be controlled, and then modify it. (This is to get the drag information in B and pass the drag information to the A object to control the sliding of a)
    2. Resets the input message. Or create a new one, or put the component I want to get input into.

It turned over for a long time. EventSystem, Baseeventdata, pointereventdata all turned over, did not find.

So the first way of thinking is adopted. The first line of thought is also very easy. Maybe there's no problem with the other UI.

But the most sad thing is scrollrect this component, if you change the coordinates of its container in an external way (that is, the direct script), it bounces back. And then to find out how to cancel the scrollrect of the rebound operation. A series of processing down, it seems to meet the requirements. However, because of the first use of Ugui, there is no good plan to let me in the message through the time to let Scrollrect do not bounce back, and when my message through the end of the launch back. Even if there is a small bounce on the interface, it is impossible to look directly.

And then I thought. Or look again, and then swish and see if we can reset the message. After all, this is the right path.

And then untie it. I'm not going to tell you how to find it, it's sheer luck. I found a Pointerdrag object when I looked at the object of the EventSystem scene. It's just the object I'm dragging, and I'm thinking, what if I get rid of him?

So the script in a search Pointerdrag, under the Pointereventdata class. This is the argument that the message function passed in. So the Pointerdrag directly changed to a, good, all work normal, is still beating. Speculation may be caused by a sudden addition of input information, without preconditions. So will scrollrect drag function query, just have a onbegindrag, plus, everything is normal.

Eventdata.pointerenter = m_scro.gameobject;eventdata.pointerpress = M_scro.gameobject;eventdata.rawpointerpress = m_ Scro.gameobject;eventdata.pointerdrag = M_scro.gameobject;m_scro.onbegindrag (EventData);

This is the message reset.

is when holding down B is not enough time, resulting in a drag, to the current drag message to a processing core code.

Other messages should also be similar.

Unity Ugui Message Transmission

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.