Here are the examples of the csharp api UnityEngine.GUI.Button(UnityEngine.Rect, UnityEngine.Texture) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
19
View Source File : GUIInterface.cs
License : MIT License
Project Creator : BelkinAndrey
License : MIT License
Project Creator : BelkinAndrey
void OnGUI()
{
GUI.skin = skin;
GUI.Box(new Rect(0, 0, Screen.width, 30), "");
if (GUI.Button(new Rect(0, 0, 140, 30), LogoButton))
{
Application.OpenURL("https://github.com/BelkinAndrey/OPENTadpole");
}
GUI.Label(new Rect(150, 5, 170, 30), ">> ConnectomTadpole <<");
if (GUI.Button(new Rect(325, 0, 115, 30), " SimWorldTadpole"))
{
Application.LoadLevel(1);
}
if (GUI.Button(new Rect(Screen.width - 30, 0, 30, 30), CloseButton))
{
Application.Quit();
}
if (GUI.Button(new Rect(Screen.width - 60, 0, 30, 30), FullButton))
{
if (!Screen.fullScreen)
{
W = Screen.width;
H = Screen.height;
Screen.fullScreen = true;
Screen.SetResolution(resolutions[resolutions.Length - 1].width, resolutions[resolutions.Length - 1].height, true);
}
else
{
Screen.fullScreen = false;
Screen.SetResolution(W, H, false);
}
}
GetComponent<SaveOpen>().PathFile = GUI.TextField(new Rect(Screen.width - 260, 5, 180, 20), GetComponent<SaveOpen>().PathFile);
if (GUI.Button(new Rect(Screen.width - 80, 0, 20, 30), DownButton))
{
pilot = !pilot;
}
if (GUI.Button(new Rect(Screen.width - 350, 0, 30, 30), ClearButton))
{
PlayerPrefs.SetString("Path", "");
PlayerPrefs.SetFloat("StartZoom", 3200);
PlayerPrefs.SetFloat("CamX", 0);
PlayerPrefs.SetFloat("CamY", -1840);
PlayerPrefs.SetFloat("CamZ", -100);
Application.LoadLevel(0);
}
if (GUI.Button(new Rect(Screen.width - 320, 0, 30, 30), OpenButton))
{
GetComponent<SaveOpen>().Open();
}
if (GUI.Button(new Rect(Screen.width - 290, 0, 30, 30), SaveButton))
{
GetComponent<SaveOpen>().Save();
}
if (pilot)
{
Rect RectPilot = new Rect(Screen.width - 260, 35, 200, 200);
OnRect = RectPilot.Contains(Event.current.mousePosition);
GUILayout.BeginArea(RectPilot, GUI.skin.box);
ScrollBlok = GUILayout.BeginScrollView(ScrollBlok, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
string[] dir = Directory.GetFiles(Application.dataPath + "/Data/", "*.tad");
foreach (string value in dir)
{
GUILayout.BeginHorizontal();
string v = value.Remove(value.Length - 4).Remove(0, Application.dataPath.Length + 6);
if (GUILayout.Button(v))
{
GameObject C = GameObject.Find("Camera");
PlayerPrefs.SetFloat("StartZoom", C.GetComponent<Camera>().orthographicSize);
PlayerPrefs.SetFloat("CamX", C.transform.position.x);
PlayerPrefs.SetFloat("CamY", C.transform.position.y);
PlayerPrefs.SetFloat("CamZ", C.transform.position.z);
PlayerPrefs.SetString("Path", v);
Application.LoadLevel(0);
}
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView();
GUILayout.EndArea();
}
}
19
View Source File : GUIInterfaceWorld.cs
License : MIT License
Project Creator : BelkinAndrey
License : MIT License
Project Creator : BelkinAndrey
void OnGUI()
{
GUI.skin = skin;
GUI.Box(new Rect(0, 0, Screen.width, 30), "");
if (GUI.Button(new Rect(0, 0, 140, 30), LogoButton))
{
Application.OpenURL("https://github.com/BelkinAndrey/OPENTadpole");
}
GUI.Label(new Rect(150, 5, 170, 30), ">> SimWorldTadpole <<");
if (GUI.Button(new Rect(325, 0, 125, 30), " ConnectomTadpole"))
{
Application.LoadLevel(0);
}
if (GUI.Button(new Rect(Screen.width - 30, 0, 30, 30), CloseButton))
{
Application.Quit();
}
if (GUI.Button(new Rect(Screen.width - 60, 0, 30, 30), FullButton))
{
if (!Screen.fullScreen)
{
W = Screen.width;
H = Screen.height;
Screen.fullScreen = true;
Screen.SetResolution(resolutions[resolutions.Length - 1].width, resolutions[resolutions.Length - 1].height, true);
}
else
{
Screen.fullScreen = false;
Screen.SetResolution(W, H, false);
}
}
GetComponent<LoadBrain>().PathFile = GUI.TextField(new Rect(Screen.width - 260, 5, 180, 20), GetComponent<LoadBrain>().PathFile);
if (GUI.Button(new Rect(Screen.width - 80, 0, 20, 30), DownButton))
{
pilot = !pilot;
}
if (GUI.Button(new Rect(Screen.width - 320, 0, 30, 30), ReStartButton))
{
Application.LoadLevel(1);
}
if (GUI.Button(new Rect(Screen.width - 290, 0, 30, 30), OpenButton))
{
GetComponent<LoadBrain>().Open();
}
if (pilot)
{
Rect RectPilot = new Rect(Screen.width - 260, 35, 200, 200);
OnRect = RectPilot.Contains(Event.current.mousePosition);
GUILayout.BeginArea(RectPilot, GUI.skin.box);
ScrollBlok = GUILayout.BeginScrollView(ScrollBlok, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
string[] dir = Directory.GetFiles(Application.dataPath + "/Data/", "*.tad");
foreach (string value in dir)
{
GUILayout.BeginHorizontal();
string v = value.Remove(value.Length - 4).Remove(0, Application.dataPath.Length + 6);
if (GUILayout.Button(v))
{
PlayerPrefs.SetString("Path", v);
Application.LoadLevel(1);
}
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView();
GUILayout.EndArea();
}
}
19
View Source File : ViewControl.cs
License : MIT License
Project Creator : codeyuan666
License : MIT License
Project Creator : codeyuan666
void OnGUI (){
var screenW = Screen.width;
var screenH = Screen.height;
if(GUI.Button (new Rect((screenW-200)/2, screenH-250, 200, 200), magicTexture)){
magicBall = GameObject.Instantiate (magicBallObj);
magicBall.transform.position = Camera.main.transform.position;
magicBall.transform.rotation = Camera.main.transform.rotation;
StartCoroutine (WaitAndRunWithSecond (2));
}
if(GUI.Button (new Rect(screenW-190, screenH-200, 170, 170), findTexture)){
DestroyObject(spriteBall);
if (getRandomValue ()) {
// 从屏幕中心发送射线
Vector3 shootPos = Camera.main.ScreenToViewportPoint (new Vector3 (screenW / 2, screenH / 2));
ARPoint shootPoint = new ARPoint {
x = shootPos.x,
y = shootPos.y,
};
// 开始命中测试,类型为利用现有的平面的范围
List<ARHitTestResult> results = m_session.HitTest (shootPoint, ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent);
if (results.Count > 0) {
tipStr = "已找到精灵球!";
// 创建一个对象,并根据结果初始化对象的位姿
spriteBall = GameObject.Instantiate (spriteBallObj);
spriteBall.transform.position = UnityARMatrixOps.GetPosition (results [0].worldTransform);
spriteBall.transform.rotation = UnityARMatrixOps.GetRotation (results [0].worldTransform);
}
} else {
tipStr = "未找到精灵球,请再尝试!";
}
}
// 显示分数
GUIStyle scoreStyle = new GUIStyle ();
scoreStyle.normal.background = fontTexture;
scoreStyle.alignment = TextAnchor.MiddleCenter;
scoreStyle.fontSize = 120;
GUI.Label(new Rect(20, screenH-200, 170, 170), scoreNum.ToString(),scoreStyle);
// 显示提示信息
GUIStyle tipStyle = new GUIStyle ();
tipStyle.normal.background = fontTexture;
tipStyle.alignment = TextAnchor.MiddleCenter;
tipStyle.fontSize = 30;
GUI.Label (new Rect (50, 50, screenW - 100, 100), tipStr, tipStyle);
}