// Use this for initialization void Start() { // m_Bone = m_SkeletonAnim.skeleton.FindBone("board"); m_SkeletonAnim = GetComponent <SkeletonAnimation>(); ragdoll = GetComponent <Spine.Unity.Modules.SkeletonRagdoll2D>(); m_RigidBody = GetComponent <Rigidbody2D>(); m_cameraShake = Camera.main.GetComponent <CameraShake>(); targetRotation = transform.rotation; for (int i = 0; i < bloodEffects.Length; ++i) { bloodEffects[i].gameObject.SetActive(false); bloodEffects[i].GetComponent <SwfClipController>().Stop(true); } }
private void RecursivelyCreateBoneProxies(Bone b) { string name = b.data.name; if (this.stopBoneNames.Contains(name)) { return; } GameObject gameObject = new GameObject(name); gameObject.layer = this.colliderLayer; Transform transform = gameObject.transform; this.boneTable.Add(b, transform); transform.parent = base.transform; transform.localPosition = new Vector3(b.WorldX, b.WorldY, 0f); transform.localRotation = Quaternion.Euler(0f, 0f, b.WorldRotationX - b.shearX); transform.localScale = new Vector3(b.WorldScaleX, b.WorldScaleY, 0f); List <Collider2D> list = SkeletonRagdoll2D.AttachBoundingBoxRagdollColliders(b, gameObject, this.skeleton); if (list.Count == 0) { float length = b.data.length; if (length == 0f) { CircleCollider2D circleCollider2D = gameObject.AddComponent <CircleCollider2D>(); circleCollider2D.radius = this.thickness * 0.5f; } else { BoxCollider2D boxCollider2D = gameObject.AddComponent <BoxCollider2D>(); boxCollider2D.size = new Vector2(length, this.thickness); boxCollider2D.offset = new Vector2(length * 0.5f, 0f); } } Rigidbody2D rigidbody2D = gameObject.AddComponent <Rigidbody2D>(); rigidbody2D.gravityScale = this.gravityScale; foreach (Bone b2 in b.Children) { this.RecursivelyCreateBoneProxies(b2); } }
void Start() { ragdoll = GetComponent <Spine.Unity.Modules.SkeletonRagdoll2D>(); naturalCollider = GetComponent <Collider2D>(); }
public void Apply() { this.isActive = true; this.mix = 1f; Bone bone = this.skeleton.FindBone(this.startingBoneName); this.StartingBone = bone; Bone bone2 = bone; this.RecursivelyCreateBoneProxies(bone2); this.RootRigidbody = this.boneTable[bone2].GetComponent <Rigidbody2D>(); this.RootRigidbody.isKinematic = this.pinStartBone; this.RootRigidbody.mass = this.rootMass; List <Collider2D> list = new List <Collider2D>(); foreach (KeyValuePair <Bone, Transform> keyValuePair in this.boneTable) { Bone key = keyValuePair.Key; Transform value = keyValuePair.Value; list.Add(value.GetComponent <Collider2D>()); Transform transform; if (key == bone2) { this.ragdollRoot = new GameObject("RagdollRoot").transform; this.ragdollRoot.SetParent(base.transform, false); if (key == this.skeleton.RootBone) { this.ragdollRoot.localPosition = new Vector3(key.WorldX, key.WorldY, 0f); this.ragdollRoot.localRotation = Quaternion.Euler(0f, 0f, SkeletonRagdoll2D.GetPropagatedRotation(key)); } else { this.ragdollRoot.localPosition = new Vector3(key.Parent.WorldX, key.Parent.WorldY, 0f); this.ragdollRoot.localRotation = Quaternion.Euler(0f, 0f, SkeletonRagdoll2D.GetPropagatedRotation(key.Parent)); } transform = this.ragdollRoot; this.rootOffset = value.position - base.transform.position; } else { transform = this.boneTable[key.Parent]; } Rigidbody2D component = transform.GetComponent <Rigidbody2D>(); if (component != null) { HingeJoint2D hingeJoint2D = value.gameObject.AddComponent <HingeJoint2D>(); hingeJoint2D.connectedBody = component; Vector3 v = transform.InverseTransformPoint(value.position); hingeJoint2D.connectedAnchor = v; hingeJoint2D.GetComponent <Rigidbody2D>().mass = hingeJoint2D.connectedBody.mass * this.massFalloffFactor; hingeJoint2D.limits = new JointAngleLimits2D { min = -this.rotationLimit, max = this.rotationLimit }; hingeJoint2D.useLimits = true; } } for (int i = 0; i < list.Count; i++) { for (int j = 0; j < list.Count; j++) { if (i != j) { Physics2D.IgnoreCollision(list[i], list[j]); } } } SkeletonUtilityBone[] componentsInChildren = base.GetComponentsInChildren <SkeletonUtilityBone>(); if (componentsInChildren.Length > 0) { List <string> list2 = new List <string>(); foreach (SkeletonUtilityBone skeletonUtilityBone in componentsInChildren) { if (skeletonUtilityBone.mode == SkeletonUtilityBone.Mode.Override) { list2.Add(skeletonUtilityBone.gameObject.name); UnityEngine.Object.Destroy(skeletonUtilityBone.gameObject); } } if (list2.Count > 0) { string str = "Destroyed Utility Bones: "; for (int l = 0; l < list2.Count; l++) { str += list2[l]; if (l != list2.Count - 1) { str += ","; } } } } if (this.disableIK) { ExposedList <IkConstraint> ikConstraints = this.skeleton.IkConstraints; int m = 0; int count = ikConstraints.Count; while (m < count) { ikConstraints.Items[m].mix = 0f; m++; } } if (this.disableOtherConstraints) { ExposedList <TransformConstraint> transformConstraints = this.skeleton.transformConstraints; int n = 0; int count2 = transformConstraints.Count; while (n < count2) { transformConstraints.Items[n].rotateMix = 0f; transformConstraints.Items[n].scaleMix = 0f; transformConstraints.Items[n].shearMix = 0f; transformConstraints.Items[n].translateMix = 0f; n++; } ExposedList <PathConstraint> pathConstraints = this.skeleton.pathConstraints; int num = 0; int count3 = pathConstraints.Count; while (num < count3) { pathConstraints.Items[num].rotateMix = 0f; pathConstraints.Items[num].translateMix = 0f; num++; } } this.targetSkeletonComponent.UpdateWorld += this.UpdateSpineSkeleton; }
void Start () { ragdoll = GetComponent<Spine.Unity.Modules.SkeletonRagdoll2D>(); naturalCollider = GetComponent<Collider2D>(); }