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

相关推荐
Y***K43418 小时前
C在游戏中的Godot
游戏·游戏引擎·godot
WarPigs1 天前
Unity编辑器开发笔记
unity·编辑器·excel
Q***f6351 天前
C++在游戏引擎开发中的实践
游戏引擎
6***x5451 天前
C++在计算机视觉中的图像处理
c++·图像处理·计算机视觉·游戏引擎·logback·milvus
霜绛1 天前
Unity:lua热更新(三)——Lua语法(续)
unity·游戏引擎·lua
世洋Blog2 天前
更好的利用ChatGPT进行项目的开发
人工智能·unity·chatgpt
evolution_language2 天前
Unity场景(Scene)的注意事项和易错点
unity·游戏引擎·scene
EQ-雪梨蛋花汤2 天前
【AI工具】使用 Doubao-Seed-Code 优化 Unity 编辑器插件:从功能实现到界面美化的完整实践
人工智能·unity·编辑器
g***B7382 天前
元宇宙游戏引擎
游戏引擎
Dr.勿忘2 天前
开源Unity小框架:高效单例与模块化设计
游戏·unity·开源·c#·游戏引擎·游戏程序·gamejam