Inheritance: ScriptableWizard
Beispiel #1
0
 private void AddBreastColliders()
 {
     if (this.middleSpine != null && this.pelvis != null)
     {
         Bounds      bounds      = this.Clip(this.GetBreastBounds(this.pelvis), this.pelvis, this.middleSpine, false);
         BoxCollider boxCollider = this.pelvis.gameObject.AddComponent <BoxCollider>();
         boxCollider.center = bounds.center;
         boxCollider.size   = bounds.size;
         bounds             = this.Clip(this.GetBreastBounds(this.middleSpine), this.middleSpine, this.middleSpine, true);
         boxCollider        = this.middleSpine.gameObject.AddComponent <BoxCollider>();
         boxCollider.center = bounds.center;
         boxCollider.size   = bounds.size;
     }
     else
     {
         Bounds bounds2 = default(Bounds);
         bounds2.Encapsulate(this.pelvis.InverseTransformPoint(this.leftHips.position));
         bounds2.Encapsulate(this.pelvis.InverseTransformPoint(this.rightHips.position));
         bounds2.Encapsulate(this.pelvis.InverseTransformPoint(this.leftArm.position));
         bounds2.Encapsulate(this.pelvis.InverseTransformPoint(this.rightArm.position));
         Vector3 size = bounds2.size;
         size[RagdollBuilder.SmallestComponent(bounds2.size)] = size[RagdollBuilder.LargestComponent(bounds2.size)] / 2f;
         BoxCollider boxCollider2 = this.pelvis.gameObject.AddComponent <BoxCollider>();
         boxCollider2.center = bounds2.center;
         boxCollider2.size   = size;
     }
 }
Beispiel #2
0
 private void BuildJoints()
 {
     foreach (RagdollBuilder.BoneInfo boneInfo in this.bones)
     {
         if (boneInfo.parent != null)
         {
             CharacterJoint characterJoint = boneInfo.anchor.gameObject.AddComponent <CharacterJoint>();
             boneInfo.joint                     = characterJoint;
             characterJoint.axis                = RagdollBuilder.CalculateDirectionAxis(boneInfo.anchor.InverseTransformDirection(boneInfo.axis));
             characterJoint.swingAxis           = RagdollBuilder.CalculateDirectionAxis(boneInfo.anchor.InverseTransformDirection(boneInfo.normalAxis));
             characterJoint.anchor              = Vector3.zero;
             characterJoint.connectedBody       = boneInfo.parent.anchor.GetComponent <Rigidbody>();
             characterJoint.enablePreprocessing = false;
             SoftJointLimit softJointLimit = default(SoftJointLimit);
             softJointLimit.contactDistance = 0f;
             softJointLimit.limit           = boneInfo.minLimit;
             characterJoint.lowTwistLimit   = softJointLimit;
             softJointLimit.limit           = boneInfo.maxLimit;
             characterJoint.highTwistLimit  = softJointLimit;
             softJointLimit.limit           = boneInfo.swingLimit;
             characterJoint.swing1Limit     = softJointLimit;
             softJointLimit.limit           = 0f;
             characterJoint.swing2Limit     = softJointLimit;
         }
     }
 }
        private static int SecondLargestComponent(Vector3 point)
        {
            int num  = RagdollBuilder.SmallestComponent(point);
            int num2 = RagdollBuilder.LargestComponent(point);

            if (num < num2)
            {
                int num3 = num2;
                num2 = num;
                num  = num3;
            }
            int result;

            if (num == 0 && num2 == 1)
            {
                result = 2;
            }
            else if (num == 0 && num2 == 2)
            {
                result = 1;
            }
            else
            {
                result = 0;
            }
            return(result);
        }
