纳金网

标题: GUI闪烁效果的实现 [打印本页]

作者: 刀锋狼    时间: 2015-7-30 00:13
标题: GUI闪烁效果的实现
GUI闪烁效果的实现
  1. using UnityEngine;
  2.         using System.Collections;
  3. //         重点是yield和StartCoroutine的使用。
  4.         public class MainBoardTop : MonoBehaviour
  5.         {
  6.                 public Texture2D Logo;
  7.                 public Texture2D SysInfo;
  8.                 public Texture2D FriInfo;
  9.                 public Texture2D IcoHelp;
  10.                 public GUIStyle style;
  11.                 public GUIStyle pathStyle;
  12.                 private bool displaySysLabel = false;
  13.                 private bool displayFriLabel = false;
  14.                 IEnumerator Start()
  15.                 {
  16.                         yield return StartCoroutine(flashSysLabel());
  17.                         yield return StartCoroutine(flashFriLabel());
  18.                 }
  19.                 IEnumerator flashSysLabel()
  20.                 {
  21.                         while(true)
  22.                         {
  23.                                 displaySysLabel = true;
  24.                                 yield return new WaitForSeconds(0.5f);
  25.                                 displaySysLabel = false;
  26.                                 yield return new WaitForSeconds(0.5f);
  27.                         }
  28.                 }
  29.                 IEnumerator flashFriLabel()
  30.                 {
  31.                 while(true)
  32.                         {
  33.                                 displayFriLabel = true;
  34.                                         yield return new WaitForSeconds(0.5f);
  35.                                 displayFriLabel = false;
  36.                                 yield return new WaitForSeconds(0.5f);
  37.                         }
  38.                 }
  39.                 void OnGUI()
  40.                 {
  41.                         GUI.BeginGroup(new Rect(0, 0, 300, 100));
  42.                         GUI.Button(new Rect(3,5,37,37),Logo,style);
  43.                         GUI.Button(new Rect(45,8,150,15),"test",pathStyle);
  44.                         if(displaySysLabel == true)
  45.                         {
  46.                                 GUI.Label(new Rect(45,25,16,16),SysInfo,style);
  47.                         }
  48.                         GUI.Label(new Rect(61,25,16,16),"0",style);
  49.                         if(displayFriLabel == true)                        {
  50.                                 GUI.Label(new Rect(77,25,16,16),FriInfo,style);
  51.                         }
  52.                         GUI.Label(new Rect(93,25,16,16),"0",style);
  53.                         GUI.Label(new Rect(108,25,16,16),IcoHelp,style);
  54.                         GUI.EndGroup();
  55.                 }
复制代码





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5