5
5
using UnityEngine . Jobs ;
6
6
using OSCTools . OSCmooth . Util ;
7
7
using OSCTools . OSCmooth . Types ;
8
+ using System . Linq ;
8
9
9
10
namespace OSCTools . OSCmooth . Animation
10
11
{
11
- public class OSCmoothAnimationHandler
12
+ public static class OSCmoothAnimationHandler
12
13
{
13
- public AnimatorController _animatorController ;
14
- public List < OSCmoothParameter > _parameters ;
15
- public bool _writeDefaults ;
16
- public string _animExportDirectory ;
17
-
18
- public OSCmoothAnimationHandler ( ) { }
19
- public OSCmoothAnimationHandler ( List < OSCmoothParameter > smoothLayer , AnimatorController animatorController , bool writeDefaults = false )
20
- {
21
- _parameters = smoothLayer ;
22
- _animatorController = animatorController ;
23
- _writeDefaults = writeDefaults ;
14
+ public static AnimatorController _animatorController ;
15
+ public static List < OSCmoothParameter > _parameters ;
16
+ public static bool _writeDefaults ;
17
+ public static string _animExportDirectory ;
18
+
19
+ public static void RemoveAllOSCmoothFromController ( )
20
+ {
21
+ AnimUtil . RevertStateMachineParameters ( _animatorController ) ;
22
+ AnimUtil . RemoveExtendedParametersInController ( "OSCm" , _animatorController ) ;
23
+ AnimUtil . RemoveContainingLayersInController ( "OSCm" , _animatorController ) ;
24
24
}
25
- public void CreateSmoothAnimationLayer ( )
25
+ public static void CreateSmoothAnimationLayer ( )
26
26
{
27
+ // Cleanup Animator before applying OSCmooth:
28
+ OSCmoothAnimationHandler . RemoveAllOSCmoothFromController ( ) ;
29
+
30
+ // Creating new OSCmooth setup.
27
31
AnimatorControllerLayer animLayer ;
28
32
29
- // Looking for existing animation layer, and will delete it to replace with a new one. Will look into
30
- // creating a more thorough solution to much more effectively overwrite the existing layer for a future update.
31
- if ( _writeDefaults )
32
- {
33
- AnimUtil . RemoveAnimLayerInController ( "_OSCmooth_Smoothing_Gen" , _animatorController ) ;
33
+ if ( _writeDefaults )
34
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
- }
35
+ else animLayer = AnimUtil . CreateAnimLayerInController ( "_OSCmooth_Smoothing_Gen" , _animatorController ) ;
41
36
42
37
// Creating a Direct BlendTree that will hold all of the smooth driver animations. This is to effectively create a 'sublayer'
43
38
// system within the Direct BlendTree to tidy up the animator base layers from bloating up visually.
44
39
AnimatorState [ ] state = new AnimatorState [ 2 ] ;
45
40
46
- if ( _writeDefaults )
41
+ if ( _writeDefaults )
47
42
{
48
43
state [ 0 ] = animLayer . stateMachine . AddState ( "OSCmooth_Local_WD" , new Vector3 ( 30 , 170 , 0 ) ) ;
49
44
state [ 1 ] = animLayer . stateMachine . AddState ( "OSCmooth_Net_WD" , new Vector3 ( 30 , 170 + 60 , 0 ) ) ;
@@ -53,7 +48,7 @@ public void CreateSmoothAnimationLayer()
53
48
state [ 0 ] = animLayer . stateMachine . AddState ( "OSCmooth_Local" , new Vector3 ( 30 , 170 , 0 ) ) ;
54
49
state [ 1 ] = animLayer . stateMachine . AddState ( "OSCmooth_Net" , new Vector3 ( 30 , 170 + 60 , 0 ) ) ;
55
50
}
56
-
51
+
57
52
58
53
state [ 0 ] . writeDefaultValues = _writeDefaults ;
59
54
state [ 1 ] . writeDefaultValues = _writeDefaults ;
@@ -76,7 +71,7 @@ public void CreateSmoothAnimationLayer()
76
71
if ( _writeDefaults )
77
72
{
78
73
nameLocalWD = "OSCm_Local_WD" ;
79
- nameRemoteWD = "OSCm_Remote_WD" ;
74
+ nameRemoteWD = "OSCm_Remote_WD" ;
80
75
}
81
76
82
77
var basisLocalBlendTree = new BlendTree ( )
@@ -105,7 +100,7 @@ public void CreateSmoothAnimationLayer()
105
100
AssetDatabase . AddObjectToAsset ( basisRemoteBlendTree , AssetDatabase . GetAssetPath ( animLayer . stateMachine ) ) ;
106
101
107
102
// Creating a '1Set' parameter that holds a value of one at all times for the Direct BlendTree
108
-
103
+
109
104
if ( _writeDefaults )
110
105
{
111
106
ParameterUtil . CheckAndCreateParameter ( "OSCm/BlendSet" , _animatorController , AnimatorControllerParameterType . Float , 1f ) ;
@@ -133,9 +128,9 @@ public void CreateSmoothAnimationLayer()
133
128
{
134
129
motionLocal = AnimUtil . CreateSmoothingBlendTree ( _animatorController , animLayer . stateMachine , p . localSmoothness , p . paramName , p . flipInputOutput , 1f , _animExportDirectory , "OSCm/Local/" , "SmootherWD" , "OSCm/Proxy/" , "Proxy" ) ;
135
130
motionRemote = AnimUtil . CreateSmoothingBlendTree ( _animatorController , animLayer . stateMachine , p . remoteSmoothness , p . paramName , p . flipInputOutput , 1f , _animExportDirectory , "OSCm/Remote/" , "SmootherRemoteWD" , "OSCm/Proxy/" , "Proxy" ) ;
136
- }
131
+ }
137
132
138
- localChildMotion . Add ( new ChildMotion
133
+ localChildMotion . Add ( new ChildMotion
139
134
{
140
135
directBlendParameter = "OSCm/BlendSet" ,
141
136
motion = motionLocal ,
0 commit comments