-
Notifications
You must be signed in to change notification settings - Fork 9
/
SpringBoneAssistant.cs
60 lines (45 loc) · 1.67 KB
/
SpringBoneAssistant.cs
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
50
51
52
53
54
55
56
57
58
59
60
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpringBoneAssistant : MonoBehaviour
{
public UnityChan.SpringManager mSpringManager;
public Vector3 mTargetBoneAxis = new Vector3(0f, 1f, 0f);
public void MarkChildren()
{
//List<SpringBoneMarker> boneMarkers = new List<SpringBoneMarker>();
// get spring bones set
SpringBoneMarker[] boneMarkers = FindObjectsOfType<SpringBoneMarker>();
// mark children
for (int i = 0; i < boneMarkers.Length; i++)
{
boneMarkers[i].MarkChildren();
}
// get again, will include children
boneMarkers = FindObjectsOfType<SpringBoneMarker>();
List<UnityChan.SpringBone> springBones = new List<UnityChan.SpringBone> { };
for (int i = 0; i < boneMarkers.Length; i++)
{
// add spring bone
springBones.Add(boneMarkers[i].AddSpringBone());
// set vector
springBones[i].boneAxis = mTargetBoneAxis;
// unmark object
boneMarkers[i].UnmarkSelf();
}
mSpringManager.springBones = springBones.ToArray();
}
public void CleanUp()
{
SpringBoneMarker[] boneMarkers = FindObjectsOfType<SpringBoneMarker>();
UnityChan.SpringBone[] springBones = FindObjectsOfType<UnityChan.SpringBone>();
for (int i = 0; i < boneMarkers.Length; i++)
{
DestroyImmediate(boneMarkers[i]);
}
for (int i = 0; i < springBones.Length; i++)
{
DestroyImmediate(springBones[i]);
}
}
}