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

}

相关推荐
WarPigs10 小时前
Unity对象不应该使用null传播的问题
unity
每日出拳老爷子1 天前
【VR】【Unity】抓走转放系列21|一天搭完门和抽屉工具槽:小场景按这个次序拼装
unity·vr·驱动·排错·snap zone
淡海水2 天前
02-02-原理篇-分代GC
算法·unity·c#·游戏引擎·.net·gc
小贺儿开发2 天前
Unity 文物新生 会讲故事的文物展墙
人工智能·科技·unity·ai·视频·互动·演示
淡海水2 天前
02-03-原理篇-大对象堆
unity·c#·游戏引擎·.net·gc
WarPigs3 天前
Unity在Create菜单添加创建自定义脚本模板选项
unity
郝学胜-神的一滴3 天前
C++ Templates 01:拨开迷雾,读懂C++模板经典著作
开发语言·c++·程序人生·游戏·游戏引擎·软件构建
淡海水3 天前
02-01-原理篇-Mark-Sweep与变种算法
算法·unity·c#·游戏引擎·.net·gc
babywang03 天前
Unity笔记--塔防游戏中的ECS架构:从原理到实战的全面解析
unity·ecs架构
babywang04 天前
Unity笔记--AssetBundle详解
unity·游戏引擎