kakozuzo/Code/swb_base/util/ModelUtil.cs

23 lines
599 B
C#
Raw Permalink Normal View History

2024-10-30 19:01:58 +03:00
using System.Linq;
namespace SWB.Base;
public class ModelUtil
{
public static void ParentToBone( GameObject gameObject, SkinnedModelRenderer target, string bone )
{
var targetBone = target.Model.Bones.AllBones.FirstOrDefault( b => b.Name == bone );
if ( targetBone is null )
{
Log.Error( $"Could not find bone '{bone}' on {target}" );
return;
}
var holdBoneGo = target.GetBoneObject( targetBone );
Log.Info(holdBoneGo);
gameObject.SetParent( holdBoneGo );
gameObject.WorldPosition = holdBoneGo.WorldPosition;
gameObject.WorldRotation = holdBoneGo.WorldRotation;
}
}