Skip to content

Commit

Permalink
Editor-time check for Write Default OFF
Browse files Browse the repository at this point in the history
  • Loading branch information
enitimeago committed Aug 24, 2024
1 parent 6d9fa4e commit c10f778
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ public override void OnInspectorGUI()
EditorGUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
}
var writeDefaultsComponents = avatar?.gameObject.GetComponentsInChildren<WriteDefaultsComponent>();
if (!data.ignoreWriteDefaultsOff && _commonChecks.AvatarHasWriteDefaultOff(avatar) && writeDefaultsComponents.All(x => !x.forceAvatarWriteDefaults))
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.HelpBox(L.Tr("CommonChecks:AvatarWriteDefaultOffFound"), MessageType.Info);
EditorGUILayout.BeginVertical();
if (GUILayout.Button(L.Tr("Common:FixThis")))
{
if (writeDefaultsComponents.Count() == 0)
{
var newComponent = data.gameObject.AddComponent<WriteDefaultsComponent>();
newComponent.forceAvatarWriteDefaults = true;
}
else
{
writeDefaultsComponents.First().forceAvatarWriteDefaults = true;
}
}
if (GUILayout.Button(L.Tr("Common:Ignore")))
{
data.ignoreWriteDefaultsOff = true;
}
EditorGUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
}

bool hasMmdShapeKeys = false;
if (!EditorApplication.isPlaying)
Expand Down
63 changes: 33 additions & 30 deletions Packages/enitimeago.non-destructive-mmd/Editor/CommonChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,43 +108,46 @@ public bool RunChecks(VRCAvatarDescriptor avatarDescriptor, bool isBuildTime = t
LogLocalized(Severity.Warning, "CommonChecks:AvatarFaceSMRNotCalledBody");
}

if (avatarDescriptor?.baseAnimationLayers != null)
if (AvatarHasWriteDefaultOff(avatarDescriptor))
{
VRCAvatarDescriptor.CustomAnimLayer fxLayer;
AnimatorController fxController = null;
foreach (var layer in avatarDescriptor.baseAnimationLayers)
{
if (layer.type == VRCAvatarDescriptor.AnimLayerType.FX && layer.animatorController != null)
{
fxLayer = layer;
fxController = layer.animatorController as AnimatorController;
break;
}
}
if (fxController != null)
LogLocalized(Severity.Warning, "CommonChecks:AvatarWriteDefaultOffFound");
}
}

return true;
}

public bool AvatarHasWriteDefaultOff(VRCAvatarDescriptor avatarDescriptor)
{
if (avatarDescriptor?.baseAnimationLayers == null)
{
return false;
}
VRCAvatarDescriptor.CustomAnimLayer fxLayer;
AnimatorController fxController = null;
foreach (var layer in avatarDescriptor.baseAnimationLayers)
{
if (layer.type == VRCAvatarDescriptor.AnimLayerType.FX && layer.animatorController != null)
{
fxLayer = layer;
fxController = layer.animatorController as AnimatorController;
break;
}
}
if (fxController != null)
{
foreach (var layer in fxController.layers)
{
foreach (var state in layer.stateMachine.states)
{
bool foundWriteDefaultOff = false;
foreach (var layer in fxController.layers)
{
foreach (var state in layer.stateMachine.states)
{
if (!state.state.writeDefaultValues)
{
foundWriteDefaultOff = true;
break;
}
}
if (foundWriteDefaultOff) break;
}
if (foundWriteDefaultOff)
if (!state.state.writeDefaultValues)
{
LogLocalized(Severity.Warning, "CommonChecks:AvatarWriteDefaultOffFound");
return true;
}
}
}
}

return true;
return false;
}

#if UNITY_2021_3_OR_NEWER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void OnInspectorGUI()
EditorGUILayout.EndHorizontal();

// Run asserts, however continue rendering GUI if errors are encountered.
_commonChecks.RunChecks(avatar);
_commonChecks.RunChecks(avatar, isBuildTime: false);

Undo.RecordObject(target, "Toggle");
EditorGUI.BeginChangeCheck();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class BlendShapeMappings : MonoBehaviour, ISerializationCallbackReceiver,
public int dataVersion;

public bool ignoreFaceMeshName = false;
public bool ignoreWriteDefaultsOff = false;

[FormerlySerializedAs("blendShapeMappings")]
[SerializeField]
Expand Down

0 comments on commit c10f778

Please sign in to comment.