当前位置: 首页>>代码示例>>C#>>正文


C# Skeleton.FindBone方法代码示例

本文整理汇总了C#中Skeleton.FindBone方法的典型用法代码示例。如果您正苦于以下问题:C# Skeleton.FindBone方法的具体用法?C# Skeleton.FindBone怎么用?C# Skeleton.FindBone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Skeleton的用法示例。


在下文中一共展示了Skeleton.FindBone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Apply

		public void Apply () {
			isActive = true;
			skeleton = skeletonAnim.Skeleton;
			mix = 1;

			var ragdollRootBone = skeleton.FindBone(startingBoneName);
			startingBone = ragdollRootBone;
			RecursivelyCreateBoneProxies(ragdollRootBone);

			rootRigidbody = boneTable[ragdollRootBone].GetComponent<Rigidbody>();
			rootRigidbody.isKinematic = pinStartBone;

			rootRigidbody.mass = rootMass;

			List<Collider> boneColliders = new List<Collider>();

			foreach (var pair in boneTable) {
				var b = pair.Key;
				var t = pair.Value;
				Bone parentBone = null;
				Transform parentTransform = transform;

				boneColliders.Add(t.GetComponent<Collider>());

				if (b != startingBone) {
					parentBone = b.Parent;
					parentTransform = boneTable[parentBone];
				} else {
					ragdollRoot = new GameObject("RagdollRoot").transform;
					ragdollRoot.parent = transform;

					if (b == skeleton.RootBone) {
						ragdollRoot.localPosition = new Vector3(b.WorldX, b.WorldY, 0);
						ragdollRoot.localRotation = Quaternion.Euler(0, 0, GetCompensatedRotationIK(b));
						parentTransform = ragdollRoot;
					} else {
						ragdollRoot.localPosition = new Vector3(b.Parent.WorldX, b.Parent.WorldY, 0);
						ragdollRoot.localRotation = Quaternion.Euler(0, 0, GetCompensatedRotationIK(b.Parent));
						parentTransform = ragdollRoot;
					}

					rootOffset = t.position - transform.position;
				}

				var rbParent = parentTransform.GetComponent<Rigidbody>();

				if (rbParent != null) {
					var joint = t.gameObject.AddComponent<HingeJoint>();
					joint.connectedBody = rbParent;
					Vector3 localPos = parentTransform.InverseTransformPoint(t.position);
					localPos.x *= 1;
					joint.connectedAnchor = localPos;
					joint.axis = Vector3.forward;
					joint.GetComponent<Rigidbody>().mass = joint.connectedBody.mass * massFalloffFactor;
					JointLimits limits = new JointLimits();
					limits.min = -rotationLimit;
					limits.max = rotationLimit;
					joint.limits = limits;
					joint.useLimits = true;
					joint.enableCollision = enableJointCollision;
				}
			}

			for (int x = 0; x < boneColliders.Count; x++) {
				for (int y = 0; y < boneColliders.Count; y++) {
					if (x == y) continue;
					Physics.IgnoreCollision(boneColliders[x], boneColliders[y]);
				}
			}

			var utilityBones = GetComponentsInChildren<SkeletonUtilityBone>();
			if (utilityBones.Length > 0) {
				List<string> destroyedUtilityBoneNames = new List<string>();
				foreach (var ub in utilityBones) {
					if (ub.mode == SkeletonUtilityBone.Mode.Override) {
						destroyedUtilityBoneNames.Add(ub.gameObject.name);
						Destroy(ub.gameObject);
					}
				}

				if (destroyedUtilityBoneNames.Count > 0) {
					string msg = "Destroyed Utility Bones: ";
					for (int i = 0; i < destroyedUtilityBoneNames.Count; i++) {
						msg += destroyedUtilityBoneNames[i];
						if (i != destroyedUtilityBoneNames.Count - 1) {
							msg += ",";
						}
					}
					Debug.LogWarning(msg);
				}
			}

			if (disableIK) {
				foreach (IkConstraint ik in skeleton.IkConstraints) {
					ik.Mix = 0;
				}
			}

			skeletonAnim.UpdateWorld += UpdateWorld;
		}
开发者ID:SirFelolis,项目名称:Snot-Ninja,代码行数:100,代码来源:SkeletonRagdoll.cs


注:本文中的Skeleton.FindBone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。