Beispiel #4
0
        private void AddHeadCollider()
        {
            if (this.head.GetComponent <Collider>())
            {
                UnityEngine.Object.Destroy(this.head.GetComponent <Collider>());
            }
            float num = Vector3.Distance(this.leftArm.transform.position, this.rightArm.transform.position);

            num /= 4f;
            SphereCollider sphereCollider = this.head.gameObject.AddComponent <SphereCollider>();

            sphereCollider.radius = num;
            Vector3 zero = Vector3.zero;
            int     index;
            float   num2;

            RagdollBuilder.CalculateDirection(this.head.InverseTransformPoint(this.pelvis.position), out index, out num2);
            if (num2 > 0f)
            {
                zero[index] = -num;
            }
            else
            {
                zero[index] = num;
            }
            sphereCollider.center = zero;
        }
        private static Vector3 CalculateDirectionAxis(Vector3 point)
        {
            int   direction = 0;
            float distance;

            RagdollBuilder.CalculateDirection(point, out direction, out distance);
            Vector3 zero = Vector3.zero;

            zero[direction] = (double)distance <= 0.0 ? -1f : 1f;
            return(zero);
        }
Beispiel #6
0
        private Bounds GetBreastBounds(Transform relativeTo)
        {
            Bounds result = default(Bounds);

            result.Encapsulate(relativeTo.InverseTransformPoint(this.leftHips.position));
            result.Encapsulate(relativeTo.InverseTransformPoint(this.rightHips.position));
            result.Encapsulate(relativeTo.InverseTransformPoint(this.leftArm.position));
            result.Encapsulate(relativeTo.InverseTransformPoint(this.rightArm.position));
            Vector3 size = result.size;

            size[RagdollBuilder.SmallestComponent(result.size)] = size[RagdollBuilder.LargestComponent(result.size)] / 2f;
            result.size = size;
            return(result);
        }
        private Bounds GetBreastBounds(Transform relativeTo)
        {
            Bounds bounds = new Bounds();

            bounds.Encapsulate(relativeTo.InverseTransformPoint(this.leftHips.position));
            bounds.Encapsulate(relativeTo.InverseTransformPoint(this.rightHips.position));
            bounds.Encapsulate(relativeTo.InverseTransformPoint(this.leftArm.position));
            bounds.Encapsulate(relativeTo.InverseTransformPoint(this.rightArm.position));
            Vector3 size = bounds.size;

            size[RagdollBuilder.SmallestComponent(bounds.size)] = size[RagdollBuilder.LargestComponent(bounds.size)] / 2f;
            bounds.size = size;
            return(bounds);
        }
Beispiel #8
0
 private void BuildCapsules()
 {
     foreach (RagdollBuilder.BoneInfo boneInfo in this.bones)
     {
         if (boneInfo.colliderType == typeof(CapsuleCollider))
         {
             int   num;
             float num2;
             if (boneInfo.children.Count == 1)
             {
                 RagdollBuilder.BoneInfo boneInfo2 = (RagdollBuilder.BoneInfo)boneInfo.children[0];
                 Vector3 position = boneInfo2.anchor.position;
                 RagdollBuilder.CalculateDirection(boneInfo.anchor.InverseTransformPoint(position), out num, out num2);
             }
             else
             {
                 Vector3 position2 = boneInfo.anchor.position - boneInfo.parent.anchor.position + boneInfo.anchor.position;
                 RagdollBuilder.CalculateDirection(boneInfo.anchor.InverseTransformPoint(position2), out num, out num2);
                 if (boneInfo.anchor.GetComponentsInChildren(typeof(Transform)).Length > 1)
                 {
                     Bounds      bounds = default(Bounds);
                     Component[] componentsInChildren = boneInfo.anchor.GetComponentsInChildren(typeof(Transform));
                     for (int i = 0; i < componentsInChildren.Length; i++)
                     {
                         Transform transform = (Transform)componentsInChildren[i];
                         bounds.Encapsulate(boneInfo.anchor.InverseTransformPoint(transform.position));
                     }
                     if (num2 > 0f)
                     {
                         num2 = bounds.max[num];
                     }
                     else
                     {
                         num2 = bounds.min[num];
                     }
                 }
             }
             CapsuleCollider capsuleCollider = boneInfo.anchor.gameObject.AddComponent <CapsuleCollider>();
             capsuleCollider.direction = num;
             Vector3 zero = Vector3.zero;
             zero[num] = num2 * 0.5f;
             capsuleCollider.center = zero;
             capsuleCollider.height = Mathf.Abs(num2);
             capsuleCollider.radius = Mathf.Abs(num2 * boneInfo.radiusScale);
         }
     }
 }
        private static int SecondLargestComponent(Vector3 point)
        {
            int num1 = RagdollBuilder.SmallestComponent(point);
            int num2 = RagdollBuilder.LargestComponent(point);

            if (num1 < num2)
            {
                int num3 = num2;
                num2 = num1;
                num1 = num3;
            }
            if (num1 == 0 && num2 == 1)
            {
                return(2);
            }
            return(num1 == 0 && num2 == 2 ? 1 : 0);
        }
