Exemplo n.º 1
0
        protected IEnumerator ConvertToRagdollAfterTime(bool ragdoll, float delay)
        {
            double waitUntil = Frontiers.WorldClock.AdjustedRealTime + delay;

            while (Frontiers.WorldClock.AdjustedRealTime < waitUntil)
            {
                yield return(null);
            }
            if (ragdoll)
            {
                //if we're converting TO a ragdoll
                //disable rigid body and animator
                //then enable the body part rigid bodies
                Animator.animator.enabled = false;
                Animator.enabled          = false;

                for (int i = BodyParts.Count - 1; i >= 0; i--)
                {
                    BodyParts [i].ConvertToRagdoll();
                }

                IgnoreCollisions(false);
                yield return(null);

                //wait for rigid bodies to get initialized
                //then link them up and set links to zero

                for (int i = 0; i < BodyParts.Count; i++)
                {
                    BodyParts [i].LinkRagdollParts(this);
                }

                IsRagdoll = true;
            }
            else
            {
                //if we're converting FROM a ragdoll
                //disable the body part rigid bodies
                //then enable rigid body and animator
                Component[] Joints = gameObject.GetComponentsInChildren <Joint> ();
                for (int i = 0; i < Joints.Length; i++)
                {
                    GameObject.Destroy(Joints [i]);
                }
                for (int i = BodyParts.LastIndex(); i >= 0; i--)
                {
                    if (BodyParts [i].RagdollRB != null)
                    {
                        GameObject.Destroy(BodyParts [i].RagdollRB);
                    }
                }

                for (int i = BodyParts.LastIndex(); i >= 0; i--)
                {
                    BodyParts [i].ConvertToAnimated();
                }

                //IgnoreCollisions (false);
                Animator.animator.enabled = true;
                Animator.enabled          = true;
                IsRagdoll = false;
            }
            mConvertingToRagdoll = false;
            yield break;
        }