MeshCombine.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using EasyButtons;
  5. public class MeshCombine : MonoBehaviour
  6. {
  7. public SkinnedMeshRenderer target;
  8. public Transform sourceRootBone;
  9. public Transform[] bones;
  10. [Button]
  11. void Recalculate(){
  12. target.rootBone = sourceRootBone;
  13. //target.bones = src.bones;
  14. Transform[] bonesT = new Transform[target.bones.Length];
  15. for(int i = 0; i < target.bones.Length; i++){
  16. Transform targetBone = target.bones[i];
  17. string targetBoneName = targetBone.name;
  18. foreach(Transform sourceBone in sourceRootBone.GetComponentsInChildren<Transform>()){
  19. if(targetBoneName == sourceBone.name){
  20. Debug.Log("Switching bone : " + targetBoneName );
  21. bonesT[i] = sourceBone;
  22. break;
  23. }
  24. }
  25. }
  26. target.bones= bonesT;
  27. bones= target.bones;
  28. target.sharedMesh.RecalculateNormals();
  29. target.sharedMesh.RecalculateBounds();
  30. }
  31. [Button]
  32. void GetSelfRenderer(){
  33. target = GetComponent<SkinnedMeshRenderer>();
  34. }
  35. }