Beispiel #10
0
        private Bounds Clip(Bounds bounds, Transform relativeTo, Transform clipTransform, bool below)
        {
            int index = RagdollBuilder.LargestComponent(bounds.size);

            if (Vector3.Dot(this.worldUp, relativeTo.TransformPoint(bounds.max)) > Vector3.Dot(this.worldUp, relativeTo.TransformPoint(bounds.min)) == below)
            {
                Vector3 min = bounds.min;
                min[index] = relativeTo.InverseTransformPoint(clipTransform.position)[index];
                bounds.min = min;
            }
            else
            {
                Vector3 max = bounds.max;
                max[index] = relativeTo.InverseTransformPoint(clipTransform.position)[index];
                bounds.max = max;
            }
            return(bounds);
        }
Beispiel #11
0
        private static Vector3 CalculateDirectionAxis(Vector3 point)
        {
            int   index = 0;
            float num;

            RagdollBuilder.CalculateDirection(point, out index, out num);
            Vector3 zero = Vector3.zero;

            if (num > 0f)
            {
                zero[index] = 1f;
            }
            else
            {
                zero[index] = -1f;
            }
            return(zero);
        }
        private void AddHeadCollider()
        {
            if ((bool)((UnityEngine.Object) this.head.GetComponent <Collider>()))
            {
                UnityEngine.Object.Destroy((UnityEngine.Object) this.head.GetComponent <Collider>());
            }
            float          num            = Vector3.Distance(this.leftArm.transform.position, this.rightArm.transform.position) / 4f;
            SphereCollider sphereCollider = this.head.gameObject.AddComponent <SphereCollider>();

            sphereCollider.radius = num;
            Vector3 zero = Vector3.zero;
            int     direction;
            float   distance;

            RagdollBuilder.CalculateDirection(this.head.InverseTransformPoint(this.pelvis.position), out direction, out distance);
            zero[direction]       = (double)distance <= 0.0 ? num : -num;
            sphereCollider.center = zero;
        }
