Skip to content

Commit eaa61ad

Browse files
authored
Merge pull request #14 from Adjerry91/Write-Defaults-Switch
Fix write defaults ON breaking in VRC stations
2 parents ac9c273 + 1b594ad commit eaa61ad

File tree

2 files changed

+67
-9
lines changed

2 files changed

+67
-9
lines changed

Assets/OSCmooth/Editor/OSCmoothAnimationHandler.cs

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,32 @@ public void CreateSmoothAnimationLayer()
2828

2929
// Looking for existing animation layer, and will delete it to replace with a new one. Will look into
3030
// 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+
}
3241

3342
// Creating a Direct BlendTree that will hold all of the smooth driver animations. This is to effectively create a 'sublayer'
3443
// system within the Direct BlendTree to tidy up the animator base layers from bloating up visually.
3544
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+
3857

3958
state[0].writeDefaultValues = _writeDefaults;
4059
state[1].writeDefaultValues = _writeDefaults;
@@ -51,23 +70,33 @@ public void CreateSmoothAnimationLayer()
5170
toLocalState.AddCondition(AnimatorConditionMode.If, 0, "IsLocal");
5271

5372
// 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+
5482
var basisLocalBlendTree = new BlendTree()
5583
{
5684
blendType = BlendTreeType.Direct,
5785
hideFlags = HideFlags.HideInHierarchy,
58-
name = "OSCm_Local",
86+
name = nameLocalWD,
5987
useAutomaticThresholds = false
60-
88+
6189
};
6290

6391
var basisRemoteBlendTree = new BlendTree()
6492
{
6593
blendType = BlendTreeType.Direct,
6694
hideFlags = HideFlags.HideInHierarchy,
67-
name = "OSCm_Remote",
95+
name = nameRemoteWD,
6896
useAutomaticThresholds = false
6997
};
7098

99+
71100
// Stuffing the BlendTrees into their designated state. Also stuffing them so that they
72101
// retain serialization.
73102
state[0].motion = basisLocalBlendTree;
@@ -76,7 +105,16 @@ public void CreateSmoothAnimationLayer()
76105
AssetDatabase.AddObjectToAsset(basisRemoteBlendTree, AssetDatabase.GetAssetPath(animLayer.stateMachine));
77106

78107
// 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+
80118

81119
List<ChildMotion> localChildMotion = new List<ChildMotion>();
82120
List<ChildMotion> remoteChildMotion = new List<ChildMotion>();
@@ -89,17 +127,25 @@ public void CreateSmoothAnimationLayer()
89127
AnimUtil.RenameAllStateMachineInstancesOfBlendParameter(_animatorController, p.paramName, "OSCm/Proxy/" + p.paramName);
90128
}
91129

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+
92138
localChildMotion.Add(new ChildMotion
93139
{
94140
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,
96142
timeScale = 1
97143
});
98144

99145
remoteChildMotion.Add(new ChildMotion
100146
{
101147
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,
103149
timeScale = 1,
104150
});
105151
}

Assets/OSCmooth/Editor/OSCmoothUtil.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ public static void RenameAllStateMachineInstancesOfBlendParameter(AnimatorContro
6262
}
6363
}
6464

65+
public static void RemoveAnimLayerInController(string layerName, AnimatorController animatorController)
66+
{
67+
for (int i = 0; i < animatorController.layers.Length; i++)
68+
{
69+
if (animatorController.layers[i].name == layerName)
70+
{
71+
animatorController.RemoveLayer(i);
72+
}
73+
}
74+
75+
}
76+
6577
public static AnimatorControllerLayer CreateAnimLayerInController(string layerName, AnimatorController animatorController)
6678
{
6779
for (int i = 0; i < animatorController.layers.Length; i++)

0 commit comments

Comments
 (0)