UGUI缓动血条制作
来源:互联网 发布:sql 存储过程中 事物 编辑:程序博客网 时间:2024/05/17 09:32
using UnityEngine;using System.Collections;using UnityEngine.UI; public class BossHealthBar : MonoBehaviour{ public static BossHealthBar instance; public GameObject goHealthBar; public Scrollbar forDel; private Vector3 positionVec3 = new Vector3(); public Text HpTxt; private int index = 1;//当前血条阶段 public int Index { get { return this.index; } set { this.index = value; } } void Start() { timer = 10; this.positionVec3 = this.transform.localPosition; } void Update() { this.CastAnimation(this.goHealthBar); } /// <summary> /// 血条当前值显示 /// </summary> /// <param name="curValue">当前血量</param> /// <param name="maxValue">最大血量</param> public void SetHealthValueText(int current, int max, bool isTrubans) { if (isTrubans) { float hp = ((float)current / (float)max) * 100; HpTxt.text = hp.ToString("f") + "%"; } else { HpTxt.text = current + "/" + max; } } /// <summary> /// 血条状态处理 /// </summary> /// <param name="curValue">当前血量</param> /// <param name="maxValue">最大血量</param> public void UpdateHealthBar(int curValue, int maxValue, bool isTurbans) { Scrollbar progressBar = null; Image _sp = null; progressBar = this.goHealthBar.GetComponent<Scrollbar>(); _sp = this.transform.Find("HealthBar/SlidingArea/forDel").GetComponent<Image>(); if (curValue >= maxValue) { curValue = maxValue; progressBar.size = 1; return; } if (maxValue <= 0 && isTurbans == false) { this.gameObject.SetActive(false); } if (Index == 0) return; int valueOfLine = maxValue / Index; if (valueOfLine <= 0) return; int index = curValue / valueOfLine; if (curValue % valueOfLine == 0) index--; float value = (curValue - index * valueOfLine) / (float)valueOfLine; if (curValue <= 0) value = 0; if (null != progressBar) { progressBar.size = value; } } //血条中间图片滑动处理 void CastAnimation(GameObject father) { Scrollbar progressBar = null; if (null != father) { progressBar = father.GetComponent<Scrollbar>(); } if (null == progressBar) { return; } if (this.forDel.size <= progressBar.size) { this.forDel.size = progressBar.size; } else { this.forDel.size -= Time.deltaTime * 0.5f; } } #region 测试代码 private float timer; //距离多长时间刷新列表 private float useTime = 0; int xt = 100; void FixedUpdate() { if (timer > 0 && useTime < Time.time) { useTime = Time.time + 1; timer -= 1; xt =xt- 10; UpdateHealthBar(xt, 100, false); SetHealthValueText(xt, 100, false); } }#endregion }
NGUI版本:http://www.shihuangzhe.org/?p=78
UGUI血条Demo下载:
链接:http://pan.baidu.com/s/1gfFr9WB 密码:hjrb
0 0
- UGUI缓动血条制作
- UGUI缓动血条制作
- UGUI 动手制作字体
- UGUI - 制作九宫贴图
- UGUI - 制作Slider进度条
- UGUI - 制作listview
- UGUI - 制作Toggle Group
- UGUI 制作血条
- UGUI艺术字制作
- Unity UGUI SwitchButton制作
- 【UGUI】制作艺术字体
- 用UGUI制作HUD
- UGUI 制作日历
- 制作ugui BMFont
- [UnityUI]使用UGUI制作排行榜
- UGUI制作Tab标签页
- NGUI/UGUI 小地图制作
- ugui制作弧形血条
- jackson 实现 javabean 与 json、xml 互转
- python定时器
- 用纯css创建三角形
- [Guava源码日报](9)Closeables
- VS2013多字节工程问题
- UGUI缓动血条制作
- 1038: 角谷猜想
- Storm实例
- 克服跨洋网络延迟,使用Docker Hub Mirror加速Docker官方镜像下载
- Tensorflow学习:线性回归问题
- Android7.0使用Intent打开文件
- Android应用编译时自动生成版本号
- mysql重置root密码
- SGU531 Bonnie and Clyde RMQ