Exemplo n.º 1
0
        bool _createRagdollManager()
        {
            RagdollManager ragMan = character.GetComponent <RagdollManager>();

            if (!ragMan)
            {
                //ragMan = character.AddComponent<RagdollManager>();
                ragMan = Undo.AddComponent <RagdollManager>(character);
            }
            if (useHumanoidSetupForRagdollBones)
            {
                Animator anim = character.GetComponent <Animator>();
                if (!anim)
                {
                    Debug.LogError("Cannot find 'animator' component." + " < " + this.ToString() + ">"); return(false);
                }

                ragdollCreator.pelvis      = anim.GetBoneTransform(HumanBodyBones.Hips);
                ragdollCreator.leftHips    = anim.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
                ragdollCreator.leftKnee    = anim.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
                ragdollCreator.leftFoot    = anim.GetBoneTransform(HumanBodyBones.LeftFoot);
                ragdollCreator.rightHips   = anim.GetBoneTransform(HumanBodyBones.RightUpperLeg);
                ragdollCreator.rightKnee   = anim.GetBoneTransform(HumanBodyBones.RightLowerLeg);
                ragdollCreator.rightFoot   = anim.GetBoneTransform(HumanBodyBones.RightFoot);
                ragdollCreator.leftArm     = anim.GetBoneTransform(HumanBodyBones.LeftUpperArm);
                ragdollCreator.leftElbow   = anim.GetBoneTransform(HumanBodyBones.LeftLowerArm);
                ragdollCreator.rightArm    = anim.GetBoneTransform(HumanBodyBones.RightUpperArm);
                ragdollCreator.rightElbow  = anim.GetBoneTransform(HumanBodyBones.RightLowerArm);
                ragdollCreator.middleSpine = anim.GetBoneTransform(HumanBodyBones.Chest);
                ragdollCreator.head        = anim.GetBoneTransform(HumanBodyBones.Head);

                ragdollCreator.totalMass = totalMass;

                ragdollCreator.CheckConsistency();
                ragdollCreator.CalculateAxes();
                ragdollCreator.Create();

                ragMan.RagdollBones = new Transform[(int)BodyParts.BODY_PART_COUNT];
                ragMan.RagdollBones[(int)BodyParts.Spine]         = ragdollCreator.pelvis;
                ragMan.RagdollBones[(int)BodyParts.Chest]         = ragdollCreator.middleSpine;
                ragMan.RagdollBones[(int)BodyParts.Head]          = ragdollCreator.head;
                ragMan.RagdollBones[(int)BodyParts.LeftShoulder]  = ragdollCreator.leftArm;
                ragMan.RagdollBones[(int)BodyParts.LeftElbow]     = ragdollCreator.leftElbow;
                ragMan.RagdollBones[(int)BodyParts.RightShoulder] = ragdollCreator.rightArm;
                ragMan.RagdollBones[(int)BodyParts.RightElbow]    = ragdollCreator.rightElbow;
                ragMan.RagdollBones[(int)BodyParts.LeftHip]       = ragdollCreator.leftHips;
                ragMan.RagdollBones[(int)BodyParts.LeftKnee]      = ragdollCreator.leftKnee;
                ragMan.RagdollBones[(int)BodyParts.RightHip]      = ragdollCreator.rightHips;
                ragMan.RagdollBones[(int)BodyParts.RightKnee]     = ragdollCreator.rightKnee;
                RagdollManager.AddBodyColliderScripts(ragMan);


                ragdollCreator = null;
            }

            return(true);
        }
