Unity GUI控件(一)——Box控件

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_39485740/article/details/102537075

GUI控件(一)

Box控件

构造函数:

构造Box的函数有以下几种:

public static void Box(Rect position, string text);
public static void Box(Rect position, Texture image);
public static void Box(Rect position, GUIContent content);
public static void Box(Rect position, string text, GUIStyle style);
public static void Box(Rect position, Texture image, GUIStyle style);
public static void Box(Rect position, GUIContent content, GUIStyle style);

各个参数的含义:

position:	在屏幕上画一个矩形用来显示Box
text:		在Box上显示的文本
content:	在Box上显示的内容,内容可以是文本,图片,提示条
image:		在Box上显示的材质
style:		绘制Box的样式。

样例:

using UnityEngine;
using System.Collections;

public class box_script : MonoBehaviour {

	public Texture BoxTexture;

	private GUIContent content;

	private GUIStyle style;
	// Use this for initialization
	void Start () {
		content = new GUIContent ("This is a box", BoxTexture, "This is a toolTip");
		style = new GUIStyle ();
		style.alignment = TextAnchor.MiddleLeft; 
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void OnGUI () {
		GUI.Box (new Rect (100, 30, Screen.width, 30), "Hello World");

		GUI.Box (new Rect (100, 70, BoxTexture.width, 30), BoxTexture);

		GUI.Box (new Rect (100, 110, Screen.width, 30), content);

		GUI.Box (new Rect (100, 150, Screen.width, 30), "Hello Unity", style);
	}
}

效果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_39485740/article/details/102537075
今日推荐