99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

OnGUI Window控件

2020-07-13 14:28 更新

通常情況下,一個游戲界面可以由很多窗口組成,在每個窗口中可以添加不同的、任意的功能組件,這讓窗口的使用豐富了游戲界面和內容。

使用 Window 控件為當前界面添加窗口,具體方法如下:

public static function Window(id:int, clientRect:Rect, func:GUI.WindowFunction,text:string):Rect;
public static function Window(id:int, clientRect:Rect, func:GUI.WindowFunction,image:Texture):Rect;
public static function Window(id:int, clientRect:Rect, func:GUI.WindowFunction,content:GUIContent):Rect;
public static function Window(id:int, clientRect:Rect, func:GUI.WindowFunction,text:string, style:GUIStyle):Rect;
public static function Window(id:int, clientRect:Rect, func:GUI.WindowFunction,image:Texture, style:GUIStyle):Rect;
public static function Window(id:int, clientRect:Rect, func:GUI.WindowFunction,title:GUIContent, style:GUIStyle):Rect;

注:

  • id 為窗口的標號,用以標識窗口。

  • clientRect 為窗口顯示區(qū)域。

  • func 是回調方法的名稱。

  • text 為窗口標題。

參數列表

參數 描述
Style 設置用于窗口的可選樣式。如果遺漏了,則使用當前GUISkin的窗口樣式。
clientRect 設置可以拖動的窗口的一部分,這部分將被剪切到實際的窗口中。
text 設置文本在窗口內呈現。
content 設置在窗口內渲染的圖形。
title 設置文本在窗口標題欄顯示。
id 設置窗口的ID號(可以是任何值, 只要它是唯一的)。
func 設置顯示窗口內容的腳本函數。
image 設置在窗口中渲染的圖像。
style 設置窗口的樣式信息。

使用案例

  1. 創(chuàng)建項目,將其命名為 window,保存場景。

  1. 執(zhí)行 AssetsCreateJavaScript 命令,創(chuàng)建一個新的腳本文件。

  1. 在 Project 視圖中打開腳本編輯器,輸入下列語句:

    var windowRect0:Rect=Rect(20, 20, 120, 50);
    var windowRect1:Rect=Rect(20, 100, 120, 50);
    function OnGUI(){
        GUI.color=Color.red;
        windowRect0=GUI.Window(0, windowRect0, DoMyWindow, "Red Window");
        GUI.color=Color.green;
        windowRect1=GUI.Window(1, windowRect1, DoMyWindow, "Green Window");
    }
    function DoMyWindow(windowID:int){
        if(GUI.Button(Rect(10, 20, 100, 20), "Hello World"))
        print("Got a click in window with color"+GUI.color);
        GUI.DragWindow(Rect(0, 0, 10000, 10000));
    }

  1. Ctrl+S 鍵保存腳本。

  1. 在 Project 視圖中選擇腳本,并將其拖曳到 Hierarchy 視圖中的 Main Camera 上,使腳本和攝像機產生關聯。

  1. 進行測試,效果如下圖所示。

以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號