u3dgui开始按钮点了是输入框,文本,输入框等如何清除?_(:з」∠)_

您所在的位置: &
Unity3D教程:GUI的布局模式
Unity3D教程:GUI的布局模式
Unity3D教程手册
有两种方法让你去布置和组织你的GUI,一个是固定的,一个是活动的,所有GUI打头的例子都是固定的,要想使用活动的Layout,就得用GUILayout代替GUI.它同样也是写在OnGUI()函数里。
固定Layout是用在你预先设计好界面的时候,活动Layout工作在你不知道会有多少组件或者如何定位他们的时候,这里有个例子:
function&OnGUI&()&{&&&&GUI.Button&(Rect&(25,25,100,30),&&I&am&a&Fixed&Layout&Btton&);&&&&GUILayout.Button&(&I&am&an&Automatic&Layout&Button&);&&}&
在活动Layout模式里,你可以控制组件的位置,并组织他们。在固定模式下你可以把多个控件放进Groups中,在活动模式下可以把他们放在Areas, Horizontal Groups和Vertical Groups里。
固定Layout中的Groups
Groups 在固定Layout模式中起到组织可用项的,他让你在屏幕的一个区域中包含多个控件。你要把定义的控件放在GUI.BeginGroup()和 GUI.EndGroup()这对函数中间,所有控件的位置坐标都以Groups的0坐标为起点,假如你更改了group坐标,那么内部的控件也会跟随改变。
&&function&OnGUI(){&&GUI.BeginGroup&(Rect&(Screen.width&/&2&,&Screen.height&/&2&&&50,&100,&100));&&GUI.Box&(Rect&(0,0,100,100),&&Group&is&here&);&&GUI.Button&(Rect&(10,40,80,30),&&Click&me&);&&GUI.EndGroup&();&&}&
Group也可以嵌套,例如:
var&bgImage&:&Texture2D;&&&var&fgImage&:&Texture2D;&&&var&playerEnergy&=&1.0;&&&function&OnGUI&()&{&&&&&&GUI.BeginGroup&(Rect&(0,0,256,32));&&&&GUI.Box&(Rect&(0,0,256,32),&bgImage);&&&&&&GUI.BeginGroup&(Rect&(0,0,playerEnergy&*&256,&32));&&&&GUI.Box&(Rect&(0,0,256,32),&fgImage);&&&&GUI.EndGroup&();&&GUI.EndGroup&();&&}&
和我们熟知的if-else语句一样,相互最接近的begin和end为一组。
活动Layout-Areas
Areas只用于活动Layout模式.作用和固定模式下的Group一样。
在活动模式下,你可以定义Area的范围,也可以不定义。不定义的时候整个屏幕就是它的范围,如果手工定义了它的范围,那么它内部的控件将以Area的坐标为起始坐标。Unity3D教程手册
function&OnGUI&()&{&&GUILayout.Button&(&I&am&not&inside&an&Area&);&&GUILayout.BeginArea&(Rect&(Screen.width/2,&Screen.height/2,&300,&300));&&GUILayout.Button&(&I&am&completely&inside&an&Area&);&&GUILayout.EndArea&();&&}&
自动Layout - Horizontal and Vertical Groups
自动模式中还有还有两对组函数:GUILayout.BeginHoriztontal(),GUILayout.EndHorizontal(),GUILayout.BeginVertical(),和GUILayout.EndVertical().他们用在Area中,同样也是成对使用的。
其特点是Horiztontal中的控件呈水平排列,Vertical中的控件呈垂直排列。
var&sliderValue&=&1.0;&&var&maxSliderValue&=&10.0;&&function&OnGUI()&&{&&&&GUILayout.BeginArea&(Rect&(20,0,200,60));&&&&GUILayout.BeginHorizontal();&&&&if&(GUILayout.RepeatButton&(&Increase&max\nSlider&Value&))&&{&&maxSliderValue&+=&3.0&*&Time.deltaT&&}&&&&&&GUILayout.BeginVertical();&&GUILayout.Box(&Slider&Value:&&&+&Mathf.Round(sliderValue));&&sliderValue&=&GUILayout.HorizontalSlider&(sliderValue,&0.0,&maxSliderValue);&&&&GUILayout.EndVertical();&&GUILayout.EndHorizontal();&&GUILayout.EndArea();&&}&
用GUILayoutOptions去定义一些控件 比如可以控制按钮的长度,如:
function&OnGUI&()&{&&GUILayout.BeginArea&(Rect&(100,&50,&Screen.width&200,&Screen.height&100));&&GUILayout.Button&(&I&am&a&regular&Automatic&Layout&Button&);&&GUILayout.Button&(&My&width&has&been&overridden&,&GUILayout.Width&(95));&&GUILayout.EndArea&();&&}&
这里GUILayout.Width (95)就定义了按钮的长度为95。
原文链接:
【责任编辑: TEL:(010)】
关于的更多文章
Unity,也称Unity3D,是近几年非常流行的一个3D游戏开发引擎,跨
所以姑娘,让我们做一枚花见花开的程序媛。
刚刚开始接触java数组的人都会听到一句类似的话:java
9月的工作日被法定假日拆的零零散散,不知道各位的工
总结一下Java I/O文件读写基本类相关知识和概念。对于
JBuilder 2006是一款强大的Java企业级开发平台,其集成了几乎所有的Java技术,涵盖了软件开发生命周期的各个过程。本书深入浅出
51CTO旗下网站Version: 5.3 ()
LanguageEnglish
Script language
Select your preferred scripting language. All code snippets will be displayed in this language.
UnityEngine.UI
Inherits from:
Implements interfaces:
, , , , , , , , , ,
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Sumbission failed
For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Your email
Suggestion *
Submit suggestion
Description
A standard button that can be clicked in order to trigger an event.
See Selectable for selection states.
UnityEvent to be fired when the buttons is pressed.
Public Functions
Registered IPointerClickHandler callback.
Registered ISubmitHandler callback.
Inherited members
Static Variables
List of all the selectable objects currently active in the scene.
Enabled Behaviours are Updated, disabled Behaviours are not.
Has the Behaviour had enabled called.
The game object this component is attached to. A component is always attached to a game object.
The tag of this game object.
The Transform attached to this GameObject (null if there is none attached).
Disabling this lets you skip the GUI layout phase.
Should the object be hidden, saved with the scene or modifiable by the user?
The name of the object.
The AnimationTriggers for this selectable object.
Convenience function to get the Animator component on the GameObject.
The ColorBlock for this selectable object.
Convenience function that converts the referenced Graphic to a Image, if possible.
UI.Selectable.interactable.
The Navigation setting for this selectable object.
The SpriteState for this selectable object.
Graphic that will be transitioned upon.
The type of transition that will be applied to the targetGraphic when the state changes.
Public Functions
Calls the method named methodName on every MonoBehaviour in this game object or any of its children.
Is this game object tagged with tag ?
Returns the component of Type type if the game object has one attached, null if it doesn't.
Returns the component of Type type in the GameObject or any of its children using depth first search.
Returns the component of Type type in the GameObject or any of its parents.
Returns all components of Type type in the GameObject.
Returns all components of Type type in the GameObject or any of its children.
Returns all components of Type type in the GameObject or any of its parents.
Calls the method named methodName on every MonoBehaviour in this game object.
Calls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
Cancels all Invoke calls on this MonoBehaviour.
Invokes the method methodName in time seconds.
Invokes the method methodName in time seconds, then repeatedly every repeatRate seconds.
Is any invoke on methodName pending?
Starts a coroutine.
Stops all coroutines running on this behaviour.
Stops the first coroutine named methodName, or the coroutine stored in routine running on this behaviour.
Returns the instance id of the object.
Returns the name of the game object.
Transition the Selectable to the entered state.
Finds the selectable object next to this one.
Find the selectable object below this one.
Find the selectable object to the left of this one.
Find the selectable object to the right of this one.
Find the selectable object above this one.
Clear any internal state from the Selectable (used when disabling).
Is the selectable currently 'highlighted'.
UI.Selectable.IsInteractable.
Unset selection and transition to appropriate state.
See MonoBehaviour.OnDisable.
Determine in which of the 4 move directions the next selectable object should be found.
Evaluate current state and transition to pressed state.
Evaluate current state and transition to appropriate state.
Evaluate current state and transition to normal state.
Evaluate eventData and transition to appropriate state.
Set selection and transition to appropriate state.
Selects this Selectable.
Internally update the selection state of the Selectable.
See MonoBehaviour.Awake.
Returns true if the GameObject and the Component are active.
Returns true if the native representation of the behaviour has been destroyed.
See MonoBehaviour.OnBeforeTransformParentChanged.
See MonoBehaviour.OnCanvasGroupChanged.
Called when the state of the parent Canvas is changed.
See MonoBehaviour.OnDestroy.
See MonoBehaviour.OnDidApplyAnimationProperties.
See MonoBehaviour.OnDisable.
See MonoBehaviour.OnEnable.
See MonoBehaviour.OnRectTransformDimensionsChange.
See MonoBehaviour.OnRectTransformParentChanged.
See MonoBehaviour.OnValidate.
See MonoBehaviour.Reset.
See MonoBehaviour.Start.
Protected Functions
Transition the Selectable to the entered state.
Clear any internal state from the Selectable (used when disabling).
Is the selectable currently 'highlighted'.
See MonoBehaviour.OnDisable.
Internally update the selection state of the Selectable.
See MonoBehaviour.Awake.
See MonoBehaviour.OnBeforeTransformParentChanged.
See MonoBehaviour.OnCanvasGroupChanged.
Called when the state of the parent Canvas is changed.
See MonoBehaviour.OnDestroy.
See MonoBehaviour.OnDidApplyAnimationProperties.
See MonoBehaviour.OnDisable.
See MonoBehaviour.OnEnable.
See MonoBehaviour.OnRectTransformDimensionsChange.
See MonoBehaviour.OnRectTransformParentChanged.
See MonoBehaviour.OnValidate.
See MonoBehaviour.Reset.
See MonoBehaviour.Start.
Static Functions
Logs message to the Unity Console (identical to Debug.Log).
Removes a gameobject, component or asset.
Destroys the object obj immediately. You are strongly recommended to use Destroy instead.
Makes the object target not be destroyed automatically when loading a new scene.
Returns the first active loaded object of Type type.
Returns a list of all active loaded objects of Type type.
Returns a copy of the object original.
Does the object exist?
Compares if two objects refer to a different object.
Compares two object references to see if they refer to the same object.
Awake is called when the script instance is being loaded.
This function is called every fixed framerate frame, if the MonoBehaviour is enabled.
LateUpdate is called every frame, if the Behaviour is enabled.
Callback for setting up animation IK (inverse kinematics).
Callback for processing animation movements for modifying root motion.
Sent to all game objects when the player gets or loses focus.
Sent to all game objects when the player pauses.
Sent to all game objects before the application is quit.
If OnAudioFilterRead is implemented, Unity will insert a custom filter into the audio DSP chain.
OnBecameInvisible is called when the renderer is no longer visible by any camera.
OnBecameVisible is called when the renderer became visible by any camera.
OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
Sent when an incoming collider makes contact with this object's collider (2D physics only).
OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
Sent when a collider on another object stops touching this object's collider (2D physics only).
OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.
Sent each frame where a collider on another object is touching this object's collider (2D physics only).
Called on the client when you have successfully connected to a server.
OnControllerColliderHit is called when the controller hits a collider while performing a Move.
This function is called when the MonoBehaviour will be destroyed.
This function is called when the behaviour becomes disabled () or inactive.
Called on the client when the connection was lost or you disconnected from the server.
Implement OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn.
Implement this OnDrawGizmosSelected if you want to draw gizmos only if the object is selected.
This function is called when the object becomes enabled and active.
Called on the client when a connection attempt fails for some reason.
Called on clients or servers when there is a problem connecting to the MasterServer.
OnGUI is called for rendering and handling GUI events.
Called when a joint attached to the same game object broke.
This function is called after a new level was loaded.
Called on clients or servers when reporting events from the MasterServer.
OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.
OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.
Called when the mouse enters the GUIElement or Collider.
Called when the mouse is not any longer over the GUIElement or Collider.
Called every frame while the mouse is over the GUIElement or Collider.
OnMouseUp is called when the user has released the mouse button.
OnMouseUpAsButton is only called when the mouse is released over the same GUIElement or Collider as it was pressed.
Called on objects which have been network instantiated with Network.Instantiate.
OnParticleCollision is called when a particle hits a collider.
Called on the server whenever a new player has successfully connected.
Called on the server whenever a player disconnected from the server.
OnPostRender is called after a camera finished rendering the scene.
OnPreCull is called before a camera culls the scene.
OnPreRender is called before a camera starts rendering the scene.
OnRenderImage is called after all rendering is complete to render image.
OnRenderObject is called after camera has rendered the scene.
Used to customize synchronization of variables in a script watched by a network view.
Called on the server whenever a Network.InitializeServer was invoked and has completed.
This function is called when the list of children of the transform of the GameObject has changed.
This function is called when the parent property of the transform of the GameObject has changed.
OnTriggerEnter is called when the Collider other enters the trigger.
Sent when another object enters a trigger collider attached to this object (2D physics only).
OnTriggerExit is called when the Collider other has stopped touching the trigger.
Sent when another object leaves a trigger collider attached to this object (2D physics only).
OnTriggerStay is called once per frame for every Collider other that is touching the trigger.
Sent each frame where another object is within a trigger collider attached to this object (2D physics only).
This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
OnWillRenderObject is called once for each camera if the object is visible.
Reset to default values.
Start is called on the frame when a script is enabled just before any of the Update methods is called the first time.
Update is called every frame, if the MonoBehaviour is enabled.Unity笔记 - 【狗刨学习网】_图文_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Unity笔记 - 【狗刨学习网】
||暂无简介
【狗刨学习网】致力于构建国内最优秀的Unit...|
总评分0.0|
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
下载文档到电脑,查找使用更方便
还剩34页未读,继续阅读
你可能喜欢求解U3D中GUI.backgroundColor对按钮背景设置颜色不起效果
[问题点数:20分,结帖人yxlovemoney]
求解U3D中GUI.backgroundColor对按钮背景设置颜色不起效果
[问题点数:20分,结帖人yxlovemoney]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。}

我要回帖

更多关于 开始按钮点了是输入框 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信