Beispiel #13
0
 private void CalculateAxes()
 {
     if (this.head != null && this.pelvis != null)
     {
         this.up = RagdollBuilder.CalculateDirectionAxis(this.pelvis.InverseTransformPoint(this.head.position));
     }
     if (this.rightElbow != null && this.pelvis != null)
     {
         Vector3 vector;
         Vector3 point;
         this.DecomposeVector(out vector, out point, this.pelvis.InverseTransformPoint(this.rightElbow.position), this.up);
         this.right = RagdollBuilder.CalculateDirectionAxis(point);
     }
     this.forward = Vector3.Cross(this.right, this.up);
     if (this.flipForward)
     {
         this.forward = -this.forward;
     }
 }
 private void CalculateAxes()
 {
     if ((UnityEngine.Object) this.head != (UnityEngine.Object)null && (UnityEngine.Object) this.pelvis != (UnityEngine.Object)null)
     {
         this.up = RagdollBuilder.CalculateDirectionAxis(this.pelvis.InverseTransformPoint(this.head.position));
     }
     if ((UnityEngine.Object) this.rightElbow != (UnityEngine.Object)null && (UnityEngine.Object) this.pelvis != (UnityEngine.Object)null)
     {
         Vector3 normalCompo;
         Vector3 tangentCompo;
         this.DecomposeVector(out normalCompo, out tangentCompo, this.pelvis.InverseTransformPoint(this.rightElbow.position), this.up);
         this.right = RagdollBuilder.CalculateDirectionAxis(tangentCompo);
     }
     this.forward = Vector3.Cross(this.right, this.up);
     if (!this.flipForward)
     {
         return;
     }
     this.forward = -this.forward;
 }
        private void BuildJoints()
        {
            IEnumerator enumerator = this.bones.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    RagdollBuilder.BoneInfo boneInfo = (RagdollBuilder.BoneInfo)enumerator.Current;
                    if (boneInfo.parent != null)
                    {
                        CharacterJoint characterJoint = boneInfo.anchor.gameObject.AddComponent <CharacterJoint>();
                        boneInfo.joint                     = characterJoint;
                        characterJoint.axis                = RagdollBuilder.CalculateDirectionAxis(boneInfo.anchor.InverseTransformDirection(boneInfo.axis));
                        characterJoint.swingAxis           = RagdollBuilder.CalculateDirectionAxis(boneInfo.anchor.InverseTransformDirection(boneInfo.normalAxis));
                        characterJoint.anchor              = Vector3.zero;
                        characterJoint.connectedBody       = boneInfo.parent.anchor.GetComponent <Rigidbody>();
                        characterJoint.enablePreprocessing = false;
                        SoftJointLimit softJointLimit = default(SoftJointLimit);
                        softJointLimit.contactDistance = 0f;
                        softJointLimit.limit           = boneInfo.minLimit;
                        characterJoint.lowTwistLimit   = softJointLimit;
                        softJointLimit.limit           = boneInfo.maxLimit;
                        characterJoint.highTwistLimit  = softJointLimit;
                        softJointLimit.limit           = boneInfo.swingLimit;
                        characterJoint.swing1Limit     = softJointLimit;
                        softJointLimit.limit           = 0f;
                        characterJoint.swing2Limit     = softJointLimit;
                    }
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
        }
 private void BuildCapsules()
 {
     foreach (RagdollBuilder.BoneInfo bone in this.bones)
     {
         if (bone.colliderType == typeof(CapsuleCollider))
         {
             int   direction;
             float distance;
             if (bone.children.Count == 1)
             {
                 Vector3 position = ((RagdollBuilder.BoneInfo)bone.children[0]).anchor.position;
                 RagdollBuilder.CalculateDirection(bone.anchor.InverseTransformPoint(position), out direction, out distance);
             }
             else
             {
                 Vector3 position = bone.anchor.position - bone.parent.anchor.position + bone.anchor.position;
                 RagdollBuilder.CalculateDirection(bone.anchor.InverseTransformPoint(position), out direction, out distance);
                 if (bone.anchor.GetComponentsInChildren(typeof(Transform)).Length > 1)
                 {
                     Bounds bounds = new Bounds();
                     foreach (Transform componentsInChild in bone.anchor.GetComponentsInChildren(typeof(Transform)))
                     {
                         bounds.Encapsulate(bone.anchor.InverseTransformPoint(componentsInChild.position));
                     }
                     distance = (double)distance <= 0.0 ? bounds.min[direction] : bounds.max[direction];
                 }
             }
             CapsuleCollider capsuleCollider = bone.anchor.gameObject.AddComponent <CapsuleCollider>();
             capsuleCollider.direction = direction;
             Vector3 zero = Vector3.zero;
             zero[direction]        = distance * 0.5f;
             capsuleCollider.center = zero;
             capsuleCollider.height = Mathf.Abs(distance);
             capsuleCollider.radius = Mathf.Abs(distance * bone.radiusScale);
         }
     }
 }
		private void CalculateMassRecurse(RagdollBuilder.BoneInfo bone)
		{
			float num = bone.anchor.GetComponent<Rigidbody>().mass;
			foreach (RagdollBuilder.BoneInfo boneInfo in bone.children)
			{
				this.CalculateMassRecurse(boneInfo);
				num += boneInfo.summedMass;
			}
			bone.summedMass = num;
		}
 private void CalculateMassRecurse(RagdollBuilder.BoneInfo bone)
 {
   float mass = bone.anchor.GetComponent<Rigidbody>().mass;
   foreach (RagdollBuilder.BoneInfo child in bone.children)
   {
     this.CalculateMassRecurse(child);
     mass += child.summedMass;
   }
   bone.summedMass = mass;
 }