RigSync.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using EasyButtons;
  6. public class RigSync : MonoBehaviour
  7. {
  8. public Transform targetRootBone;
  9. public Transform sourceRootBone;
  10. [SerializeField]public List<TransformDic> boneDic;
  11. [Button]
  12. void CalculateDic()
  13. {
  14. boneDic = new List<TransformDic>();
  15. foreach(Transform target in targetRootBone.GetComponentsInChildren<Transform>()){
  16. foreach(Transform souce in sourceRootBone.GetComponentsInChildren<Transform>()){
  17. if(target.name == souce.name){
  18. boneDic.Add(new TransformDic(souce, target));
  19. break;
  20. }
  21. }
  22. }
  23. }
  24. // Update is called once per frame
  25. void LateUpdate()
  26. {
  27. foreach(TransformDic bonePair in boneDic){
  28. bonePair.value.position = Vector3.Lerp(bonePair.value.position, bonePair.key.position + bonePair.offset, 0.1f);
  29. // bonePair.value.rotation = Quaternion.Lerp(bonePair.value.rotation, bonePair.key.rotation, 0.1f);
  30. bonePair.value.rotation = bonePair.key.rotation;
  31. }
  32. }
  33. }
  34. [Serializable]
  35. public class TransformDic{
  36. public string name;
  37. public Transform key;
  38. public Transform value;
  39. public Vector3 offset;
  40. public TransformDic(){
  41. key = null;
  42. value=null;
  43. }
  44. public TransformDic(Transform _key, Transform _value){
  45. name = _key.name;
  46. key=_key;
  47. value=_value;
  48. offset=_value.position - _key.position;
  49. }
  50. }