Unity New UI Event System (EventSystem) Demo

Source: Internet
Author: User

New UI system messaging is designed with Monobehaviour to implement a custom interface so that callbacks from the message system can be accepted. When an object is specified by the execution of the message, all scripts that implement the custom interface for this object will be notified, and the specified method will be executed.

1. Define an interface icustommessagetarget inherit Ieventsystemhandler, so that when this type of message is sent, the object that implements the script for this interface will be notified.

using Unityengine; using Unityengine.eventsystems; using System.Collections;  Public Interface icustommessagetarget:ieventsystemhandler{    void  Message1 ();     void Message2 ();}

2. Test script Custommessagetarget implement Icustommessagetarget, add to an object.

usingUnityengine;usingSystem.Collections; Public classCustommessagetarget:monobehaviour, icustommessagetarget{ Public voidMessage1 () {Debug.Log ("Message1 received."); }     Public voidMessage2 () {Debug.Log ("Message2 received."); }}

This event is triggered when the following code is executed

null, (x, y) = = X.message1 ());

EventSystem also provides a number of events that can be triggered by simply implementing these interfaces in the script.

  • Ipointerenterhandler-onpointerenter-called when a pointer enters the object
  • ipointerexithandler-onpointerexit-called when a pointer exits the object
  • Ipointerdownhandler-onpointerdown-called when a pointer was pressed on the object
  • Ipointeruphandler-onpointerup-called when a pointer was released (called on the original The pressed object)
  • Ipointerclickhandler-onpointerclick-called when a pointer are pressed and released on the same object
  • Iinitializepotentialdraghandler-oninitializepotentialdrag-called when a drag target was found, can be used to Initialis E values
  • Ibegindraghandler-onbegindrag-called on the Drag object when dragging are about to begin
  • Idraghandler-ondrag-called on the Drag object if a drag is happening
  • Ienddraghandler-onenddrag-called on the Drag object when a drag finishes
  • Idrophandler-ondrop-called on the object where a drag finishes
  • iscrollhandler-onscroll-called when a mouse wheel scrolls
  • Iupdateselectedhandler-onupdateselected-called on the selected object each tick
  • iselecthandler-onselect-called when the object becomes the selected object
  • Ideselecthandler-ondeselect-called on the selected object becomes deselected
  • imovehandler-onmove-called When a move event occurs (left, right, up, down, ect)
  • isubmithandler-onsubmit-called when the submit button is pressed
  • icancelhandler-oncancel-called when the Cancel button is pressed

Example:

usingUnityengine;usingSystem.Collections;usingUnityengine.eventsystems; Public classTestpointerenterevent:monobehaviour, Ipointerenterhandler, ipointerclickhandler{ Public voidonpointerenter (pointereventdata data) {Debug.Log ("Pointer Enter."); }     Public voidOnpointerclick (pointereventdata data) {Debug.Log ("Pointer Click."); }}

Unity New UI Event System (EventSystem) Demo

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.