69 lines
1.1 KiB
C#
69 lines
1.1 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace RootMotion.FinalIK
|
|
{
|
|
[Serializable]
|
|
public class IKMappingBone : IKMapping
|
|
{
|
|
public Transform bone;
|
|
|
|
[Range(0f, 1f)]
|
|
public float maintainRotationWeight = 1f;
|
|
|
|
private BoneMap boneMap = new BoneMap();
|
|
|
|
public override bool IsValid(IKSolver solver, ref string message)
|
|
{
|
|
if (!base.IsValid(solver, ref message))
|
|
{
|
|
return false;
|
|
}
|
|
if (bone == null)
|
|
{
|
|
message = "IKMappingBone's bone is null.";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public IKMappingBone()
|
|
{
|
|
}
|
|
|
|
public IKMappingBone(Transform bone)
|
|
{
|
|
this.bone = bone;
|
|
}
|
|
|
|
public void StoreDefaultLocalState()
|
|
{
|
|
boneMap.StoreDefaultLocalState();
|
|
}
|
|
|
|
public void FixTransforms()
|
|
{
|
|
boneMap.FixTransform(position: false);
|
|
}
|
|
|
|
public override void Initiate(IKSolverFullBody solver)
|
|
{
|
|
if (boneMap == null)
|
|
{
|
|
boneMap = new BoneMap();
|
|
}
|
|
boneMap.Initiate(bone, solver);
|
|
}
|
|
|
|
public void ReadPose()
|
|
{
|
|
boneMap.MaintainRotation();
|
|
}
|
|
|
|
public void WritePose(float solverWeight)
|
|
{
|
|
boneMap.RotateToMaintain(solverWeight * maintainRotationWeight);
|
|
}
|
|
}
|
|
}
|