@@ -28,13 +28,32 @@ public void CreateSmoothAnimationLayer()
28
28
29
29
// Looking for existing animation layer, and will delete it to replace with a new one. Will look into
30
30
// creating a more thorough solution to much more effectively overwrite the existing layer for a future update.
31
- animLayer = AnimUtil . CreateAnimLayerInController ( "_OSCmooth_Smoothing_Gen_" , _animatorController ) ;
31
+ if ( _writeDefaults )
32
+ {
33
+ AnimUtil . RemoveAnimLayerInController ( "_OSCmooth_Smoothing_Gen" , _animatorController ) ;
34
+ animLayer = AnimUtil . CreateAnimLayerInController ( "_OSCmooth_Smoothing_WD_Gen" , _animatorController ) ;
35
+ }
36
+ else
37
+ {
38
+ AnimUtil . RemoveAnimLayerInController ( "_OSCmooth_Smoothing_WD_Gen" , _animatorController ) ;
39
+ animLayer = AnimUtil . CreateAnimLayerInController ( "_OSCmooth_Smoothing_Gen" , _animatorController ) ;
40
+ }
32
41
33
42
// Creating a Direct BlendTree that will hold all of the smooth driver animations. This is to effectively create a 'sublayer'
34
43
// system within the Direct BlendTree to tidy up the animator base layers from bloating up visually.
35
44
AnimatorState [ ] state = new AnimatorState [ 2 ] ;
36
- state [ 0 ] = animLayer . stateMachine . AddState ( "OSCmooth_Local" , new Vector3 ( 30 , 170 , 0 ) ) ;
37
- state [ 1 ] = animLayer . stateMachine . AddState ( "OSCmooth_Net" , new Vector3 ( 30 , 170 + 60 , 0 ) ) ;
45
+
46
+ if ( _writeDefaults )
47
+ {
48
+ state [ 0 ] = animLayer . stateMachine . AddState ( "OSCmooth_Local_WD" , new Vector3 ( 30 , 170 , 0 ) ) ;
49
+ state [ 1 ] = animLayer . stateMachine . AddState ( "OSCmooth_Net_WD" , new Vector3 ( 30 , 170 + 60 , 0 ) ) ;
50
+ }
51
+ else
52
+ {
53
+ state [ 0 ] = animLayer . stateMachine . AddState ( "OSCmooth_Local" , new Vector3 ( 30 , 170 , 0 ) ) ;
54
+ state [ 1 ] = animLayer . stateMachine . AddState ( "OSCmooth_Net" , new Vector3 ( 30 , 170 + 60 , 0 ) ) ;
55
+ }
56
+
38
57
39
58
state [ 0 ] . writeDefaultValues = _writeDefaults ;
40
59
state [ 1 ] . writeDefaultValues = _writeDefaults ;
@@ -51,23 +70,33 @@ public void CreateSmoothAnimationLayer()
51
70
toLocalState . AddCondition ( AnimatorConditionMode . If , 0 , "IsLocal" ) ;
52
71
53
72
// Creating BlendTree objects to better customize them in the AC Editor
73
+ var nameLocalWD = "OSCm_Local" ;
74
+ var nameRemoteWD = "OSCm_Remote" ;
75
+
76
+ if ( _writeDefaults )
77
+ {
78
+ nameLocalWD = "OSCm_Local_WD" ;
79
+ nameRemoteWD = "OSCm_Remote_WD" ;
80
+ }
81
+
54
82
var basisLocalBlendTree = new BlendTree ( )
55
83
{
56
84
blendType = BlendTreeType . Direct ,
57
85
hideFlags = HideFlags . HideInHierarchy ,
58
- name = "OSCm_Local" ,
86
+ name = nameLocalWD ,
59
87
useAutomaticThresholds = false
60
-
88
+
61
89
} ;
62
90
63
91
var basisRemoteBlendTree = new BlendTree ( )
64
92
{
65
93
blendType = BlendTreeType . Direct ,
66
94
hideFlags = HideFlags . HideInHierarchy ,
67
- name = "OSCm_Remote" ,
95
+ name = nameRemoteWD ,
68
96
useAutomaticThresholds = false
69
97
} ;
70
98
99
+
71
100
// Stuffing the BlendTrees into their designated state. Also stuffing them so that they
72
101
// retain serialization.
73
102
state [ 0 ] . motion = basisLocalBlendTree ;
@@ -76,7 +105,16 @@ public void CreateSmoothAnimationLayer()
76
105
AssetDatabase . AddObjectToAsset ( basisRemoteBlendTree , AssetDatabase . GetAssetPath ( animLayer . stateMachine ) ) ;
77
106
78
107
// Creating a '1Set' parameter that holds a value of one at all times for the Direct BlendTree
79
- ParameterUtil . CheckAndCreateParameter ( "OSCm/BlendSet" , _animatorController , AnimatorControllerParameterType . Float , 1f / ( float ) _parameters . Count ) ;
108
+
109
+ if ( _writeDefaults )
110
+ {
111
+ ParameterUtil . CheckAndCreateParameter ( "OSCm/BlendSet" , _animatorController , AnimatorControllerParameterType . Float , 1f ) ;
112
+ }
113
+ else
114
+ {
115
+ ParameterUtil . CheckAndCreateParameter ( "OSCm/BlendSet" , _animatorController , AnimatorControllerParameterType . Float , 1f / ( float ) _parameters . Count ) ;
116
+ }
117
+
80
118
81
119
List < ChildMotion > localChildMotion = new List < ChildMotion > ( ) ;
82
120
List < ChildMotion > remoteChildMotion = new List < ChildMotion > ( ) ;
@@ -89,17 +127,25 @@ public void CreateSmoothAnimationLayer()
89
127
AnimUtil . RenameAllStateMachineInstancesOfBlendParameter ( _animatorController , p . paramName , "OSCm/Proxy/" + p . paramName ) ;
90
128
}
91
129
130
+ var motionLocal = AnimUtil . CreateSmoothingBlendTree ( _animatorController , animLayer . stateMachine , p . localSmoothness , p . paramName , p . flipInputOutput , ( float ) _parameters . Count , _animExportDirectory , "OSCm/Local/" , "Smoother" , "OSCm/Proxy/" , "Proxy" ) ;
131
+ var motionRemote = AnimUtil . CreateSmoothingBlendTree ( _animatorController , animLayer . stateMachine , p . remoteSmoothness , p . paramName , p . flipInputOutput , ( float ) _parameters . Count , _animExportDirectory , "OSCm/Remote/" , "SmootherRemote" , "OSCm/Proxy/" , "Proxy" ) ;
132
+ if ( _writeDefaults )
133
+ {
134
+ motionLocal = AnimUtil . CreateSmoothingBlendTree ( _animatorController , animLayer . stateMachine , p . localSmoothness , p . paramName , p . flipInputOutput , 1f , _animExportDirectory , "OSCm/Local/" , "SmootherWD" , "OSCm/Proxy/" , "Proxy" ) ;
135
+ motionRemote = AnimUtil . CreateSmoothingBlendTree ( _animatorController , animLayer . stateMachine , p . remoteSmoothness , p . paramName , p . flipInputOutput , 1f , _animExportDirectory , "OSCm/Remote/" , "SmootherRemoteWD" , "OSCm/Proxy/" , "Proxy" ) ;
136
+ }
137
+
92
138
localChildMotion . Add ( new ChildMotion
93
139
{
94
140
directBlendParameter = "OSCm/BlendSet" ,
95
- motion = AnimUtil . CreateSmoothingBlendTree ( _animatorController , animLayer . stateMachine , p . localSmoothness , p . paramName , p . flipInputOutput , ( float ) _parameters . Count , _animExportDirectory , "OSCm/Local/" , "Smoother" , "OSCm/Proxy/" , "Proxy" ) ,
141
+ motion = motionLocal ,
96
142
timeScale = 1
97
143
} ) ;
98
144
99
145
remoteChildMotion . Add ( new ChildMotion
100
146
{
101
147
directBlendParameter = "OSCm/BlendSet" ,
102
- motion = AnimUtil . CreateSmoothingBlendTree ( _animatorController , animLayer . stateMachine , p . remoteSmoothness , p . paramName , p . flipInputOutput , ( float ) _parameters . Count , _animExportDirectory , "OSCm/Remote/" , "SmootherRemote" , "OSCm/Proxy/" , "Proxy" ) ,
148
+ motion = motionRemote ,
103
149
timeScale = 1 ,
104
150
} ) ;
105
151
}
0 commit comments