本文主要是介绍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);
}
}
这篇关于Unity 不规则进度条显示根据点对点进行的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!