Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add AFK bypass #38

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class AV3Constants
public static readonly string LayerName_FaceEmoteOverride = "[ USER EDIT ] FACE EMOTE OVERRIDE";
public static readonly string LayerName_Blink = "BLINK";
public static readonly string LayerName_MouthMorphCanceler = "MOUTH MORPH CANCELLER";
public static readonly string LayerName_Bypass = "BYPASS";
public static readonly string LayerName_LocalIndicatorSound = "LOCAL INDICATOR SOUND";

public static readonly string StateName_BlinkEnabled = "ENABLE";
Expand Down Expand Up @@ -57,6 +58,7 @@ public class AV3Constants
public static readonly string ParamName_CN_BLINK_ENABLE = "CN_BLINK_ENABLE";
public static readonly string ParamName_CN_MOUTH_MORPH_CANCEL_ENABLE = "CN_MOUTH_MORPH_CANCEL_ENABLE";
public static readonly string ParamName_CN_EMOTE_OVERRIDE = "CN_EMOTE_OVERRIDE";
public static readonly string ParamName_CN_BYPASS = "CN_BYPASS";
public static readonly string ParamName_EV_PLAY_INDICATOR_SOUND = "EV_PLAY_INDICATOR_SOUND";
public static readonly string ParamName_CNST_TOUCH_NADENADE_POINT = "CNST_TOUCH_NADENADE_POINT";
public static readonly string ParamName_CNST_TOUCH_EMOTE_LOCK_TRIGGER_L = "CNST_TOUCH_EMOTE_LOCK_TRIGGER_L";
Expand Down
46 changes: 45 additions & 1 deletion Packages/jp.suzuryg.face-emo/Editor/Detail/AV3/FxGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void Generate(IMenu menu, bool forceOverLimitMode = false)
GenerateFaceEmotePlayerLayer(modes, _aV3Setting, aac, animatorController, useOverLimitMode);
ModifyBlinkLayer(aac, avatarDescriptor, animatorController);
ModifyMouthMorphCancelerLayer(_aV3Setting, aac, avatarDescriptor, animatorController);
AddBypassLayer(_aV3Setting, aac, animatorController);

// Generate MA Object
EditorUtility.DisplayProgressBar(DomainConstants.SystemName, $"Generating ExMenu...", 0);
Expand Down Expand Up @@ -266,7 +267,14 @@ private void GenerateDefaultFaceLayer(AacFlBase aac, VRCAvatarDescriptor avatarD

// Create default face state
var defaultFace = GetDefaultFaceAnimation(aac, avatarDescriptor);
layer.NewState("DEFAULT", 0, 0).WithAnimation(defaultFace);
var defaultState = layer.NewState("DEFAULT", 0, 0).WithAnimation(defaultFace);

// Create bypass state
var bypassState = layer.NewState("BYPASS", 1, 0);
defaultState.TransitionsTo(bypassState).
When(layer.BoolParameter(AV3Constants.ParamName_CN_BYPASS).IsTrue());
bypassState.TransitionsTo(defaultState).
When(layer.BoolParameter(AV3Constants.ParamName_CN_BYPASS).IsFalse());

EditorUtility.DisplayProgressBar(DomainConstants.SystemName, $"Generating \"{layerName}\" layer...", 1);
}
Expand Down Expand Up @@ -504,6 +512,17 @@ private static void GenerateFaceEmotePlayerLayer(IReadOnlyList<ModeEx> modes, AV
.Or()
.When(layer.Av3().InStation.IsFalse());

// Create bypass state
var bypassState = layer.NewState("BYPASS", 4, -1)
.Drives(layer.BoolParameter(AV3Constants.ParamName_CN_BLINK_ENABLE), false)
.Drives(layer.BoolParameter(AV3Constants.ParamName_CN_MOUTH_MORPH_CANCEL_ENABLE), false)
.TrackingSets(TrackingElement.Eyes, VRC_AnimatorTrackingControl.TrackingType.Animation)
.TrackingSets(TrackingElement.Mouth, VRC_AnimatorTrackingControl.TrackingType.Tracking);
bypassState.TransitionsFromAny()
.When(layer.BoolParameter(AV3Constants.ParamName_CN_BYPASS).IsTrue());
bypassState.Exits()
.When(layer.BoolParameter(AV3Constants.ParamName_CN_BYPASS).IsFalse());

EditorUtility.DisplayProgressBar(DomainConstants.SystemName, $"Generating \"{layerName}\" layer...", 1);
}

Expand Down Expand Up @@ -539,6 +558,30 @@ private void ModifyMouthMorphCancelerLayer(AV3Setting aV3Setting, AacFlBase aac,
EditorUtility.DisplayProgressBar(DomainConstants.SystemName, $"Modifying \"{layerName}\" layer...", 1);
}

private void AddBypassLayer(AV3Setting aV3Setting, AacFlBase aac, AnimatorController animatorController)
{
// Create or replace layer
var layerName = AV3Constants.LayerName_Bypass;
var layer = aac.CreateSupportingArbitraryControllerLayer(animatorController, layerName);
AV3Utility.SetLayerWeight(animatorController, layerName, 0);
layer.StateMachine.WithEntryPosition(0, -1).WithAnyStatePosition(0, -2).WithExitPosition(0, -3);

// Create states
if (!aV3Setting.ChangeAfkFace)
{
var gate = layer.NewState("LOCAL GATE", 0, 0);
var disable = layer.NewState("DISABLE", 0, 1).Drives(layer.BoolParameter(AV3Constants.ParamName_CN_BYPASS), false).DrivingLocally();
var enable = layer.NewState("ENABLE", 0, 2).Drives(layer.BoolParameter(AV3Constants.ParamName_CN_BYPASS), true).DrivingLocally();

gate.TransitionsTo(disable)
.When(layer.Av3().IsLocal.IsEqualTo(true));
disable.TransitionsTo(enable).
When(layer.Av3().AFK.IsEqualTo(true));
enable.TransitionsTo(disable).
When(layer.Av3().AFK.IsEqualTo(false));
}
}

