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

}

相关推荐
zhangphil17 小时前
Unity3D(Unity)跨平台游戏引擎简介
unity
Madokaly17 小时前
DOTween动画:TweenManager深度解析
unity
_ZHOURUI_H_2 天前
Unity TCP底层极限拆解:粘包、半包、CRC、序列号、双缓冲到底怎么一起工作的?
网络·网络协议·tcp/ip·游戏·unity·游戏引擎·游戏开发
KindSuper_liu2 天前
Unity 游戏网络基础:从 TCP、UDP 到 HTTP、TLS 与 Best HTTP
网络·游戏·unity
qq_170264752 天前
unity里GameObject和Texture的内存归属
java·unity·游戏引擎
weixin_404679312 天前
godot + vscode ai开发
ide·vscode·编辑器·游戏引擎·godot
还是大剑师兰特3 天前
Unity3D(Unity)完整详细介绍
unity·游戏引擎
ellis19703 天前
u3d插件xLua[七]例6 Coroutine
unity
还是大剑师兰特3 天前
Unity 从零搭建简易3D场景(新手分步教程)
3d·unity·游戏引擎
神码编程3 天前
【Unity】TankBattle联机坦克大战(三)创建关卡(生成地块)
unity·游戏引擎·帧同步·坦克大战