Ngui Study Summary Notes

Source: Internet
Author: User

Learning Ngui has been intermittent and currently intends to make a summary of the notes.

I'm using the older version of 3.6.0.

1. Using Ngui, you need to turn on the "Raycasts hit tiggers" option in "Edit", "Project Settings", "Physics", otherwise you will not be able to use the interactive system, which is now turned on by default.

2.NGUI control to add the Box Collider component to accept interactive events;

3. If you want the text on the button to change color depending on the state of the button, you can then add another button component to the button and set the target of the component to text;

4. If you need to use more interactive events, such as moving in and out, you can add Uieventtrigger scripts;

5. Example of adding Uieventtrigger events manually using code:

1 usingUnityengine;2 usingSystem.Collections;3 4  Public classAddevent:monobehaviour5 {6     Privategameobject button;7 8     //passed Parameters9      Public floatnum =123.456f;Ten  One     voidStart () A     { -button = Gameobject.find ("UI Root/sprite"); -  the         //Get Components -Uieventtrigger et = button. Getcomponent<uieventtrigger>(); -  -         //Direct incoming method for callback +Eventdelegate ed1 =Neweventdelegate (OnButtonHoverOver1); - Et.onHoverOver.Add (ed1); +  A         //if the method has parameters, it must be set in the form of a string atEventdelegate Ed2 =NewEventdelegate ( This,"OnButtonHoverOver2"); -ed2.parameters[0] =NewEventdelegate.parameter ( This,"Num"); - Et.onHoverOver.Add (ED2); -     } -  -     Private voidOnButtonHoverOver1 () in     { -Debug.Log ("OnButtonHoverOver1"); to     } +  -     Private voidOnButtonHoverOver2 (floatp) the     { *Debug.Log ("OnButtonHoverOver2 P:"+p.tostring ()); $     }Panax Notoginseng}

Other events, such as the onclick of the button, are consistent.

NGUI list<eventdelegate> Xiao Keng

6. If the control cannot receive the event, you need to pay attention to the depth setting of the control, and the high depth will block to the low depth. For this scenario, you can turn on the debug mode of Ngui so that you can view the object that receives the mouse event.

7.ScrollView Usage Record:

    • For the ScrollView control, we can add more than one control to its interior, add boxcollider and Uidragscrollview scripts for the controls inside it, and scroll by dragging the inner object.
    • If you want to drag through a region instead of a specific display component, you can add a invisible Widget, take care not to add it as a child of ScrollView, drag it to the same size as the ScrollView, To add Boxcollider and Uidragscrollview scripts to it, the Uidragscrollview script can set the ScrollView object it controls so that you can drag scrollview through a region.
    • If you want objects in your scene to also receive events, you can add Uicamera scripts to the main camera. We add scripts for the objects in the scene that need to listen for events.

8. To drag the components in the ScrollView out of the implementation:

    1. Add a Dragdropitem script to the inner object, and the object can be dragged but still in ScrollView.
    2. Add a depth panel to add a dragdroproot script to it so that when objects in ScrollView are dragged out, they are added to the panel. However, when the mouse is released, the dragged object will still return to the ScrollView and will remain in the drag position.
    3. Add a grid for ScrollView and move all ScrollView subkeys into the grid, so that automatic sorting can be done, and the smooth tween can be checked for ease.
    4. The currently dragged object will return to the end, and we can choose sorting for horizontal so that the object will be aligned to the nearest position.
    5. Create a horizontal Scroll Bar, check Scroll view, locate the Scroll Bars in the UIScroll view component, assign the added horizontal scroll bar to the horizontal property to associate two objects.
    6. At this time we will find that the sprite in the horizontal drag scroll view is not a scrolling scroll view but a direct drag, to solve this problem only need to select the entire sprite, choose Uidrag Drop Item restriction for vertical can , indicating that the drag only supports vertical orientation.
    7. Let's take a look at how to drag an object from the scroll view to the specified place, we create a sprite and add a box Collider to it, and that's the destination we're going to drag to. Then add a Draganddropcontainer script for it.
    8. For a draganddropcontainer script that has a Reparent target property, we can create a grid and assign it to it so that all our dragged objects are added to the grid.

Ngui Study Summary Notes

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.