Unity HUD
来源:互联网 发布:网络兼职应聘 编辑:程序博客网 时间:2024/04/30 13:27
HUD (head up displaye) 用于在角色的头上显示信息, 然后信息会跟随角色, 一般用于显示角色的扣血量之类的; 用于测试也是一个非常不错的选择, 特别是在实机上测试时不能方便的看到Debug信息的时候.
下面是源代码, 一个HUD的管理类, 具体的实现用的是NGUI 和 一个HUDText的插件
using UnityEngine;using System.Collections;using System.Collections.Generic;/// <summary>/// 用于显示HUD/// </summary>public class HUD{ //原始的hudText GameObject originalHUDText; public static readonly HUD Instance = new HUD(); private HUD() { originalHUDText = GameObject.Find("HUDText"); } //所有HUDUser List<HUDUser> hudUsers = new List<HUDUser>(); //默认设置 float defaultStayDuration = 0.3f; Color defaultColor = Color.white; /// <summary> /// 显示HUD /// </summary> public void Show(object text, GameObject followTarget) { Show(text, defaultColor, defaultStayDuration, followTarget); } /// <summary> /// 显示HUD /// </summary> public void Show(object text, Color color, GameObject followTarget) { Show(text, color, defaultStayDuration, followTarget); } /// <summary> /// 显示HUD /// </summary> public void Show(object text, Color color, float stayDuration, GameObject followTarget) { //没有包含就加入新的 if (IsHad(followTarget) == false) { hudUsers.Add(new HUDUser(originalHUDText, followTarget)); } //显示HUD for (int i = 0; i < hudUsers.Count; i++) { if (hudUsers[i].FollowTarget == followTarget) { hudUsers[i].Show(text, color, stayDuration); break; } } } /// <summary> /// 移除 /// </summary> public void Remove(GameObject followTarget) { for (int i = 0; i < hudUsers.Count; i++) { if (hudUsers[i].FollowTarget == followTarget) { hudUsers[i].Destroy(); break; } } } //是否已经包含了 bool IsHad(GameObject followTarget) { for (int i = 0; i < hudUsers.Count; i++) { if (hudUsers[i].FollowTarget == followTarget) return true; } return false; }}/// <summary>/// 保存HUD的使用者/// </summary>class HUDUser{ public GameObject FollowTarget; HUDText hudText; public HUDUser(GameObject originalHUDText, GameObject followTarget) { //复制一个 GameObject copy = GameObject.Instantiate(originalHUDText) as GameObject; copy.transform.parent = originalHUDText.transform.parent; copy.transform.localScale = originalHUDText.transform.localScale; this.hudText = copy.GetComponent<HUDText>(); this.hudText.enabled = true; this.FollowTarget = followTarget; this.hudText.GetComponent<UIFollowTarget>().target = FollowTarget.transform; } public void Show(object text,Color color,float stayDuration) { this.hudText.Add(text, color, stayDuration); } public void Destroy() { if (hudText != null && hudText.gameObject !=null) { GameObject.Destroy(hudText.gameObject); } }}
HUDText插件下载 : http://pan.baidu.com/s/1Cc5Cm
0 0
- Unity HUD
- Unity NGUI HUD text简单使用
- HUD
- Unity插件NGUI制作血条--HUD的基本使用
- unity手游<少侠历险记>(3)NGUI:HUD使用
- unity手游<少侠历险记>(3)NGUI:HUD使用
- Unity实战 RTS3D即时战略游戏开发(八) HUD的使用 小地图显示
- Unity实战 RTS3D即时战略游戏开发(八) HUD的使用 单位信息显示
- Unity的NGUI插件的HUD Text插件血条数值的显示
- HUD 1000
- HUD 1033
- HUD 4038
- HUD P1561
- HUD 4473
- HUD 4502
- Hud 4608
- hud 2073
- hud 1518
- 【错误记录】fatal error C1002: 在第2遍中编译器的堆空间不足
- ACE_Task
- 不法分子盗qq号的方法
- CCScrollView的拖动,自适应到合适位置
- js判断网页是否加载完毕 包括图片
- Unity HUD
- defaultServiceManager
- SHELLEXECUTEINFO 和 ShellExecuteEx的使用
- linux screen Cannot open your terminal '/dev/pts/5' - please check. 解决方法
- Redis与Memcached的比较
- linux内存管理浅析
- 黑客惯用软件
- 学习HTML5开发RPG游戏第三步>基本对象设计<三>
- Servlet3.0实现上传文件到服务器端