Example #1
0
    public void MapHumanAvatarToBoneReferences(Transform root, Animator animator)
    {
        HumanBodyBoneReferenceData reference = this;

        if (animator == null || root == null)
        {
            return;
        }
        reference.root = root;
        for (int i = 0; i < _listMappingBoneName.Count; i++)
        {
            _dicBones[_listMappingBoneName[i]] = animator.GetBoneTransform((HumanBodyBones)_listMappingBoneName[i]);
        }
    }
Example #2
0
        public static void CreateJoints(Transform root, HumanBodyBoneReferenceData r, bool isReal)
        {
            // Hip
            // Spine
            // Chest
            // Shoulder
            // Arm
            // Leg

            // Clear Colliders
            LineSphereCollider[] preColliders = root.gameObject.GetComponentsInChildren <LineSphereCollider>(true);
            for (int i = 0; i < preColliders.Length; i++)
            {
                GameObject.DestroyImmediate(preColliders[i]);
            }
            RootColliderManager[] mgs = root.gameObject.GetComponentsInChildren <RootColliderManager>(true);
            for (int i = 0; i < mgs.Length; i++)
            {
                GameObject.DestroyImmediate(mgs[i]);
            }

            Transform trsLeftUpperArm  = r._dicBones[(int)HumanBodyBones.LeftUpperArm];
            Transform trsRightUpperArm = r._dicBones[(int)HumanBodyBones.RightUpperArm];
            Transform trsLeftLowerArm  = r._dicBones[(int)HumanBodyBones.LeftLowerArm];
            Transform trsLeftUpperLeg  = r._dicBones[(int)HumanBodyBones.LeftUpperLeg];
            Transform trsLeftLowerLeg  = r._dicBones[(int)HumanBodyBones.LeftLowerLeg];

            float   upperArmDis = Vector3.Distance(trsLeftUpperArm.position, trsLeftLowerArm.position);
            float   legDis      = Vector3.Distance(trsLeftUpperLeg.position, trsLeftLowerLeg.position);
            Vector3 v2          = trsLeftUpperArm.position - trsRightUpperArm.position;
            float   torsoWidth  = v2.magnitude;

            // check Optional JointConfig
            bool hasChest    = r.CheckBone(HumanBodyBones.Chest);
            bool hasShoulder = r.CheckBone(HumanBodyBones.LeftShoulder);
            bool hasNeck     = r.CheckBone(HumanBodyBones.Neck);

            _cacheList.Clear();
            if (!hasChest)
            {
                if (hasShoulder)
                {
                    _cacheList.Add(optionalSpineWithOutChestJoint);
                }
                else
                {
                    _cacheList.Add(optionalSpineWithOutCheckShoulderJoint);
                }
                if (!hasNeck)
                {
                    _cacheList.Add(optionaSpineWithOutNeck);
                }
            }
            else
            {
                if (!hasShoulder)
                {
                    _cacheList.Add(optionalChestWithOutShoulderJoint);
                }
                if (!hasNeck)
                {
                    _cacheList.Add(optionalCheckWithOutNeck);
                }
            }

            _cacheList.AddRange(_listJointConfigs007);
            for (int i = 0; i < _cacheList.Count; i++)
            {
                JointConfig    jc       = _cacheList[i];
                HumanBodyBones rootBone = jc._rootBone;
                if (!r._dicBones.ContainsKey((int)rootBone) || (r._dicBones[(int)rootBone] == null))
                {
                    continue;
                }
                List <HumanBodyBones> jointBones = jc._bones;
                Transform             rootTrs    = r._dicBones[(int)rootBone];

                bool hasCollider = false;
                for (int boneIndex = 0; boneIndex < jointBones.Count; boneIndex++)
                {
                    HumanBodyBones bone = jointBones[boneIndex];
                    if (!r._dicBones.ContainsKey((int)jointBones[boneIndex]) ||
                        (r._dicBones[(int)jointBones[boneIndex]]) == null)
                    {
                        continue;
                    }
                    Transform          boneTrs  = r._dicBones[(int)jointBones[boneIndex]];
                    LineSphereCollider collider = rootTrs.gameObject.AddComponent <LineSphereCollider>();
                    collider._startBone = rootBone;
                    collider._endBone   = jointBones[boneIndex];
                    collider.WorldA     = rootTrs.position;
                    collider.WorldB     = boneTrs.position;

                    float a = GetRadius(upperArmDis, legDis, torsoWidth, rootBone);
                    float b = GetRadius(upperArmDis, legDis, torsoWidth, bone);

                    collider.RadiusA = a;
                    collider.RadiusB = b;
                    hasCollider      = true;
                }

                if (hasCollider)
                {
                    RootColliderManager mg = rootTrs.gameObject.AddComponent <RootColliderManager>();
                    mg.InitRootColliderManagerWhenCreate();
                }
            }
            // Debug.Log("## Create Joints Point collider over ##");
        }
