private static Transform SearchRec(Transform tr, string name) { int childCount = tr.childCount; for (int i = 0; i < childCount; i++) { Transform child = tr.GetChild(i); if (child.name == name) { return child; } Transform transform = AnimationLink.SearchRec(child, name); if (transform != null) { return transform; } } return null; }
public void CalculateOffsets(List <Vector3> trace, out Vector3 endPosition) { endPosition = base.transform.position; if (this.referenceMesh == null) { return; } GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.referenceMesh, base.transform.position, base.transform.rotation); gameObject.hideFlags = HideFlags.HideAndDontSave; Transform transform = AnimationLink.SearchRec(gameObject.transform, this.boneRoot); if (transform == null) { throw new Exception("Could not find root transform"); } Animation animation = gameObject.GetComponent <Animation>(); if (animation == null) { animation = gameObject.AddComponent <Animation>(); } for (int i = 0; i < this.sequence.Length; i++) { animation.AddClip(this.sequence[i].clip, this.sequence[i].clip.name); } Vector3 a = Vector3.zero; Vector3 vector = base.transform.position; Vector3 b = Vector3.zero; for (int j = 0; j < this.sequence.Length; j++) { AnimationLink.LinkClip linkClip = this.sequence[j]; if (linkClip == null) { endPosition = vector; return; } animation[linkClip.clip.name].enabled = true; animation[linkClip.clip.name].weight = 1f; for (int k = 0; k < linkClip.loopCount; k++) { animation[linkClip.clip.name].normalizedTime = 0f; animation.Sample(); Vector3 vector2 = transform.position - base.transform.position; if (j > 0) { vector += a - vector2; } else { b = vector2; } for (int l = 0; l <= 20; l++) { float num = (float)l / 20f; animation[linkClip.clip.name].normalizedTime = num; animation.Sample(); Vector3 item = vector + (transform.position - base.transform.position) + linkClip.velocity * num * linkClip.clip.length; trace.Add(item); } vector += linkClip.velocity * 1f * linkClip.clip.length; animation[linkClip.clip.name].normalizedTime = 1f; animation.Sample(); Vector3 vector3 = transform.position - base.transform.position; a = vector3; } animation[linkClip.clip.name].enabled = false; animation[linkClip.clip.name].weight = 0f; } vector += a - b; UnityEngine.Object.DestroyImmediate(gameObject); endPosition = vector; }