unity脚本收集

This commit is contained in:
Abin committed 2025-08-01 10:50:57 +08:00
1 parent ab57544ef5
commit d88804cd63
16 files changed
+1325 -1

No files matched your search

@@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using TMPro;
public class NumberScrollPlayableBehaviour : PlayableBehaviour
{
public TMP_Text textMesh;
public int startValue;
public int endValue;
private double clipDuration;
public override void OnGraphStart(Playable playable)
{
clipDuration = playable.GetDuration();
}
public override void OnGraphStop(Playable playable)
{
if (textMesh != null)
{
textMesh.text = endValue.ToString();
}
}
public override void OnBehaviourPlay(Playable playable, FrameData info)
{
if (textMesh != null)
{
textMesh.text = startValue.ToString();
}
}
public override void OnBehaviourPause(Playable playable, FrameData info)
{
if (textMesh != null && playable.GetTime() >= clipDuration)
{
textMesh.text = endValue.ToString();
}
}
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
if (textMesh == null)
{
return;
}
double normalizedTime = playable.GetTime() / clipDuration;
float currentValue = Mathf.Lerp(startValue, endValue, (float)normalizedTime);
textMesh.text = Mathf.FloorToInt(currentValue).ToString();
// Ensure the text is set to the end value if the normalized time is 1.0 or more
if (normalizedTime >= 1.0)
{
textMesh.text = endValue.ToString();
}
}
}