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

}

相关推荐
WiChP1 天前
【V0.1B11】从零开始的2D游戏引擎开发之路
开发语言·游戏引擎
玖玥拾1 天前
Cocos学习笔记:武器系统与数据驱动UI联动
游戏引擎·cocos2d
winlife_1 天前
全程用 AI 做一款商业级手游 · EP1 地基:先搭框架层,不急着写玩法
unity·ai编程·游戏架构·mcp·框架设计·funplay
小贺儿开发1 天前
Unity VideoPlayer 播放控制器
unity·编辑器·播放器·视频·工具·videoplayer·互动
め.2 天前
UIFramework
ui·unity
fqbqrr2 天前
2606d,用d语言构建游戏引擎
游戏引擎·d
℡枫叶℡2 天前
Unity - Import Activity Window 资源导入诊断信息窗口
unity·资源导入诊断
TO_ZRG2 天前
Unity 证书校验
unity·游戏引擎
mxwin2 天前
Unity Shader 切线空间数据是如何计算出来的
unity·游戏引擎·shader