Game Interface Elements 游戏界面元素

优质
小牛编辑
137浏览
2023-12-01

To create interface elements for your game, you have some options to choose from. You can use GUI Text and GUI Texture objects, or you can use UnityGUI. UnityGUI is the Interface Scripting system introduced in Unity 2.0.

为游戏创建界面元素,有一些可供选择的选项。可以使用GUI TextGUI Texture物体,或使用UnityGUI。UnityGUI是在Unity 2.0引入的界面脚本系统。

The rest of this page contains a detailed guide for getting up and running with UnityGUI.

本页包含一个入门细节指南和UnityGUI运行。

GUI Scripting Guide 用户图形界面脚本指南

Overview 概述

GUI stands for Graphical User Interface. Unity's GUI system is called UnityGUI. UnityGUI allows you to create a huge variety of GUIs complete with functionality very quickly and easily. Rather than creating a GUI object, manually positioning it, and then writing a script that handles its functionality, you do all of this at once in a small amount of code. This works by creating GUI Controls, which are instantiated, positioned, and defined all at once.

GUI表示图形用户界面的简称。Unity的GUI系统被称为UnityGUI。UnityGUI可以创建种类繁多的GUI,非常快速方便地完成各种功能,而不是创建一个GUI对象,手动定位,并写脚本来处理它的功能,做这些只需要一次少量代码。这是通过创建GUI控件,实例化,定位,并一次全部定义。

For example, the following code will create a fully functional button from scratch:

例如,下面的代码将从头创建一个功能齐全的按钮:

function OnGUI () {
	if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
		print ("You clicked the button!");
	}
}


This is the button created by the code above 这是由上面的代码创建的按钮

Although this example is very simple, there are very powerful and complex techniques available for use in UnityGUI. It is a broad subject, and the following sections will help you get up to speed as quickly as possible. This guide can be read straight through, or used as reference material.

虽然这个例子很简单,在UnityGUI是使用非常强大和复杂的技术。这是一个笼统的讨论主题,在下列各节将帮助你尽可能加快速度学习。本指南应从头至尾阅读,或作为参考资料。

UnityGUI Basics 图形用户界面基础

This section covers the important concepts of UnityGUI, giving you an overview as well as a bunch of working examples you can paste into your own projects. UnityGUI is very friendly to play with, so this is a good place to get started.

本节涵盖UnityGUI的重要概念,概述以及一堆工作的例子,可以将其粘贴到您自己的项目中。UnityGUI非常好用,以便发挥,因此,这里是入门的好地方。

Controls 控件

This section lists every available Control in UnityGUI. It is complete with code examples and images.

本节列出了每一个可用的在UnityGUI控件,有完整的代码示例和图像。

Customization 自定义

Creating functional GUI controls would not be as useful if their appearances couldn't be customized. Thankfully, we've thought of this. All controls in UnityGUI can be customized with GUIStyles and GUISkins. This section explains how to use them.

如果它们的外观不能定制,创建功能性GUI控件不会有什么用。值得庆幸的是,我们已经想到了这一点。在UnityGUI所有控件都可以自定义,并具有GUIStyles 和 GUISkins。

Layout Modes 布局模式

UnityGUI features two ways to arrange your GUIs. You can manually place each control on the screen, or you can use an Automatic Layout system which works a lot like HTML tables. Using one system or the other is as simple as using a different class, and you can mix the two together. This section explains the functional differences between the two systems, including examples.

UnityGUI功能有两种方式来排列GUI。一种是手动在屏幕上方在每一个控件,一种是使用自动布局系统,有点像HTML表格。可以使用一种或另一种方式,但也可以两种混合一起使用。这节讲述了两种系统不同的功能,包含一些例子。

Extending UnityGUI 扩展UnityGUI

UnityGUI is very easy to extend with new Control types. This chapter shows you how to make simple compound controls - complete with integration into Unity's event system.

UnityGUI很容易扩展新的控件类型,本节讲述如何制作简单的复合控件,并整合到Unity的事件系统。

Extending Unity Editor 扩展Unity编辑器

The main Unity editor is written using UnityGUI. It is completely extensible using the same code as you would use for in-game GUI. In addition, there are a bunch of Editor specific GUI widgets to help you out when creating custom editor GUI.

主要Unity编辑器是使用UnityGUI编写。使用相同的代码,它是完全可扩展,会用于游戏GUI。此外,有一堆编辑器特定GUI部件来帮助你创建自定义编辑器GUI。

页面最后更新:2007-11-16