private void ApplyDNA(TestDNA testDNA) { SkinnedMeshRenderer renderer = testDNA.GetComponent <SkinnedMeshRenderer>(); Transform[] boneTransforms = renderer.bones; Transform transform = renderer.transform; string boneName = testDNA.DNABoneName; Vector3 dna = testDNA.DNA; DNAType dnaType = testDNA.DNAType; int boneIndex = FindBoneIndex(boneTransforms, boneName); if (boneIndex == -1) { Debug.LogFormat("骨骼名字{0}不存在", boneName); return; } Mesh mesh = renderer.sharedMesh; Matrix4x4[] bindposes = mesh.bindposes; // 在原来的bindposes上,再乘以dna的结果 Matrix4x4 dnaMatrix = MakeDNAMatrix(dna, dnaType); bindposes[boneIndex] = dnaMatrix * testDNA.OriginBindposes[boneIndex]; mesh.bindposes = bindposes; }
public override void OnInspectorGUI() { base.OnInspectorGUI(); TestDNA testDNA = target as TestDNA; if (GUILayout.Button("应用DNA")) { ApplyDNA(testDNA); } }