日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Unity3D教程:GUI的布局模式

固定Layout是用在你預先設計好界面的時候,活動Layout工作在你不知道會有多少組件或者如何定位他們的時候,這里有個例子:

成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供關嶺網(wǎng)站建設、關嶺做網(wǎng)站、關嶺網(wǎng)站設計、關嶺網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、關嶺企業(yè)網(wǎng)站模板建站服務,十年關嶺做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。

 
 
 
  1. function OnGUI () { 
  2.    // 固定Layout 
  3.    GUI.Button (Rect (25,25,100,30), “I am a Fixed Layout Btton”); 
  4.    // 活動Layout 
  5.    GUILayout.Button (“I am an Automatic Layout Button”); 
  6.    } 

排列控制

在活動Layout模式里,你可以控制組件的位置,并組織他們。在固定模式下你可以把多個控件放進Groups中,在活動模式下可以把他們放在Areas, Horizontal Groups和Vertical Groups里。

固定Layout中的Groups

Groups 在固定Layout模式中起到組織可用項的,他讓你在屏幕的一個區(qū)域中包含多個控件。你要把定義的控件放在GUI.BeginGroup()和 GUI.EndGroup()這對函數(shù)中間,所有控件的位置坐標都以Groups的0坐標為起點,假如你更改了group坐標,那么內(nèi)部的控件也會跟隨改變。

舉個例子:

 
 
 
  1. // 在Group中有一個box和一個button.這里,兩個控件是屬于Group的. 
  2.    function OnGUI(){ 
  3.    GUI.BeginGroup (Rect (Screen.width / 2 , Screen.height / 2 − 50, 100, 100)); 
  4.    GUI.Box (Rect (0,0,100,100), “Group is here”); 
  5.    GUI.Button (Rect (10,40,80,30), “Click me”); 
  6.    GUI.EndGroup (); 
  7.    } 

Group也可以嵌套,例如:

 
 
 
  1. var bgImage : Texture2D; // background image that is 256 x 32 
  2.    var fgImage : Texture2D; // foreground image that is 256 x 32 
  3.    var playerEnergy = 1.0; // a float between 0.0 and 1.0 
  4.    function OnGUI () { 
  5.    // Create one Group to contain both images 
  6.    // Adjust the first 2 coordinates to place it somewhere else on−screen 
  7.    GUI.BeginGroup (Rect (0,0,256,32)); 
  8.    // Draw the background image 
  9.    GUI.Box (Rect (0,0,256,32), bgImage); 
  10.    // Create a second Group which will be clipped 
  11.    // We want to clip the image and not scale it, which is why we need the second Group 
  12.    GUI.BeginGroup (Rect (0,0,playerEnergy * 256, 32)); 
  13.    // Draw the foreground image 
  14.    GUI.Box (Rect (0,0,256,32), fgImage); 
  15.    // End both Groups 
  16.    GUI.EndGroup (); 
  17.    GUI.EndGroup (); 
  18.    } 

和我們熟知的if-else語句一樣,相互最接近的begin和end為一組。

活動Layout-Areas

Areas只用于活動Layout模式.作用和固定模式下的Group一樣。

在活動模式下,你可以定義Area的范圍,也可以不定義。不定義的時候整個屏幕就是它的范圍,如果手工定義了它的范圍,那么它內(nèi)部的控件將以Area的坐標為起始坐標。Unity3D教程手冊

一個例子:

 
 
 
  1. function OnGUI () { 
  2.    GUILayout.Button (“I am not inside an Area”); 
  3.    GUILayout.BeginArea (Rect (Screen.width/2, Screen.height/2, 300, 300)); 
  4.    GUILayout.Button (“I am completely inside an Area”); 
  5.    GUILayout.EndArea (); 
  6.    } 

自動Layout - Horizontal and Vertical Groups

自動模式中還有還有兩對組函數(shù):GUILayout.BeginHoriztontal(),GUILayout.EndHorizontal(),GUILayout.BeginVertical(),和GUILayout.EndVertical().他們用在Area中,同樣也是成對使用的。

其特點是Horiztontal中的控件呈水平排列,Vertical中的控件呈垂直排列。

例子一個:

 
 
 
  1. var sliderValue = 1.0; 
  2.    var maxSliderValue = 10.0; 
  3.    function OnGUI() 
  4.    { 
  5.    // Wrap everything in the designated GUI Area 
  6.    GUILayout.BeginArea (Rect (20,0,200,60)); 
  7.    // Begin the singular Horizontal Group 
  8.    GUILayout.BeginHorizontal(); 
  9.    // Place a Button normally 
  10.    if (GUILayout.RepeatButton (“Increase max\nSlider Value”)) 
  11.    { 
  12.    maxSliderValue += 3.0 * Time.deltaTime; 
  13.    } 
  14.    // Arrange two more Controls vertically beside the Button 
  15.    // 這里面有兩個控件 是按照垂直的形式排列的 
  16.    GUILayout.BeginVertical(); 
  17.    GUILayout.Box(“Slider Value: ” + Mathf.Round(sliderValue)); 
  18.    sliderValue = GUILayout.HorizontalSlider (sliderValue, 0.0, maxSliderValue); 
  19.    // End the Groups and Area 
  20.    GUILayout.EndVertical(); 
  21.    GUILayout.EndHorizontal(); 
  22.    GUILayout.EndArea(); 
  23.    } 

用GUILayoutOptions去定義一些控件   比如可以控制按鈕的長度,如:

 
 
 
  1. function OnGUI () { 
  2.    GUILayout.BeginArea (Rect (100, 50, Screen.width−200, Screen.height−100)); 
  3.    GUILayout.Button (“I am a regular Automatic Layout Button”); 
  4.    GUILayout.Button (“My width has been overridden”, GUILayout.Width (95)); 
  5.    GUILayout.EndArea (); 
  6.    } 

這里GUILayout.Width (95)就定義了按鈕的長度為95。

原文鏈接:http://www.unitymanual.com/6064.html


網(wǎng)頁名稱:Unity3D教程:GUI的布局模式
文章網(wǎng)址:http://www.5511xx.com/article/dhhggsc.html