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

}

相关推荐
魔士于安6 小时前
unity 音乐会场景 unity2022
游戏·unity·游戏引擎·贴图·模型
一线灵7 小时前
Axmol 3.x 输入系统重构:从 Touch/Mouse 到统一 Pointer,再到现代 InputField
重构·游戏引擎
Zwarwolf7 小时前
Godot零散知识点项目汇总
游戏引擎·godot
Mediary8 小时前
Unity is running with Administrator privileges, which isnot supported...
unity
游乐码10 小时前
Unity基础(十四)场景异步加载
unity·游戏引擎
mxwin11 小时前
Unity Shader URP:法线在空间变换上的特殊性
unity·游戏引擎·shader
nnsix11 小时前
Unity 动态批处理、静态批处理、GPU Instaning、SRP Batcher 笔记
笔记·unity·单一职责原则
charlee4412 小时前
Unity在安卓端如何调试输出信息
android·unity·adb·游戏引擎·真机调试
TCW112113 小时前
Minetest游戏引擎源代码解析
游戏引擎