-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBController.cs
148 lines (139 loc) · 5.38 KB
/
DBController.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class DBController : MonoBehaviour
{
public Transform[] Bones;
public float UpdateRate;
public UpdateMode m_UpdateMode = UpdateMode.Default;
public enum UpdateMode
{
Normal,
AnimatePhysics,
UnscaledTime,
Default
}
[Range(0f, 1f)] public float Damping;
public AnimationCurve DanpingDistrib;
[Range(0f, 1f)] public float Elasticity;
public AnimationCurve ElasticityDistrib;
[Range(0f, 1f)] public float Stiffness;
public AnimationCurve StiffnessDistrib;
[Range(0f, 1f)] public float Inert;
public AnimationCurve InertDistrib;
[Range(0f, 1f)] public float Friction;
public AnimationCurve FrictionDistrib;
public float Radius;
public AnimationCurve RadiusDistrib;
public float EndLength;
public Vector3 EndOffset, Gravity, Force;
public bool UseColliderSettings;
public List<DynamicBoneColliderBase> Colliders;
public List<Transform> Exclusions;
public enum FreezeAxis
{
None, X, Y, Z
}
public FreezeAxis m_FreezeAxis = FreezeAxis.None;
public bool DistantDisable = true;
public Transform ReferenceObject;
public float DistanceToObject = 20;
// Use this for initialization
void Reset()
{
var db = GetComponent<DynamicBone>();
if (!db) return;
UpdateRate = db.m_UpdateRate;
Damping = db.m_Damping;
Elasticity = db.m_Elasticity;
Stiffness = db.m_Stiffness;
Inert = db.m_Inert;
Radius = db.m_Radius;
Friction = db.m_Friction;
DanpingDistrib = db.m_DampingDistrib;
ElasticityDistrib = db.m_ElasticityDistrib;
StiffnessDistrib = db.m_StiffnessDistrib;
InertDistrib = db.m_InertDistrib;
RadiusDistrib = db.m_RadiusDistrib;
FrictionDistrib = db.m_FrictionDistrib;
DistantDisable = db.m_DistantDisable;
DistanceToObject = db.m_DistanceToObject;
Exclusions = db.m_Exclusions;
ReferenceObject = db.m_ReferenceObject;
EndOffset = db.m_EndOffset;
Gravity = db.m_Gravity;
Force = db.m_Force;
EndLength = db.m_EndLength;
if (UseColliderSettings) Colliders = db.m_Colliders;
}
void OnValidate() {
var dbs = GetComponents<DynamicBone>();
// アタッチされていないボーンがあれば追加
var attachedBones = dbs.Select(db => db.m_Root);
var unAttachedBones = Bones.Except(attachedBones).ToArray();
foreach (var bone in unAttachedBones)
{
if (bone == null) break;
var db = gameObject.AddComponent<DynamicBone>();
db.m_Root = bone;
}
// 追加した場合コンポーネントをリロード
if (unAttachedBones.Length > 0)
{
dbs = GetComponents<DynamicBone>();
}
foreach (var dynamicBone in dbs)
{
dynamicBone.m_UpdateRate = UpdateRate;
dynamicBone.m_Damping = Damping;
dynamicBone.m_Elasticity = Elasticity;
dynamicBone.m_Stiffness = Stiffness;
dynamicBone.m_Inert = Inert;
dynamicBone.m_Radius = Radius;
dynamicBone.m_Friction = Friction;
dynamicBone.m_DampingDistrib = DanpingDistrib;
dynamicBone.m_ElasticityDistrib = ElasticityDistrib;
dynamicBone.m_StiffnessDistrib = StiffnessDistrib;
dynamicBone.m_InertDistrib = InertDistrib;
dynamicBone.m_RadiusDistrib = RadiusDistrib;
dynamicBone.m_FrictionDistrib = FrictionDistrib;
dynamicBone.m_DistantDisable = DistantDisable;
dynamicBone.m_DistanceToObject = DistanceToObject;
dynamicBone.m_Exclusions = Exclusions;
dynamicBone.m_ReferenceObject = ReferenceObject;
dynamicBone.m_EndOffset = EndOffset;
dynamicBone.m_Gravity = Gravity;
dynamicBone.m_Force = Force;
dynamicBone.m_EndLength = EndLength;
if (UseColliderSettings) dynamicBone.m_Colliders = Colliders;
switch(m_FreezeAxis){
case FreezeAxis.X:
dynamicBone.m_FreezeAxis = DynamicBone.FreezeAxis.X;
break;
case FreezeAxis.Y:
dynamicBone.m_FreezeAxis = DynamicBone.FreezeAxis.Y;
break;
case FreezeAxis.Z:
dynamicBone.m_FreezeAxis = DynamicBone.FreezeAxis.Z;
break;
case FreezeAxis.None:
dynamicBone.m_FreezeAxis = DynamicBone.FreezeAxis.None;
break;
}
switch(m_UpdateMode){
case UpdateMode.Normal:
dynamicBone.m_UpdateMode = DynamicBone.UpdateMode.Normal;
break;
case UpdateMode.AnimatePhysics:
dynamicBone.m_UpdateMode = DynamicBone.UpdateMode.AnimatePhysics;
break;
case UpdateMode.UnscaledTime:
dynamicBone.m_UpdateMode = DynamicBone.UpdateMode.UnscaledTime;
break;
case UpdateMode.Default:
dynamicBone.m_UpdateMode = DynamicBone.UpdateMode.Default;
break;
}
}
}
}