56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
using EasyButtons;
|
|
|
|
public class RigSync : MonoBehaviour
|
|
{
|
|
public Transform targetRootBone;
|
|
public Transform sourceRootBone;
|
|
[SerializeField]public List<TransformDic> boneDic;
|
|
|
|
[Button]
|
|
void CalculateDic()
|
|
{
|
|
boneDic = new List<TransformDic>();
|
|
|
|
foreach(Transform target in targetRootBone.GetComponentsInChildren<Transform>()){
|
|
foreach(Transform souce in sourceRootBone.GetComponentsInChildren<Transform>()){
|
|
if(target.name == souce.name){
|
|
boneDic.Add(new TransformDic(souce, target));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void LateUpdate()
|
|
{
|
|
foreach(TransformDic bonePair in boneDic){
|
|
bonePair.value.position = Vector3.Lerp(bonePair.value.position, bonePair.key.position + bonePair.offset, 0.1f);
|
|
// bonePair.value.rotation = Quaternion.Lerp(bonePair.value.rotation, bonePair.key.rotation, 0.1f);
|
|
bonePair.value.rotation = bonePair.key.rotation;
|
|
}
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class TransformDic{
|
|
public string name;
|
|
public Transform key;
|
|
public Transform value;
|
|
public Vector3 offset;
|
|
|
|
public TransformDic(){
|
|
key = null;
|
|
value=null;
|
|
}
|
|
public TransformDic(Transform _key, Transform _value){
|
|
name = _key.name;
|
|
key=_key;
|
|
value=_value;
|
|
offset=_value.position - _key.position;
|
|
}
|
|
} |