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