当前位置: 首页 > news >正文

【cocos creator】进度条控制脚本,支持节点进度条,图片进度条,进度条组件,和进度文字展示

进度条控制脚本,支持节点进度条,图片进度条,进度条组件,和进度文字展示
在这里插入图片描述
在这里插入图片描述


const { ccclass, property, menu } = cc._decorator;let text_type = cc.Enum({"20%": 0,"1/5": 1,"差值": 2,"自定义": 3,
});
let bar_type = cc.Enum({"Sprite": 0,"ProgressBar": 1,"Node": 2,
});@ccclass
@menu("自定义组件/进度条")
export default class barNode extends cc.Component {@property({type: cc.Sprite,visible() { return this.barType == bar_type.Sprite }})spriteBar: cc.Sprite = null;@property({type: cc.ProgressBar,visible() { return this.barType == bar_type.ProgressBar }})progressBar: cc.ProgressBar = null;@property({type: cc.Node,visible() { return this.barType == bar_type.Node }})nodeBar: cc.Node = null;@property({type: cc.Float,visible() { return this.barType == bar_type.Node }})max: number = 1;@property({type: cc.Float,visible() { return this.barType == bar_type.Node }})min: number = 0;@property(cc.RichText)barDesc: cc.RichText = null;@property(cc.Label)barDesc2: cc.Label = null;@property({type: cc.Enum(bar_type),displayName: "进度条类型"})barType = bar_type.Sprite;@property({type: cc.Enum(text_type),displayName: "进度文字类型"})textType = text_type["1/5"];_width = 0;protected onLoad(): void {}init(value, limit, bar_desc?) {let desc: string = bar_desc || "[0]";let percent = value / limit;percent = percent > 1 ? 1 : percent;if (this.spriteBar && this.barType == bar_type.Sprite) this.spriteBar.fillRange = percent;if (this.progressBar && this.barType == bar_type.ProgressBar) this.progressBar.progress = (percent < 0.1 && percent != 0) ? 0.1 : percent;if (this.nodeBar && this.barType == bar_type.Node) {this.nodeBar.width = (percent && percent * this.max < this.min) ? this.min : percent * this.max;}let str = "";switch (this.textType) {case 0: str = `${this.fixForce(percent * 100, 2)}%`desc = desc.replace("[0]", str);break;case 1: str = `${value}/${limit}`;desc = desc.replace("[0]", str);break;case 2: str = `${limit - value < 0 ? 0 : limit - value}`desc = desc.replace("[0]", str);break;case 3:desc = desc.replace("[0]", value);desc = desc.replace("[1]", limit);break;}if (this.barDesc) this.barDesc.string = desc;if (this.barDesc2) this.barDesc2.string = desc;}fixForce(count, fixTo): string {let a = (count + "").split(".");let b = a[0];if (a.length > 1) b = a[0] + "." + a[1].slice(0, fixTo);if (b == "0.00" && count != 0) {if (a.length > 1) b = a[0] + "." + a[1].slice(0, 4);}return b;}
}
http://www.lryc.cn/news/356117.html

相关文章:

  • Bean的一些属性信息总结
  • CentOS 7 安装 Minio
  • vue3和vite实现vue-router4版本路由的配置以及自动生成路由配置
  • Flutter 中的 CupertinoDatePicker 小部件:全面指南
  • 用 Python 编写自动发送每日电子邮件报告的脚本
  • IT人的拖延——渴望成功与害怕成功的矛盾
  • 【全开源】场馆预定系统源码(ThinkPHP+FastAdmin+UniApp)
  • 音乐系统java在线音乐网站基于springboot+vue的音乐系统带万字文档
  • Python—面向对象小解(1)
  • 2024最新TikTok抖音国际版,tiktok正版免拔卡安装来了!
  • 【Python-OS】os.path.splitext()
  • 安卓开发--安卓使用Echatrs绘制折线图
  • 每日5题Day9 - LeetCode 41 - 45
  • 进程间通信的方式中,socket和消息队列的区别
  • 10. C++异步IO处理库和使用libevent实现高性能服务器
  • React里面useMemo和useCallBack的区别
  • css 渐变色边框
  • prompt提示词:如何让AI帮你提一个好问题
  • 若依ruoyi-vue element-ui 横向滚动条 动态横向滚动条
  • CET-4 听力高频词
  • ARM鲲鹏920-oe2309-caffe
  • 这款网站测试工具,炫酷且强大!【送源码】
  • 成功案例(IF=7.4)| 代谢组+16s联合分析助力房颤代谢重构的潜在机制研究
  • 【LeetCode:496. 下一个更大元素 I + 单调栈】
  • 软考案例题总结
  • 第二证券炒股知识:股票破发后怎么办?
  • Angular中,@HostListener装饰器
  • lammps案例:reaxff势模拟Fe(OH)3高温反应过程
  • 基于springboot实现政府管理系统项目【项目源码+论文说明】
  • 5.28_Java语法_运算符,接收键盘数据