using System.Collections.Generic; using UnityEngine; namespace UniHumanoid { /// /// Mapping HumanBodyBones to BoneIndex /// public struct Skeleton { Dictionary m_indexMap; public Dictionary Bones { get { return m_indexMap; } } public int GetBoneIndex(HumanBodyBones bone) { int index; if (m_indexMap.TryGetValue(bone, out index)) { return index; } else { return -1; } } #if UNITY_EDITOR /// /// For UnitTest /// Dictionary m_nameMap; /// /// ForTest /// /// /// public string GetBoneName(HumanBodyBones bone) { string name; if (m_nameMap.TryGetValue(bone, out name)) { return name; } else { return null; } } #endif public static Skeleton Estimate(Transform hips) { var estimater = new BvhSkeletonEstimator(); return estimater.Detect(hips); } /// /// Register bone's HumanBodyBones /// /// /// /// public void Set(HumanBodyBones bone, IList bones, IBone b) { if (b != null) { Set(bone, bones.IndexOf(b), b.Name); } } public void Set(HumanBodyBones bone, int index, string name) { if (m_indexMap == null) { m_indexMap = new Dictionary(); } m_indexMap[bone] = index; #if UNITY_EDITOR if (m_nameMap == null) { m_nameMap = new Dictionary(); } m_nameMap[bone] = name; #endif } } }