Exemplo n.º 2
0
        // unity OnInspectorGUI method
        public override void OnInspectorGUI()
        {
            RagdollManager ragMan = (RagdollManager)target;

            DrawDefaultInspector();

            if (ragMan.hitInterval == RagdollManager.HitIntervals.Timed)
            {
                float hitInterval = (float)EditorGUILayout.FloatField("Hit Interval", ragMan.hitTimeInterval);
                ragMan.hitTimeInterval = hitInterval;
            }

            bool enableGetUp = (bool)EditorGUILayout.Toggle("Enable Get Up Animation", ragMan.enableGetUpAnimation);

            ragMan.enableGetUpAnimation = enableGetUp;

            string text = (string)EditorGUILayout.TextField("Name Of Get Up From Back State", ragMan.nameOfGetUpFromBackState);

            ragMan.nameOfGetUpFromBackState = text;

            text = (string)EditorGUILayout.TextField("Name Of Get Up From Front State", ragMan.nameOfGetUpFromFrontState);
            ragMan.nameOfGetUpFromFrontState = text;

            bool ragdollWizard = GUILayout.Button("Ragdoll Wizard");

            if (ragdollWizard)
            {
                RagdollCreatorWizard builderWizard = RagdollCreatorWizard.DisplayWizard();
                RagdollCreator       builder       = builderWizard.ragdollCreator;
                builder.OnWizardCreateCallback = () =>
                {
                    ragMan.RagdollBones = new Transform[(int)BodyParts.BODY_PART_COUNT];
                    ragMan.RagdollBones[(int)BodyParts.Spine]         = builder.pelvis;
                    ragMan.RagdollBones[(int)BodyParts.Chest]         = builder.middleSpine;
                    ragMan.RagdollBones[(int)BodyParts.Head]          = builder.head;
                    ragMan.RagdollBones[(int)BodyParts.LeftShoulder]  = builder.leftArm;
                    ragMan.RagdollBones[(int)BodyParts.LeftElbow]     = builder.leftElbow;
                    ragMan.RagdollBones[(int)BodyParts.RightShoulder] = builder.rightArm;
                    ragMan.RagdollBones[(int)BodyParts.RightElbow]    = builder.rightElbow;
                    ragMan.RagdollBones[(int)BodyParts.LeftHip]       = builder.leftHips;
                    ragMan.RagdollBones[(int)BodyParts.LeftKnee]      = builder.leftKnee;
                    ragMan.RagdollBones[(int)BodyParts.RightHip]      = builder.rightHips;
                    ragMan.RagdollBones[(int)BodyParts.RightKnee]     = builder.rightKnee;


                    EditorUtility.SetDirty(ragMan);
                    serializedObject.ApplyModifiedProperties();

                    RagdollManager.AddBodyColliderScripts(ragMan);

                    builder.OnWizardCreateCallback = null;
                };
            }


            bool removeRagdoll = GUILayout.Button("Remove Ragoll");

            if (removeRagdoll)
            {
                if (ragMan.RagdollBones.Length == (int)BodyParts.BODY_PART_COUNT)
                {
                    for (int i = 0; i < (int)BodyParts.BODY_PART_COUNT; i++)
                    {
                        Transform t = ragMan.RagdollBones[i];
                        if (!t)
                        {
                            continue;
                        }
                        CharacterJoint[]     t_joints = t.GetComponents <CharacterJoint>();
                        Collider[]           t_cols   = t.GetComponents <Collider>();
                        Rigidbody[]          t_rbs    = t.GetComponents <Rigidbody>();
                        BodyColliderScript[] t_bcs    = t.GetComponents <BodyColliderScript>();
                        foreach (CharacterJoint cj in t_joints)
                        {
                            DestroyImmediate(cj);
                        }
                        foreach (Collider c in t_cols)
                        {
                            DestroyImmediate(c);
                        }
                        foreach (Rigidbody rb in t_rbs)
                        {
                            DestroyImmediate(rb);
                        }
                        foreach (BodyColliderScript b in t_bcs)
                        {
                            DestroyImmediate(b);
                        }
                        ragMan.RagdollBones[i] = null;
                    }
                    ragMan.RagdollBones = null;
                    EditorUtility.SetDirty(ragMan);
                    serializedObject.ApplyModifiedProperties();
                }
            }



            bool addColSc = GUILayout.Button("Add Collider Scripts");

            if (addColSc)
            {
                RagdollManager.AddBodyColliderScripts(ragMan);
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(ragMan);
                serializedObject.ApplyModifiedProperties();
            }
        }