UnityExtensions.cs
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections.Generic;
using UnityEngine;
namespace UniHumanoid
{
public static class UnityExtensions
{
public static Quaternion ReverseX(this Quaternion quaternion)
{
float angle;
Vector3 axis;
quaternion.ToAngleAxis(out angle, out axis);
return Quaternion.AngleAxis(-angle, new Vector3(-axis.x, axis.y, axis.z));
}
public static IEnumerable<Transform> GetChildren(this Transform parent)
{
foreach (Transform child in parent)
{
yield return child;
}
}
public static IEnumerable<Transform> Traverse(this Transform parent)
{
yield return parent;
foreach (Transform child in parent)
{
foreach (Transform descendant in Traverse(child))
{
yield return descendant;
}
}
}
public static SkeletonBone ToSkeletonBone(this Transform t)
{
var sb = new SkeletonBone();
sb.name = t.name;
sb.position = t.localPosition;
sb.rotation = t.localRotation;
sb.scale = t.localScale;
return sb;
}
}
}