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); } }

相关推荐
派葛穆1 小时前
Unity-realvirtual-S7通讯快速配置(未完结)
unity·游戏引擎
w-白兰地11 小时前
【Addressable远端加载资源】
unity·addressable·资源加载
小张不爱写代码15 小时前
[Unity 技巧] 如何自定义 Inspector 变量显示名称 (CustomLabel)
unity·游戏引擎
Sator115 小时前
Unity开发中常用的随机方法扩展
unity
dzj202115 小时前
Unity中使用LLMUnity遇到的问题(五)——主要脚本的继承关系+用DuckDB对知识库升级的思考
unity·向量数据库·向量搜索·duckdb·llmunity
地狱为王19 小时前
Unity使用Spleeter分离人声和伴奏
unity·游戏引擎·spleeter
在路上看风景1 天前
26. Texture和Sprite
unity
lllljz1 天前
Blender导出模型到Unity或UE5引擎材质丢失模型出错
unity·ue5·游戏引擎·blender·材质
_乐无1 天前
Unity 发布 Android 安卓端所有文件可读写
android·unity·游戏引擎
JIes__2 天前
Unity(二)——核心系统
unity·游戏引擎