#pragma warning disable 618 void Update() { if (runScript && umaData) { umaData.boneHashList = new Dictionary <int, UMAData.BoneData>(); Transform[] umaBones = boneStructure.gameObject.GetComponentsInChildren <Transform>(); umaData.tempBoneData = new UMAData.BoneData[umaBones.Length]; for (int i = 0; i < umaBones.Length; i++) { UMAData.BoneData tempBone = new UMAData.BoneData(); tempBone.boneTransform = umaBones[i]; tempBone.originalBonePosition = umaBones[i].localPosition; tempBone.originalBoneRotation = umaBones[i].localRotation; tempBone.originalBoneScale = umaBones[i].localScale; umaData.boneHashList.Add(UMASkeleton.StringToHash(umaBones[i].name), tempBone); umaData.tempBoneData[i] = tempBone; //Only while Dictionary can't be serialized } Debug.Log(umaData.boneHashList.Count + " bones have been included"); ReplaceAnimatedBones(); } runScript = false; }
internal int[] GetAnimatedBones() { #pragma warning disable 618 List <int> res = new List <int>(tempBoneData.Length); Dictionary <int, int> resHash = new Dictionary <int, int>(tempBoneData.Length); for (int slotDataIndex = 0; slotDataIndex < umaRecipe.slotDataList.Length; slotDataIndex++) { var slotData = umaRecipe.slotDataList[slotDataIndex]; if (slotData == null) { continue; } if (slotData.animatedBones == null || slotData.animatedBones.Length == 0) { continue; } for (int animatedBoneIndex = 0; animatedBoneIndex < slotData.animatedBones.Length; animatedBoneIndex++) { var animatedBone = slotData.animatedBones[animatedBoneIndex]; var hashName = UMASkeleton.StringToHash(animatedBone.name); if (resHash.ContainsKey(hashName)) { continue; } resHash.Add(hashName, hashName); res.Add(hashName); } } return(res.ToArray()); #pragma warning restore 618 }
public void UpdateBoneData() { if (tempBoneData == null) { return; } for (int i = 0; i < tempBoneData.Length; i++) { boneHashList.Add(UMASkeleton.StringToHash(tempBoneData[i].boneTransform.gameObject.name), tempBoneData[i]); } }
public void UpdateBoneData() { #pragma warning disable 618 if (tempBoneData == null) { return; } for (int i = 0; i < tempBoneData.Length; i++) { boneHashList.Add(UMASkeleton.StringToHash(tempBoneData[i].boneTransform.gameObject.name), tempBoneData[i]); } #pragma warning restore 618 }
public void EnsureBoneData(Transform[] umaBones, Transform[] animBones, Dictionary <Transform, Transform> boneMap) { #pragma warning disable 618 foreach (Transform bone in umaBones) { int nameHash = UMASkeleton.StringToHash(bone.name); if (!boneHashList.ContainsKey(nameHash)) { Transform umaBone; if (!boneMap.TryGetValue(bone, out umaBone)) { continue; } BoneData newBoneData = new BoneData(); newBoneData.originalBonePosition = umaBone.localPosition; newBoneData.originalBoneScale = umaBone.localScale; newBoneData.originalBoneRotation = umaBone.localRotation; newBoneData.boneTransform = umaBone; newBoneData.actualBonePosition = umaBone.localPosition; newBoneData.actualBoneScale = umaBone.localScale; boneHashList.Add(UMASkeleton.StringToHash(umaBone.name), newBoneData); } } if (animBones != null) { List <Transform> newBones = new List <Transform>(); foreach (Transform bone in animBones) { Transform umaBone = boneMap[bone]; if ((umaBone != null) && (System.Array.IndexOf(animatedBones, umaBone) < 0)) { newBones.Add(umaBone); } } if (newBones.Count > 0) { int oldSize = animatedBones.Length; System.Array.Resize <Transform>(ref animatedBones, oldSize + newBones.Count); for (int i = 0; i < newBones.Count; i++) { animatedBones[oldSize + i] = newBones[i]; } } } #pragma warning restore 618 }
private void AddBonesRecursive(Transform transform) { var hash = UMASkeleton.StringToHash(transform.name); boneHashData[hash] = new UMAData.BoneData() { boneTransform = transform, originalBonePosition = transform.localPosition, originalBoneScale = transform.localScale, originalBoneRotation = transform.localRotation }; for (int i = 0; i < transform.childCount; i++) { var child = transform.GetChild(i); AddBonesRecursive(child); } }
private static void SkeletonModifier(UMAData umaData, ref SkeletonBone[] bones) { Dictionary <Transform, Transform> animatedBones = new Dictionary <Transform, Transform>(); for (var i = 0; i < umaData.animatedBones.Length; i++) { animatedBones.Add(umaData.animatedBones[i], umaData.animatedBones[i]); } for (var i = 0; i < bones.Length; i++) { var skeletonbone = bones[i]; UMAData.BoneData entry; if (umaData.boneHashList.TryGetValue(UMASkeleton.StringToHash(skeletonbone.name), out entry)) { //var entry = umaData.boneList[skeletonbone.name]; skeletonbone.position = entry.boneTransform.localPosition; //skeletonbone.rotation = entry.boneTransform.localRotation; skeletonbone.scale = entry.boneTransform.localScale; bones[i] = skeletonbone; animatedBones.Remove(entry.boneTransform); } } if (animatedBones.Count > 0) { var newBones = new List <SkeletonBone>(bones); // iterate original list rather than dictionary to ensure that relative order is preserved for (var i = 0; i < umaData.animatedBones.Length; i++) { var animatedBone = umaData.animatedBones[i]; if (animatedBones.ContainsKey(animatedBone)) { var newBone = new SkeletonBone(); newBone.name = animatedBone.name; newBone.position = animatedBone.localPosition; newBone.rotation = animatedBone.localRotation; newBone.scale = animatedBone.localScale; newBones.Add(newBone); } } bones = newBones.ToArray(); } }
public void GotoTPose() { if (umaRecipe.raceData.TPose != null) { var tpose = umaRecipe.raceData.TPose; tpose.DeSerialize(); for (int i = 0; i < tpose.boneInfo.Length; i++) { var bone = tpose.boneInfo[i]; var hash = UMASkeleton.StringToHash(bone.name); var go = skeleton.GetBoneGameObject(hash); if (go == null) { continue; } skeleton.SetPosition(hash, bone.position); skeleton.SetRotation(hash, bone.rotation); skeleton.SetScale(hash, bone.scale); } } }
public GameObject GetBoneGameObject(string boneName) { return(GetBoneGameObject(UMASkeleton.StringToHash(boneName))); }