private string CheckConsistency() { this.PrepareBones(); Hashtable hashtable = new Hashtable(); foreach (RagdollBuilder.BoneInfo boneInfo in this.bones) { if (boneInfo.anchor) { if (hashtable[boneInfo.anchor] != null) { RagdollBuilder.BoneInfo boneInfo2 = (RagdollBuilder.BoneInfo)hashtable[boneInfo.anchor]; string result = string.Format("{0} and {1} may not be assigned to the same bone.", boneInfo.name, boneInfo2.name); return(result); } hashtable[boneInfo.anchor] = boneInfo; } } foreach (RagdollBuilder.BoneInfo boneInfo3 in this.bones) { if (boneInfo3.anchor == null) { string result = string.Format("{0} has not been assigned yet.\n", boneInfo3.name); return(result); } } return(string.Empty); }
private RagdollBuilder.BoneInfo FindBone(string name) { IEnumerator enumerator = this.bones.GetEnumerator(); RagdollBuilder.BoneInfo result; try { while (enumerator.MoveNext()) { RagdollBuilder.BoneInfo boneInfo = (RagdollBuilder.BoneInfo)enumerator.Current; if (boneInfo.name == name) { result = boneInfo; return(result); } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } result = null; return(result); }
private void AddJoint(string name, Transform anchor, string parent, Vector3 worldTwistAxis, Vector3 worldSwingAxis, float minLimit, float maxLimit, float swingLimit, Type colliderType, float radiusScale, float density) { RagdollBuilder.BoneInfo boneInfo = new RagdollBuilder.BoneInfo(); boneInfo.name = name; boneInfo.anchor = anchor; boneInfo.axis = worldTwistAxis; boneInfo.normalAxis = worldSwingAxis; boneInfo.minLimit = minLimit; boneInfo.maxLimit = maxLimit; boneInfo.swingLimit = swingLimit; boneInfo.density = density; boneInfo.colliderType = colliderType; boneInfo.radiusScale = radiusScale; if (this.FindBone(parent) != null) { boneInfo.parent = this.FindBone(parent); } else { if (name.StartsWith("Left")) { boneInfo.parent = this.FindBone("Left " + parent); } else { if (name.StartsWith("Right")) { boneInfo.parent = this.FindBone("Right " + parent); } } } boneInfo.parent.children.Add(boneInfo); this.bones.Add(boneInfo); }
private string CheckConsistency() { this.PrepareBones(); Hashtable hashtable = new Hashtable(); foreach (RagdollBuilder.BoneInfo bone in this.bones) { if ((bool)((UnityEngine.Object)bone.anchor)) { if (hashtable[(object)bone.anchor] != null) { RagdollBuilder.BoneInfo boneInfo = (RagdollBuilder.BoneInfo)hashtable[(object)bone.anchor]; return(string.Format("{0} and {1} may not be assigned to the same bone.", (object)bone.name, (object)boneInfo.name)); } hashtable[(object)bone.anchor] = (object)bone; } } foreach (RagdollBuilder.BoneInfo bone in this.bones) { if ((UnityEngine.Object)bone.anchor == (UnityEngine.Object)null) { return(string.Format("{0} has not been assigned yet.\n", (object)bone.name)); } } return(string.Empty); }
private string CheckConsistency() { this.PrepareBones(); Hashtable hashtable = new Hashtable(); IEnumerator enumerator = this.bones.GetEnumerator(); string result; try { while (enumerator.MoveNext()) { RagdollBuilder.BoneInfo boneInfo = (RagdollBuilder.BoneInfo)enumerator.Current; if (boneInfo.anchor) { if (hashtable[boneInfo.anchor] != null) { RagdollBuilder.BoneInfo boneInfo2 = (RagdollBuilder.BoneInfo)hashtable[boneInfo.anchor]; result = string.Format("{0} and {1} may not be assigned to the same bone.", boneInfo.name, boneInfo2.name); return(result); } hashtable[boneInfo.anchor] = boneInfo; } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } IEnumerator enumerator2 = this.bones.GetEnumerator(); try { while (enumerator2.MoveNext()) { RagdollBuilder.BoneInfo boneInfo3 = (RagdollBuilder.BoneInfo)enumerator2.Current; if (boneInfo3.anchor == null) { result = string.Format("{0} has not been assigned yet.\n", boneInfo3.name); return(result); } } } finally { IDisposable disposable2; if ((disposable2 = (enumerator2 as IDisposable)) != null) { disposable2.Dispose(); } } result = ""; return(result); }
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; }
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 void Cleanup() { IEnumerator enumerator = this.bones.GetEnumerator(); try { while (enumerator.MoveNext()) { RagdollBuilder.BoneInfo boneInfo = (RagdollBuilder.BoneInfo)enumerator.Current; if (boneInfo.anchor) { Component[] componentsInChildren = boneInfo.anchor.GetComponentsInChildren(typeof(Joint)); Component[] array = componentsInChildren; for (int i = 0; i < array.Length; i++) { Joint obj = (Joint)array[i]; UnityEngine.Object.DestroyImmediate(obj); } Component[] componentsInChildren2 = boneInfo.anchor.GetComponentsInChildren(typeof(Rigidbody)); Component[] array2 = componentsInChildren2; for (int j = 0; j < array2.Length; j++) { Rigidbody obj2 = (Rigidbody)array2[j]; UnityEngine.Object.DestroyImmediate(obj2); } Component[] componentsInChildren3 = boneInfo.anchor.GetComponentsInChildren(typeof(Collider)); Component[] array3 = componentsInChildren3; for (int k = 0; k < array3.Length; k++) { Collider obj3 = (Collider)array3[k]; UnityEngine.Object.DestroyImmediate(obj3); } } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } }
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 PrepareBones() { if (this.pelvis) { this.worldRight = this.pelvis.TransformDirection(this.right); this.worldUp = this.pelvis.TransformDirection(this.up); this.worldForward = this.pelvis.TransformDirection(this.forward); } this.bones = new ArrayList(); this.rootBone = new RagdollBuilder.BoneInfo(); this.rootBone.name = "Pelvis"; this.rootBone.anchor = this.pelvis; this.rootBone.parent = null; this.rootBone.density = 2.5f; this.bones.Add(this.rootBone); this.AddMirroredJoint("Hips", this.leftHips, this.rightHips, "Pelvis", this.worldRight, this.worldForward, -20f, 70f, 30f, typeof(CapsuleCollider), 0.3f, 1.5f); this.AddMirroredJoint("Knee", this.leftKnee, this.rightKnee, "Hips", this.worldRight, this.worldForward, -80f, 0f, 0f, typeof(CapsuleCollider), 0.25f, 1.5f); this.AddJoint("Middle Spine", this.middleSpine, "Pelvis", this.worldRight, this.worldForward, -20f, 20f, 10f, null, 1f, 2.5f); this.AddMirroredJoint("Arm", this.leftArm, this.rightArm, "Middle Spine", this.worldUp, this.worldForward, -70f, 10f, 50f, typeof(CapsuleCollider), 0.25f, 1f); this.AddMirroredJoint("Elbow", this.leftElbow, this.rightElbow, "Arm", this.worldForward, this.worldUp, -90f, 0f, 0f, typeof(CapsuleCollider), 0.2f, 1f); this.AddJoint("Head", this.head, "Middle Spine", this.worldRight, this.worldForward, -40f, 25f, 25f, null, 1f, 1f); }
private void BuildBodies() { IEnumerator enumerator = this.bones.GetEnumerator(); try { while (enumerator.MoveNext()) { RagdollBuilder.BoneInfo boneInfo = (RagdollBuilder.BoneInfo)enumerator.Current; boneInfo.anchor.gameObject.AddComponent <Rigidbody>(); boneInfo.anchor.GetComponent <Rigidbody>().mass = boneInfo.density; } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } }
private void CalculateMass() { this.CalculateMassRecurse(this.rootBone); float num = this.totalMass / this.rootBone.summedMass; IEnumerator enumerator = this.bones.GetEnumerator(); try { while (enumerator.MoveNext()) { RagdollBuilder.BoneInfo boneInfo = (RagdollBuilder.BoneInfo)enumerator.Current; boneInfo.anchor.GetComponent <Rigidbody>().mass *= num; } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } this.CalculateMassRecurse(this.rootBone); }
private void CalculateMassRecurse(RagdollBuilder.BoneInfo bone) { float num = bone.anchor.GetComponent <Rigidbody>().mass; IEnumerator enumerator = bone.children.GetEnumerator(); try { while (enumerator.MoveNext()) { RagdollBuilder.BoneInfo boneInfo = (RagdollBuilder.BoneInfo)enumerator.Current; this.CalculateMassRecurse(boneInfo); num += boneInfo.summedMass; } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } bone.summedMass = num; }