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

Unity 不规则进度条显示根据点对点进行

using UniRx;
using UnityEngine;
using UnityEngine.UI;

public class SpeedVehicle : MonoBehaviour
{
//加速踏板
[SerializeField] private Image AcceleratorApertureSlider;
//制动踏板
[SerializeField] private Image BrakingPedalApertureSlider;

private static readonly string TAG = "SpeedVehicle";

private void Start()
{
    //当前加速踏板进度
    DataCenter.AcceleratorAperture.Subscribe(f =>
    {
        Log.I(TAG, "AcceleratorAperture select value:  " + f);
        float fillAmount = f / 100f;
        AcceleratorApertureSlider.fillAmount = fillAmount;
        //SetAnimationFrame(AcceleratorApertureSlider, f * 100);
        AcceleratorAperture(fillAmount);
    }).AddTo(this);
    //当前制动踏板进度
    DataCenter.BrakingPedalAperture.Subscribe(f =>
    {
        Log.I(TAG, "BrakingPedalAperture select value:  " + f);
        float fillAmount = Normalize(f, 10, 45);
        BrakingPedalApertureSlider.fillAmount = fillAmount;
        //SetAnimationFrame(BrakingPedalApertureSlider, f * 100);
        BrakingPedalAperture(fillAmount);
    }).AddTo(this);
}

protected virtual void AcceleratorAperture(float fillAmount) { }

protected virtual void BrakingPedalAperture(float fillAmount) { }

private float Normalize(float value, float min, float max)
{
    return (value - min) / (max - min);
}

private void SetAnimationFrame(Animation animation, float frameToFreeze)
{
    // 第N帧对应的时间(秒)
    float timeAtNthFrame = frameToFreeze / 25f;

    animation.clip.SampleAnimation(animation.gameObject, timeAtNthFrame);
}

}


http://www.kler.cn/news/288790.html

相关文章:

  • yolov9目标检测pyside6可视化检测界面python源码-用于计数统计-摄像头可用
  • jquery swiper插件的用法
  • c++vscode多文件实现通讯录管理系统
  • DRY原则-用函数和模块化来避免重复代码
  • 算法训练营|图论第6天 108.冗余连接 109.冗余连接2
  • 【黑马点评】达人探店
  • 使用sass的混合插入模式进行@media响应式媒体查询做自适应开发
  • Github 2024-08-28 C开源项目日报 Top9
  • 算法笔试-编程练习-好题-03
  • 前端框架大观:探索现代Web开发的基石
  • react- native创建pdf
  • mysql学习教程,从入门到精通,MySQL介绍(1)
  • 设计模式及创建型模式-python版
  • C++ Qt进程间通信机制之QRO、QRemoteObjectHost
  • Anaconda安装并配置Python环境 | Python系列教程
  • 把设计模式用起来!(一)——楔
  • 【日常记录-JS】HTML5中使用SVG元素
  • LeetCode40 组合总和 II
  • 安卓model转鸿蒙ets
  • Centos挂载yum源
  • Spring框架
  • 店铺所有商品接口数据解析,JSON格式的示例
  • 在Spring Boot中实现请求IP白名单拦截
  • python-读取word中的内容
  • 代码随想录第二十天 | 513. 找树左下角的值,路径总和,106. 从中序与后序遍历序列构造二叉树
  • react|useState的异步渲染
  • 【AIGC】ChatGPT 3.5/4.0 新手使用手册
  • 【pyhton】python如何实现将word等文档中的文字转换成语音
  • 如何用Python 下载B站上的视频
  • SQL【2】稍稍进阶