"Tgui" builds a unity-based UI library from scratch 01

Source: Internet
Author: User

As a beginner unity3d one months of small rookie, want to build a UI library is also quite crazy, but the eldest brother not to use Ngui, Then at that time Unity4.6 official version has not yet released (or I do not know that Unity4.6 has its own UI), and then the fearless write down, at present, although the function is very simple, the implementation of the control is very small, but as the purpose of practiced hand has been achieved, so put up to share.

--------------------------------------------------Split Line--------------------------------------------------

1.UI engine

The UI of course to do a set of core mechanisms, this thing called his UI engine, it is also very simple, that is, when the mouse click, the UI engine will trigger the Click event, when the mouse is sliding, will trigger the sliding event, click End will trigger the Click End Event, mouse move out will also trigger the corresponding event .... Wait a minute.

In fact, this is a mouse ray, put a script on the main camera, this script in the update each time a camera to the mouse on the screen position of the ray, and then hit by this ray of the object, will trigger the mouse to move the event, and then hit the mouse click on the left button, The mouse click event will be triggered ...

The specific core code is as follows:

Ray Ray=camera.main.screenpointtoray (input.mouseposition);//from Camera to screen if (Physics.raycast (Ray,out hit))// Ray Collision Detection {//        here write mouse click on if (Input.getmousebuttondown (0)) {}else if (...)//other event {}else//mouse over event {}}

Of course, the engine is not just these features, but this is the most basic function of the engine. UI engine is written by my classmates, has been encapsulated into a DLL, he added a WPF-like control mechanism-tunnel events, interested students can study.

http://download.csdn.net/detail/baijiajie2012/8237051

"Tgui" builds a unity-based UI library from scratch 01

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.