private VRCExpressionsMenu GenerateExMenu(IReadOnlyList<ModeEx> modes, IMenu menu, string exMenuPath, bool useOverLimitMode)
{
var loc = _localizationSetting.GetCurrentLocaleTable();
Expand Down Expand Up @@ -1065,6 +1108,7 @@ private void AddParameterComponent(GameObject rootObject, int defaultModeIndex)
modularAvatarParameters.parameters.Add(NotSyncedMAParam(AV3Constants.ParamName_CN_BLINK_ENABLE, addPrefix: _aV3Setting.AddParameterPrefix));
modularAvatarParameters.parameters.Add(NotSyncedMAParam(AV3Constants.ParamName_CN_MOUTH_MORPH_CANCEL_ENABLE, addPrefix: _aV3Setting.AddParameterPrefix));
modularAvatarParameters.parameters.Add(NotSyncedMAParam(AV3Constants.ParamName_CN_EMOTE_OVERRIDE, addPrefix: _aV3Setting.AddParameterPrefix));
modularAvatarParameters.parameters.Add(NotSyncedMAParam(AV3Constants.ParamName_CN_BYPASS, addPrefix: _aV3Setting.AddParameterPrefix));
modularAvatarParameters.parameters.Add(NotSyncedMAParam(AV3Constants.ParamName_EV_PLAY_INDICATOR_SOUND, addPrefix: _aV3Setting.AddParameterPrefix));
modularAvatarParameters.parameters.Add(NotSyncedMAParam(AV3Constants.ParamName_CNST_TOUCH_NADENADE_POINT, addPrefix: _aV3Setting.AddParameterPrefix));
modularAvatarParameters.parameters.Add(NotSyncedMAParam(AV3Constants.ParamName_CNST_TOUCH_EMOTE_LOCK_TRIGGER_L, addPrefix: _aV3Setting.AddParameterPrefix));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public class LocalizationTable : ScriptableObject
public string InspectorView_Thumbnail_Reset = "Reset";

public string InspectorView_AFK = "AFK Face Settings";
public string InspectorView_AFK_ChangeAfkFace = "Change AFK Face";
public string InspectorView_AFK_EnterFace = "AFK Enter Face";
public string InspectorView_AFK_Face = "AFK Face";
public string InspectorView_AFK_ExitFace = "AFK Exit Face";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ MonoBehaviour:
InspectorView_Thumbnail_VerticalAngle: "\u89D2\u5EA6\uFF08\u5782\u76F4\uFF09"
InspectorView_Thumbnail_Reset: "\u30EA\u30BB\u30C3\u30C8"
InspectorView_AFK: "AFK\u8868\u60C5\u8A2D\u5B9A"
InspectorView_AFK_ChangeAfkFace: "AFK\u8868\u60C5\u3092\u5909\u66F4\u3059\u308B"
InspectorView_AFK_EnterFace: "AFK\u958B\u59CB\u6642\u306E\u8868\u60C5"
InspectorView_AFK_Face: "AFK\u4E2D\u306E\u8868\u60C5"
InspectorView_AFK_ExitFace: "AFK\u7D42\u4E86\u6642\u306E\u8868\u60C5"
Expand Down
12 changes: 9 additions & 3 deletions Packages/jp.suzuryg.face-emo/Editor/Detail/View/InspectorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,15 @@ private void Field_AFKFace()
HelpBoxDrawer.InfoLayout(_localizationTable.InspectorView_Tooltip_AFK);
}

EditorGUILayout.PropertyField(_av3Setting.FindProperty(nameof(AV3Setting.AfkEnterFace)), new GUIContent(_localizationTable.InspectorView_AFK_EnterFace));
EditorGUILayout.PropertyField(_av3Setting.FindProperty(nameof(AV3Setting.AfkFace)), new GUIContent(_localizationTable.InspectorView_AFK_Face));
EditorGUILayout.PropertyField(_av3Setting.FindProperty(nameof(AV3Setting.AfkExitFace)), new GUIContent(_localizationTable.InspectorView_AFK_ExitFace));
var changeAfkFace = _av3Setting.FindProperty(nameof(AV3Setting.ChangeAfkFace));
TogglePropertyField(changeAfkFace, _localizationTable.InspectorView_AFK_ChangeAfkFace);

using (new EditorGUI.DisabledScope(!changeAfkFace.boolValue))
{
EditorGUILayout.PropertyField(_av3Setting.FindProperty(nameof(AV3Setting.AfkEnterFace)), new GUIContent(_localizationTable.InspectorView_AFK_EnterFace));
EditorGUILayout.PropertyField(_av3Setting.FindProperty(nameof(AV3Setting.AfkFace)), new GUIContent(_localizationTable.InspectorView_AFK_Face));
EditorGUILayout.PropertyField(_av3Setting.FindProperty(nameof(AV3Setting.AfkExitFace)), new GUIContent(_localizationTable.InspectorView_AFK_ExitFace));
}
}

private void Field_ThumbnailSetting()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AV3Setting : ScriptableObject
public List<string> AdditionalToggleObjectPaths = new List<string>();
public List<string> AdditionalTransformObjectPaths = new List<string>();

public bool ChangeAfkFace = false;
public AnimationClip AfkEnterFace;
public AnimationClip AfkFace;
public AnimationClip AfkExitFace;
Expand Down
Loading