Transform CopyTransformTree(Transform otherRoot, string newName = null, Action <Transform, Transform> copyMade = null) { string name = (newName != null) ? newName : otherRoot.name; Stack <TransformPair> stack = new Stack <TransformPair>(); Transform root = CopyTransform(otherRoot, name); stack.Push(new TransformPair(otherRoot, root)); while (stack.Count > 0) { TransformPair parentPair = stack.Pop(); for (int i = 0; i < parentPair.orig.childCount; i++) { Transform child = parentPair.orig.GetChild(i); Transform childCopy = CopyTransform(child); childCopy.SetParent(parentPair.copy); // notify callback about the copy if (copyMade != null) { copyMade(child, childCopy); } stack.Push(new TransformPair(child, childCopy)); } } return(root); }
private void FixedUpdate() { if (this.physicsSystem == PhysicsSystem.Physics2D) { Rigidbody2D component = this.shadowRoot.GetComponent <Rigidbody2D>(); component.MovePosition(base.transform.position); component.MoveRotation(base.transform.rotation.eulerAngles.z); } else { Rigidbody component = this.shadowRoot.GetComponent <Rigidbody>(); component.MovePosition(base.transform.position); component.MoveRotation(base.transform.rotation); } int num = 0; int count = this.shadowTable.Count; while (num < count) { TransformPair pair = this.shadowTable[num]; pair.dest.localPosition = pair.src.localPosition; pair.dest.localRotation = pair.src.localRotation; num++; } }
public static TransformPair <F, T> [] GetFrom(params object [] objects) { TransformPair <F, T> [] pairs = new TransformPair <F, T> [objects.Length / 2]; for (int i = 0; i < objects.Length; i += 2) { pairs[i / 2] = new TransformPair <F, T> ((F)objects[i], (T)objects[i + 1]); } return(pairs); }
private void Start() { this.shadowRoot = UnityEngine.Object.Instantiate <GameObject>(base.gameObject); UnityEngine.Object.Destroy(this.shadowRoot.GetComponent <SkeletonUtilityKinematicShadow>()); Transform transform = this.shadowRoot.transform; transform.position = base.transform.position; transform.rotation = base.transform.rotation; Vector3 b = base.transform.TransformPoint(Vector3.right); float num = Vector3.Distance(base.transform.position, b); transform.localScale = Vector3.one; if (!this.detachedShadow) { if (this.parent == null) { transform.parent = base.transform.root; } else { transform.parent = this.parent; } } if (this.hideShadow) { this.shadowRoot.hideFlags = HideFlags.HideInHierarchy; } foreach (Joint joint in this.shadowRoot.GetComponentsInChildren <Joint>()) { joint.connectedAnchor *= num; } SkeletonUtilityBone[] componentsInChildren = base.GetComponentsInChildren <SkeletonUtilityBone>(); SkeletonUtilityBone[] components = this.shadowRoot.GetComponentsInChildren <SkeletonUtilityBone>(); foreach (SkeletonUtilityBone bone in componentsInChildren) { if (bone.gameObject != base.gameObject) { Type type = (this.physicsSystem != PhysicsSystem.Physics2D) ? typeof(Rigidbody) : typeof(Rigidbody2D); foreach (SkeletonUtilityBone bone2 in components) { if ((bone2.GetComponent(type) != null) && (bone2.boneName == bone.boneName)) { TransformPair item = new TransformPair { dest = bone.transform, src = bone2.transform }; this.shadowTable.Add(item); break; } } } } DestroyComponents(components); DestroyComponents(base.GetComponentsInChildren <Joint>()); DestroyComponents(base.GetComponentsInChildren <Rigidbody>()); DestroyComponents(base.GetComponentsInChildren <Collider>()); }
private void FixedUpdate() { Rigidbody component = shadowRoot.GetComponent <Rigidbody>(); component.MovePosition(base.transform.position); component.MoveRotation(base.transform.rotation); int i = 0; for (int count = shadowTable.Count; i < count; i++) { TransformPair transformPair = shadowTable[i]; transformPair.dest.localPosition = transformPair.src.localPosition; transformPair.dest.localRotation = transformPair.src.localRotation; } }
public void TestParseITunesDuration() { TransformPair <string, TimeSpan> [] pairs = TransformPair <string, TimeSpan> .GetFrom( null, TimeSpan.Zero, "", TimeSpan.Zero, "0", TimeSpan.Zero, "0:0", TimeSpan.Zero, "0:0:0", TimeSpan.Zero, "1:0:0", new TimeSpan (1, 0, 0), "363", new TimeSpan (0, 0, 363), "2:45", new TimeSpan (0, 2, 45), "1:02:22", new TimeSpan (1, 2, 22), "9:0:0", new TimeSpan (9, 0, 0) ); AssertForEach(pairs, delegate(TransformPair <string, TimeSpan> pair) { Assert.AreEqual(pair.To, RssParser.GetITunesDuration(pair.From)); }); }
public void TestParseDates() { // The local timezone for tests is America/Chicago (UTC -06:00) TransformPair <string, DateTime> [] pairs = TransformPair <string, DateTime> .GetFrom( "Fri, 22 Feb 2008 16:00:00 EST", DateTime.Parse("22/02/2008 15.00.00"), "Fri, 15 Feb 2008 4:10:00 EST", DateTime.Parse("15/02/2008 3.10.00"), "Tue, 08 Apr 2008 03:37:04 -0400", DateTime.Parse("08/04/2008 2.37.04"), "Tue, 26 Feb 2008 03:28:51 -0500", DateTime.Parse("26/02/2008 2.28.51"), "Sun, 11 May 2008 01:33:26 -0400", DateTime.Parse("11/05/2008 0.33.26"), "Fri, 16 May 2008 16:09:10 -0500", DateTime.Parse("16/05/2008 16.09.10"), "Fri, 14 Mar 2008 13:44:53 -0500", DateTime.Parse("14/03/2008 13.44.53"), "Fri, 07 December 2007 17:00:00 EST", DateTime.Parse("07/12/2007 16.00.00"), "Sat, 08 Mar 2008 12:00:00 EST", DateTime.Parse("08/03/2008 11.00.00"), "Sat, 17 May 2008 20:47:57 +0000", DateTime.Parse("17/05/2008 15.47.57"), "Sat, 17 May 2008 19:33:42 +0000", DateTime.Parse("17/05/2008 14.33.42") ); AssertForEach(pairs, delegate(TransformPair <string, DateTime> pair) { Assert.AreEqual(pair.To, Rfc822DateTime.Parse(pair.From)); }); }