Esempio n. 1
0
        /*
         *      Build the runtime representations of the ragdoll bones
         *
         *      Adds the ragdoll components (Rigidbodies, joints, colliders...) if they werent
         *      pre built in the editor.
         *
         *      then the variables, (like joint limits and rigidbody masses),
         *      are adjusted via the ragdoll profile
         */
        void Awake()
        {
            if (!initializedValues)
            {
                initializedValues = true;

                Animator myAnimator = GetComponent <Animator>();

                //if there werent any errros
                if (RagdollBuilder.BuildRagdollElements(myAnimator, out allElements, out boneElements))
                {
                    RagdollBuilder.BuildBones(myAnimator, ragdollProfile, !preBuilt, boneElements, out initialHeadOffsetFromChest);


                    //set the bones to the ragdoll layer
                    //SetLayer(LayerMask.NameToLayer("Ragdoll"));

                    //get all renderers
                    allRenderers = GetComponentsInChildren <Renderer>();

                    InitializeRagdollBoneComponents();
                }
                //display errors
                else
                {
                    CheckForErroredRagdoll("Awake");
                }
            }
        }
        /*
         *      set teh follow target for this ragdoll
         *
         *      assumes that the animator avatar is humanoid and has the same transform bone setup
         *
         *      as the animator and avatar on this ragdoll object
         */
        public void SetFollowTarget(Animator followAnimator)
        {
            if (CheckForErroredRagdoll("SetFollowTarget"))
            {
                return;
            }

            // generate Ragdoll transforms for the follow target

            RagdollTransform[] followTransforms;

            // if there was an error return...
            if (!RagdollBuilder.BuildRagdollElements(followAnimator, out followTransforms, out _))
            {
                return;
            }

            int l = followTransforms.Length;

            if (l != allElements.Length)
            {
                Debug.LogError("children list different sizes for ragdoll: " + name + ", and follow target: " + followAnimator.name);
                return;
            }

            //set follow targets on our bones as these new master bones
            for (int i = 0; i < l; i++)
            {
                allElements[i].SetFollowTarget(followTransforms[i]);
            }
        }
Esempio n. 3
0
        /*
         *      set teh follow target for this ragdoll
         *
         *      assumes that the animator avatar is humanoid and has the same transform bone setup
         *
         *      as the animator and avatar on this ragdoll object
         */
        public void SetFollowTarget(Animator followAnimator)
        {
            if (CheckForErroredRagdoll("SetFollowTarget"))
            {
                return;
            }

            // generate Ragdoll elements for the follow target
            // set as non physics, so no profile or adding of components needed,

            Element[] followElements;

            // if there was an error return...
            //if (!RagdollBuilder.BuildRagdoll(followAnimator, null, false, true, out _, out followElements, out _)) {
            if (!RagdollBuilder.BuildRagdollElements(followAnimator, out followElements, out _))
            {
                return;
            }

            int l = followElements.Length;

            if (l != allElements.Length)
            {
                Debug.LogError("children list different sizes for ragdoll: " + name + ", and follow target: " + followAnimator.name);
                return;
            }

            //set follow targets on our bones as these new master bones
            for (int i = 0; i < l; i++)
            {
                allElements[i].SetFollowTarget(followElements[i]);
            }
        }
        void DrawBuildOptions()
        {
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();

            SerializedProperty preBuiltProp = serializedObject.FindProperty("preBuilt");

            bool isBuilt = preBuiltProp.boolValue;

            if (isBuilt)
            {
                if (GUILayout.Button(isBuilt ? "Clear Ragdoll" : "Pre Build Ragdoll"))
                {
                    RagdollBuilder.EraseRagdoll(ragdoll.GetComponent <Animator>());
                    preBuiltProp.boolValue = !isBuilt;
                }
            }
            else
            {
                GUI.enabled = ragdoll.ragdollProfile != null;
                if (GUILayout.Button(isBuilt ? "Clear Ragdoll" : "Pre Build Ragdoll"))
                {
                    System.Collections.Generic.Dictionary <HumanBodyBones, RagdollTransform> bones;
                    RagdollBuilder.BuildRagdollElements(ragdoll.GetComponent <Animator>(), out _, out bones);
                    RagdollBuilder.BuildBones(ragdoll.GetComponent <Animator>(), ragdoll.ragdollProfile, true, bones, out _);
                    preBuiltProp.boolValue = !isBuilt;
                }
                GUI.enabled = true;
            }



            if (isBuilt)
            {
                GUI.enabled = ragdoll.ragdollProfile != null;
                // if (ragdoll.ragdollProfile) {

                if (GUILayout.Button("Update Ragdoll To Profile"))
                {
                    System.Collections.Generic.Dictionary <HumanBodyBones, RagdollTransform> bones;
                    RagdollBuilder.BuildRagdollElements(ragdoll.GetComponent <Animator>(), out _, out bones);
                    RagdollBuilder.BuildBones(ragdoll.GetComponent <Animator>(), ragdoll.ragdollProfile, false, bones, out _);
                }
                GUI.enabled = true;
                // }
            }
            EditorGUILayout.EndHorizontal();
        }