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

}

相关推荐
wgslucky10 小时前
Godot GDScript初学者遇到的问题记录
游戏引擎·godot
点心的游戏开发世界12 小时前
GDScript 入门笔记(五):函数
笔记·游戏引擎·godot
谢斯15 小时前
[unity]如何在unity中添加newtonsoft-json
unity·json·游戏引擎
天人合一peng16 小时前
Unity标记固定颜色及投影标记
unity
云雨巫山20 小时前
Unity 游戏开发性能优化全景手册
unity·智能手机·性能优化·游戏引擎
maybeyaluokenai20 小时前
unity build in渲染管线概述
unity·图形渲染
学习星球20 小时前
AI 原生游戏开发:Godot 4 + AI Agent 全栈指南(Ziva 3 / Godot MCP 深度实战)
人工智能·游戏引擎·godot
云雨巫山20 小时前
Unity 性能优化 · 图解全景手册
unity·性能优化·游戏引擎
Madokaly1 天前
DOTween的Vector3Plugin
unity
点心的游戏开发世界2 天前
GDScript 入门笔记(二):变量与数据类型
笔记·游戏引擎·godot