IBone.cs
958 Bytes
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
using System.Collections.Generic;
using UnityEngine;
namespace UniHumanoid
{
public interface IBone
{
string Name { get; }
Vector3 SkeletonLocalPosition { get; }
IBone Parent { get; }
IList<IBone> Children { get; }
}
public static class IBoneExtensions
{
public static IEnumerable<IBone> Traverse(this IBone self)
{
yield return self;
foreach (var child in self.Children)
{
foreach (var x in child.Traverse())
{
yield return x;
}
}
}
public static Vector3 CenterOfDescendant(this IBone self)
{
var sum = Vector3.zero;
int i = 0;
foreach (var x in self.Traverse())
{
sum += x.SkeletonLocalPosition;
++i;
}
return sum / i;
}
}
}