NGUI is a Unity (professional and free) Plug-in written in C #. It provides a powerful UI system and Event Notification framework.
To use the NGUI plug-in for development in unity3D, follow these steps:
1. First download the free NGUI plug-in. If you have money, you can download the Professional Edition!
: Http://www.tasharen.com/get.php? File = NGUI
2. Import the downloaded NGUI plug-in Unity3d. After the import is complete, remember to refresh the refresh to refresh the NGUI.
3. After the import is complete, find open the UI wizard in the menu NGUI and create
4. After adding the widget, continue to find the open the widget wizard in the NGUI menu, and add the button and label to be used by the calculator.
5. After adding the image, adjust the interface to get the desired effect.
6. Add the C # script calc. cs and write the code as follows:
Using UnityEngine; using System. collections; public class calc: MonoBehaviour {public string strPutkeyCode; public UILabel strResult; // The result shows public static string str1; // The first operand public static string str2; // The second operand public static string strOpt; // mark the addition, subtraction, multiplication, and division sign int sum = 0; // calculation result void OnClick () {if (strPutkeyCode = "= ") // when press =, {if (strOpt = "/") {sum = int. parse (str2)/int. parse (str1);} else if (strOpt = "*") {sum = int. pa Rse (str1) * int. parse (str2);} else if (strOpt = "+") {sum = int. parse (str1) + int. parse (str2);} else if (strOpt = "-") {sum = int. parse (str2)-int. parse (str1);} str1 = ""; str2 = sum. toString (); Debug. log (sum); strResult. text = sum. toString ();} if (strPutkeyCode = "CE") // clears {Debug. log ("CE"); strResult. text = "0"; sum = 0; str1 = ""; str2 = "";} if (strPutkeyCode = "B") // delete a number {Debug. log ("B"); str1 = str1.Substring (0, str 1. length-1); if (str1 = "") {strResult. text = "0"; return;} strResult. text = str1;} if (strPutkeyCode = "/" | strPutkeyCode = "*" | strPutkeyCode = "-" | strPutkeyCode = "+ ") {strOpt = strPutkeyCode; // record the operator pressed, and assign the original operand str1 to the operand str2if (str1! = "") {Str2 = str1;} strResult. text = str2; Debug. log ("code ---"); str1 = "";} if (strPutkeyCode = "1" | strPutkeyCode = "2" | strPutkeyCode = "3" | strPutkeyCode = "4" | strPutkeyCode = "5" | strPutkeyCode = "6" | strPutkeyCode = "7" | strPutkeyCode = "8" | strPutkeyCode = "9" | strPutkeyCode = "0") {str1 + = strPutkeyCode; // concatenate the number strResult. text = str1; Debug. log (str1) ;}}// Use this for initializationvoid Start (){}}
7. The last thing left is the object binding. BIND (drag) the script calc. cs and label to each button and assign a key value to the button.
The result is as follows:
Download Code: http://download.csdn.net/detail/wyz365889/5753403