GUI實現,如下:

按“G”鍵開始新手引導

代碼如下:
using UnityEngine; using System.Collections; public class OkButton : GUIBase { /// <summary> /// 按鈕圖片 /// </summary> public Texture2D OKBTN_a; public Texture2D OKBTN_b; /// <summary> /// 引導圖片 /// </summary> public Texture2D HoleTexture; private GUIStyle OKBTNStyle; private GUIStyle _defaultStyle; // Use this for initialization public override void Start () { base.Start(); OKBTNStyle = new GUIStyle(); _defaultStyle = new GUIStyle(); _defaultStyle.padding = new RectOffset(0, 0, 0, 0); _defaultStyle.border = new RectOffset(0, 0, 0, 0); if (OKBTN_a == null) { OKBTN_a = Resources.Load("OKBTN/OK_a") as Texture2D; OKBTNStyle.normal.background = OKBTN_a; } if (OKBTN_b == null) { OKBTN_b = Resources.Load("OKBTN/OK_b") as Texture2D; OKBTNStyle.active.background = OKBTN_b; } if (HoleTexture == null) HoleTexture = Resources.Load("OKBTN/okfight") as Texture2D; } // Update is called once per frame public override void Update () { base.Update(); } private bool _isGuider = false; void LateUpdate() { if (Input.GetKeyDown(KeyCode.G)) { _isGuider = true; } } public override void OnGUI() { base.OnGUI(); if (_isGuider) //引導 { GUI.DrawTexture(new Rect(0, 0, 800, 480), HoleTexture); Rect rect = new Rect(674, 355, 128, 128); OkButton.AddHole(rect, _defaultStyle); if (Event.current.type == EventType.MouseUp) { if (rect.Contains(Event.current.mousePosition)) { StartCoroutine(disCatch()); } } } if (GUI.Button(new Rect(674, 355, 128, 128), "", OKBTNStyle)) { print("Click OKBTN"); _isGuider = false; } if (GUI.Button(new Rect(0, 0, 128, 128), "", OKBTNStyle)) { print("Click Other"); } } /// <summary> /// 另外線程處理 /// </summary> /// <returns></returns> IEnumerator disCatch() { //開一個線程處理要處理的事 yield return 1; } /// <summary> /// 在界面上面開孔,只有此處可以點擊,其余的地方屏蔽用戶點擊,即在該按鈕四周加其他按鈕,先加的按鈕會在上層。后加的按鈕被屏蔽。 /// </summary> /// <param name="rect"></param> public static void AddHole(Rect rect, GUIStyle style) { GUI.Button(new Rect(0, 0, GUIBase.DesignStageWidth, rect.y), "", style);//上面的button GUI.Button(new Rect(0, rect.yMax, GUIBase.DesignStageWidth, GUIBase.DesignStageHeight - rect.yMax), "", style); //下邊的button GUI.Button(new Rect(0, rect.y, rect.x, rect.height), "", style);//左邊 GUI.Button(new Rect(rect.xMax, rect.y, GUIBase.DesignStageWidth - rect.xMax, rect.height), "", style);//右邊 } }
