Files
2026-03-04 10:03:45 +08:00

42 lines
1.0 KiB
C#

using RootMotion.FinalIK;
using UnityEngine;
[CreateAssetMenu(menuName = "Data/RodActionCurve", fileName = "RodActionCurve")]
public class RodActionCurve : ScriptableObject
{
public AnimationCurve curve;
private void InjectCurveIntoRodInPlayerHand()
{
if (!Application.isPlaying)
{
Debug.LogWarning("Cannot inject curve. The game is not running.");
return;
}
FPlayer fPlayer = Object.FindObjectOfType<FPlayer>();
if (fPlayer == null)
{
Debug.LogWarning("FPlayer not found in the scene.");
return;
}
if (fPlayer.currentRod == null)
{
Debug.LogWarning("FPlayer's currentRod is null.");
return;
}
CCDIK component = fPlayer.currentRod.GetComponent<CCDIK>();
if (component == null)
{
Debug.LogWarning("CCDIK component not found on the currentRod.");
return;
}
int num = component.solver.bones.Length;
for (int i = 0; i < num; i++)
{
float time = (float)i / (float)(num - 1);
float weight = curve.Evaluate(time);
component.solver.bones[i].weight = weight;
}
}
}