"Turn" [Unityui]ugui-ray inspection

Source: Internet
Author: User

http://blog.csdn.net/lyh916/article/details/50947026

1.Graphic Raycaster

Primarily for Ray detection on the UI, objects with this component must be hung on canvas (the canvas will automatically hang when graphic raycaster is hung).

Ignore reversed Graphics: whether to ignore the inverse direction of the graphic, if true, indicates that the graphic front of the display, will receive a ray detection, negative display, do not receive radiographic inspection; otherwise, the positive and negative display will receive a ray detection

Blocking Objects: Masks (physical) objects of the specified type so that they do not participate in Ray detection. Rendering mode does not work when screenspaceoverlay. The optional values are:
None: Do not block any physical objects
D: Block 2D physical objects (that is, objects with 2D collisions)
Three D: Masking 3D physical objects (i.e. objects with 3D collisions)

All: Block all Object objects

Blocking Mask: Causes the specified layer in the masked object not to participate in radiographic inspection. The rendering mode is not screenspaceoverlay, and blocking objects does not work when it is none.
For example, Blocking objects is a UI for 2d,blocking mask, meaning that anything in a 2D physical object that is in the UI layer will not receive ray detection, while the other layers in the 2D physical object will still be able to receive Ray detection


2.Physics Raycaster & physics2d Raycaster

It is mainly used for Ray detection on physical objects, and objects with this component must be hung onto the camera component (the camera will automatically hang when the component is attached). When an object (2D or 3D physical object) is detected by a ray, the method that implements the event interface on the object is called


Physics Raycaster: Only affects 3D object objects, camera projection, as far as possible to choose perspective (Perspective) mode
Physics2d Raycaster: Only affects 2D object objects, camera projection, as far as possible to choose orthography (orthogonal) mode
Eventmask: A ray-acting layer that can be used to do event masking

3.Selectable

Selectable means optional, it is the base class for many interactive controls (Button/slider/inputfield/toggle/scrollbar/) in Ugui, where interactable, when the value is false, The UI control enters the Disable state (the color becomes the color of disabled color), but the UI control can still receive the ray detection!

4.CanvasGroup

Used to manage the control in bulk and the UI controls under the control. Interactable The meaning above has been said, and blocks raycasts, if False, the UI control can not receive Ray detection

Ray penetration:

For example, button and image both implement the Click interface, if you want to click on the overlap between the two, the button event is not triggered, and the event of the image is triggered, the method is:

Attach the canvas group component to the button and uncheck blocks raycasts

5. Determine if the mouse or finger is clicked on the UI

For EventSystem.current.IsPointerOverGameObject this function, because EventSystem is the UI's event system, Gameobject in Ispointerovergameobject is for the UI, not the Universal Gameobject in the sense of

[CSharp]View PlainCopy 
  1. Using Unityengine;
  2. Using Unityengine.ui;
  3. Using Unityengine.eventsystems;
  4. Public class Testtouch:monobehaviour {
  5. public text text;
  6. void Update ()
  7. {
  8. if (input.getmousebuttondown (0) | |  (Input.touchcount > 0 && input.gettouch (0). Phase = = Touchphase.began))
  9. {
  10. #if Unity_android | | Unity_iphone
  11. if (EventSystem.current.IsPointerOverGameObject (Input.gettouch (0). Fingerid))
  12. #else
  13. if (EventSystem.current.IsPointerOverGameObject ())
  14. #endif
  15. Text.text = "Current touch on UI";
  16. Else
  17. Text.text = "There is currently no touch on the UI";
  18. }
  19. }
  20. }

"Go" [Unityui]ugui-ray detection

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.