Example #3
0
        private void OnGUI()
        {
            EditorGUILayout.HelpBox("Copy , Clear Humanoid Collider", MessageType.Info);
            EditorTools.DrawLabelWithColorInBox("Copy", Color.green);

            m_Src = EditorGUILayout.ObjectField("Source", m_Src, typeof(GameObject), true) as GameObject;
            m_Des = EditorGUILayout.ObjectField("Destination", m_Des, typeof(GameObject), true) as GameObject;

            // If your humanoid character has same "bone" name
            if (GUILayout.Button("Copy Line-Sphere With Same Hierarchy", GUILayout.MinHeight(25)))
            {
                if (m_Src == null || m_Des == null)
                {
                    EditorTools.ShowMessage("Src or Des is Null...");
                }
                else
                {
                    FTPColliderTools.CopyLineSphereColliderWithSameHierarchy(m_Src, m_Des);
                }
            }
            // If your humanoid character has unsame "bone" name you can use Avatar to copy Collider
            if (GUILayout.Button("Copy Line-Sphere with Avatar Settings", GUILayout.MinHeight(25)))
            {
                if (m_Src == null || m_Des == null)
                {
                    EditorTools.ShowMessage("Src or Des is Null...");
                }
                else
                {
                    FTPColliderTools.CopyLineSphereColliderWithAvatar(m_Src, m_Des);
                }
            }

            EditorTools.DrawSpace(4);
            EditorTools.DrawLabelWithColorInBox("Clear", Color.green);
            m_ClearHumanoidColliderTarget = EditorGUILayout.ObjectField("Clear Target", m_ClearHumanoidColliderTarget, typeof(GameObject), true) as GameObject;
            // clear line-sphere collider
            if (GUILayout.Button("Clear Line-Sphere Collider", GUILayout.MinHeight(25)))
            {
                FTPColliderTools.ClearLineSphereCollider(m_ClearHumanoidColliderTarget);
            }

            // clear normal box or other real collider
            // just clear bone collider with avatar bone map
            if (GUILayout.Button("Clear Normal Collider", GUILayout.MinHeight(25)))
            {
                if (m_ClearHumanoidColliderTarget != null)
                {
                    Animator animator = m_ClearHumanoidColliderTarget.GetComponent <Animator>();
                    if (animator == null || !animator.isHuman || animator.avatar == null)
                    {
                        EditorTools.ShowMessage("Collider Target Need Animator to get avatar bone map.check Collider target is the Animator root?" +
                                                "And We need Humanoid Target and with Avatar set");
                    }
                    else
                    {
                        if (EditorUtility.DisplayDialog("Message", "Clear Humanoid Normal Collider with Avatar Bone?", "OK", "Cancel"))
                        {
                            if (newAvatarBoneData == null)
                            {
                                newAvatarBoneData = new HumanBodyBoneReferenceData();
                            }
                            newAvatarBoneData.ResetReference();
                            newAvatarBoneData.MapHumanAvatarToBoneReferences(m_ClearHumanoidColliderTarget.transform, animator);

                            foreach (var bone in newAvatarBoneData._dicBones)
                            {
                                if (bone.Value != null)
                                {
                                    Collider[] colliders = bone.Value.GetComponents <Collider>();
                                    for (int i = 0; i < colliders.Length; i++)
                                    {
                                        Object.DestroyImmediate(colliders[i]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }