Пример #1
0
        public static void CopyLineSphereColliderWithSameHierarchy(GameObject src, GameObject des)
        {
            if (src == null || des == null)
            {
                Debug.LogError("_src == null || _des == null");
                return;
            }
            else
            {
                LineSphereCollider[] scripts = src.GetComponentsInChildren <LineSphereCollider>(true);
                for (int i = 0; i < scripts.Length; i++)
                {
                    Transform trs  = scripts[i].transform;
                    string    path = AnimationUtility.CalculateTransformPath(trs, src.transform);

                    Transform desTrs = des.transform.Find(path);
                    if (desTrs == null)
                    {
                        Debug.LogError("Fail: src and des dismatch in Hierarchy...");
                        return;
                    }
                    RootColliderManager smanager = desTrs.GetComponent <RootColliderManager>();
                    if (smanager == null)
                    {
                        smanager = desTrs.gameObject.AddComponent <RootColliderManager>();
                    }

                    LineSphereCollider sp = desTrs.gameObject.AddComponent <LineSphereCollider>();
                    LineSphereCollider s1 = scripts[i];

                    sp.A       = s1.A;
                    sp.B       = s1.B;
                    sp.RadiusA = s1.RadiusA;
                    sp.RadiusB = s1.RadiusB;

                    sp.scaleAFactor = s1.scaleAFactor;
                    sp.scaleBFactor = s1.scaleBFactor;

                    sp.EditorAFactor   = s1.EditorAFactor;
                    sp.EditorBFactor   = s1.EditorBFactor;
                    sp.lineIndex       = s1.lineIndex;
                    sp._enableCollider = s1._enableCollider;
                    sp._startBone      = s1._startBone;
                    sp._endBone        = s1._endBone;

                    smanager._lineSphereColliders.Add(sp);
                }
            }
        }
Пример #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 ##");
        }
Пример #3
0
        public static void CopyLineSphereColliderWithAvatar(GameObject src, GameObject des)
        {
            if (src == null || des == null)
            {
                Debug.LogError("_src == null || _des == null");
                return;
            }

            Animator animatorSrc = src.GetComponent <Animator>();
            Animator animatorDes = des.GetComponent <Animator>();

            if (animatorSrc == null || animatorDes == null)
            {
                Debug.LogError("animator src == null || animator src == null");
                return;
            }

            int boneCount = (int)HumanBodyBones.LastBone - 1;

            for (int i = 0; i < boneCount; i++)
            {
                HumanBodyBones bone   = (HumanBodyBones)i;
                Transform      trs01  = animatorSrc.GetBoneTransform(bone);
                Transform      trsDes = animatorDes.GetBoneTransform(bone);
                if (trs01 == null)
                {
                    continue;
                }
                if (trs01 != null && trsDes == null)
                {
                    Debug.LogError("Two humanoid does have the same bone please Check");
                    return;
                }

                LineSphereCollider[] colliders = trs01.GetComponents <LineSphereCollider>();

                RootColliderManager smanager = trsDes.GetComponent <RootColliderManager>();
                if (smanager == null)
                {
                    smanager = trsDes.gameObject.AddComponent <RootColliderManager>();
                }

                for (int index = 0; index < colliders.Length; index++)
                {
                    LineSphereCollider sp = trsDes.gameObject.AddComponent <LineSphereCollider>();
                    LineSphereCollider s1 = colliders[index];

                    sp.A       = s1.A;
                    sp.B       = s1.B;
                    sp.RadiusA = s1.RadiusA;
                    sp.RadiusB = s1.RadiusB;

                    sp.scaleAFactor = s1.scaleAFactor;
                    sp.scaleBFactor = s1.scaleBFactor;

                    sp.EditorAFactor   = s1.EditorAFactor;
                    sp.EditorBFactor   = s1.EditorBFactor;
                    sp.lineIndex       = s1.lineIndex;
                    sp._enableCollider = s1._enableCollider;
                    sp._startBone      = s1._startBone;
                    sp._endBone        = s1._endBone;

                    smanager._lineSphereColliders.Add(sp);
                }
            }
        }